Beispiel #1
0
        /// <summary>
        /// Invokes the appropriate service handler (registered using a ServiceAttribute)
        /// </summary>
        public void InvokeServiceHandler(Message request, Message response, HttpSessionState session, HttpResponse httpresponse)
        {
            if (request.Type.Equals(this.Request))
            {
                try
                {
                    Message temp_response = response;
                    Object[] parameters = new Object[] { request, temp_response };
                    Object declaringTypeInstance = Activator.CreateInstance(this.MethodInfo.DeclaringType);
                    this.MethodInfo.Invoke(declaringTypeInstance, parameters);
                    temp_response = (Message)parameters[1];
                    temp_response.Type = this.Response;
                    temp_response.Scope = request.Scope;
                    temp_response.Version = request.Version;
                    temp_response.RequestDetails = request.RequestDetails;

                    Logger.Instance.Debug("Invoked service for request: " + request.Type);
                    Dispatcher.Instance.EnqueueOutgoingMessage(temp_response, session.SessionID);
                }
                catch (Exception e)
                {
                    String err = "";
                    err+="Exception while invoking service handler - " + this.MethodInfo.Name + " in " + this.MethodInfo.DeclaringType.Name + "\n";
                    err += "Request Message - " + request.Type + "\n";
                    err += "Response Message - " + response.Type + "\n";
                    err += "Message - " + e.Message + "\n";
                    err += "Stacktrace - " + e.StackTrace + "\n";
                    Logger.Instance.Error(err);
                }
            }
        }
Beispiel #2
0
 public void TestMessageHandler(Message request, ref Message response)
 {
     response.Data.Add("success", true);
     String message;
     try
     {
         message = ((JsonString)request.Data["message"]).Value;
     }
     catch
     {
         message = "";
     }
     response.Data.Add("message", "I received from you " + message);
 }
        /// <summary>
        /// Invokes the appropriate handler for a given request
        /// </summary>
        /// <param name="request">The ServiceRequest object corresponding to the incoming request</param>
        /// <param name="response">The ServiceResponse object corresponding to the outgoing response</param>
        public void HandleRequest(Message request, Message response, HttpSessionState session, HttpResponse httpresponse)
        {
            try
            {
                Logger.Instance.Debug("Invoking services for request: " + request.Type);
                List<Service> handlers = RequestToServiceMap[request.Type];

                foreach (Service handler in handlers)
                {
                    handler.InvokeServiceHandler(request, response, session, httpresponse);
                }
            }
            catch (KeyNotFoundException)
            {
                //There's no Service to handle the incoming request -- Log it to the console
                Logger.Instance.Debug("No service registered to handle request: " + request.Type);
            }
        }
        /// <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;
        }