public Message(JsonObject message, HttpSessionState session, ServiceBroker servicebroker, RequestDetails details) { type = ((JsonString)message["type"]).Value; scope = ((JsonString)message["scope"]).Value; version = ((JsonString)message["version"]).Value; json = (JsonObject)message["data"]; sessionid = session.SessionID; requestdetails = details; this.session = session; this.servicebroker = servicebroker; }
public Message(XPathNavigator msgXML, HttpSessionState session, ServiceBroker servicebroker, RequestDetails details) { XmlDocument doc = new XmlDocument(); doc.LoadXml(msgXML.OuterXml); XmlElement msg = doc.DocumentElement; requestid = msg.GetAttribute("requestid"); type = msg.GetAttribute("type").ToLower(); scope = msg.GetAttribute("scope"); version = msg.GetAttribute("version"); sessionid = session.SessionID; json = parseMessagePayload(msg.InnerText); requestdetails = details; this.session = session; this.servicebroker = servicebroker; }
public void ProcessRequest(HttpContext context) { String session_id = context.Session.SessionID; HttpResponse response = context.Response; HttpRequest request = context.Request; String content_type = request.ContentType; response.ContentType = request.ContentType; response.Expires = 0; response.CacheControl = "Private"; //no-cache, no-store, private, must-revalidate //This is needed to prevent the SessionID from changing on every request (if nothing is stored //in the session object context.Session["make_persistant"] = 1; String response_text = ""; if ((content_type == "" || content_type.Contains(TEXT_HTML)) && request.QueryString.GetValues("initial") != null) return; content_type = content_type.Contains(XML_JSON) ? XML_JSON : APPLICATION_JSON; logger.Debug("Received HTTP Reqest of type: " + request.HttpMethod +" with content_type of " + content_type); switch (request.HttpMethod) { case "GET": // Send waiting message(s) to client [from queue] response_text = dispatcher.GetQueuedMessages(session_id,content_type); break; case "POST": // Dispatch incoming message(s) and send waiting message(s) to client [[from queue] RequestDetails requestdetails = new RequestDetails(request.InputStream,content_type); List<Message> incomingMessages = serviceManager.ParseIncomingMessages(context, this, requestdetails, content_type); //Dispatch each incoming message from the list here once dispatcher, listeners are both done dispatcher.Dispatch(incomingMessages, serviceManager,request,response,context.Session, this); response_text = dispatcher.GetQueuedMessages(session_id,content_type); break; } response.Write(response_text); }
/// <summary> /// Parses incoming messages and returns a list to be dispatched /// </summary> /// <param name="iter">The iterator with the message element list (xml)</param> /// <param name="context">The HttpContext of the request</param> /// <param name="broker">The ServiceBroker handling the request</param> /// <param name="details">The RequestDetails from the request</param> /// <returns></returns> public List<Message> ParseIncomingMessages(HttpContext context, ServiceBroker broker, RequestDetails details, String content_type) { List<Message> messages = new List<Message>(); switch (content_type) { case ServiceBroker.APPLICATION_JSON: JsonArray messageArray = (JsonArray)details.JSON["messages"]; foreach (JsonObject jsonMessage in messageArray) { Message m = new Message(jsonMessage, context.Session, broker, details); m.Direction = MessageDirection.INCOMING; messages.Add(m); } break; case ServiceBroker.XML_JSON: XPathNodeIterator iter = details.XMLIterator; while (iter.MoveNext()) { Message m = new Message(iter.Current, context.Session, broker, details); m.Direction = MessageDirection.INCOMING; messages.Add(m); } break; } Logger.Instance.Debug("Parsed " + messages.Count + " incoming message(s)"); return messages; }