Exemple #1
0
        /**
         * This implementation of process performs the following steps:
         *
         * - Read the beginning of the message.
         * - Extract the service name from the message.
         * - Using the service name to locate the appropriate processor.
         * - Dispatch to the processor, with a decorated instance of TProtocol
         *    that allows readMessageBegin() to return the original TMessage.
         *
         * Throws an exception if
         * - the message type is not CALL or ONEWAY,
         * - the service name was not found in the message, or
         * - the service name has not been RegisterProcessor()ed.
         */
        public bool Process(TProtocol iprot, TProtocol oprot)
        {
            /*  Use the actual underlying protocol (e.g. TBinaryProtocol) to read the
             *  message header.  This pulls the message "off the wire", which we'll
             *  deal with at the end of this method. */

            try
            {
                TMessage message = iprot.ReadMessageBegin();

                if ((message.Type != TMessageType.Call) && (message.Type != TMessageType.Oneway))
                {
                    Fail(oprot, message,
                         TApplicationException.ExceptionType.InvalidMessageType,
                         "Message type CALL or ONEWAY expected");
                    return(false);
                }

                // Extract the service name
                int index = message.Name.IndexOf(TMultiplexedProtocol.SEPARATOR);
                if (index < 0)
                {
                    Fail(oprot, message,
                         TApplicationException.ExceptionType.InvalidProtocol,
                         "Service name not found in message name: " + message.Name + ". " +
                         "Did you forget to use a TMultiplexProtocol in your client?");
                    return(false);
                }

                // Create a new TMessage, something that can be consumed by any TProtocol
                string     serviceName = message.Name.Substring(0, index);
                TProcessor actualProcessor;
                if (!ServiceProcessorMap.TryGetValue(serviceName, out actualProcessor))
                {
                    Fail(oprot, message,
                         TApplicationException.ExceptionType.InternalError,
                         "Service name not found: " + serviceName + ". " +
                         "Did you forget to call RegisterProcessor()?");
                    return(false);
                }

                // Create a new TMessage, removing the service name
                TMessage newMessage = new TMessage(
                    message.Name.Substring(serviceName.Length + TMultiplexedProtocol.SEPARATOR.Length),
                    message.Type,
                    message.SeqID);

                // Dispatch processing to the stored processor
                return(actualProcessor.Process(new StoredMessageProtocol(iprot, newMessage), oprot));
            }
            catch (IOException)
            {
                return(false);  // similar to all other processors
            }
        }
Exemple #2
0
 public bool Process(TProtocol iprot, TProtocol oprot)
 {
   try
   {
     TMessage msg = iprot.ReadMessageBegin();
     ProcessFunction fn;
     processMap_.TryGetValue(msg.Name, out fn);
     if (fn == null) {
       TProtocolUtil.Skip(iprot, TType.Struct);
       iprot.ReadMessageEnd();
       TApplicationException x = new TApplicationException (TApplicationException.ExceptionType.UnknownMethod, "Invalid method name: '" + msg.Name + "'");
       oprot.WriteMessageBegin(new TMessage(msg.Name, TMessageType.Exception, msg.SeqID));
       x.Write(oprot);
       oprot.WriteMessageEnd();
       oprot.Transport.Flush();
       return true;
     }
     fn(msg.SeqID, iprot, oprot);
   }
   catch (IOException)
   {
     return false;
   }
   return true;
 }
Exemple #3
0
 public override TMessage ReadMessageBegin()
 {
     return(WrappedProtocol.ReadMessageBegin());
 }
        /**
         * This implementation of process performs the following steps:
         *
         * - Read the beginning of the message.
         * - Extract the service name from the message.
         * - Using the service name to locate the appropriate processor.
         * - Dispatch to the processor, with a decorated instance of TProtocol
         *    that allows readMessageBegin() to return the original TMessage.
         *  
         * Throws an exception if 
         * - the message type is not CALL or ONEWAY, 
         * - the service name was not found in the message, or 
         * - the service name has not been RegisterProcessor()ed.  
         */
        public bool Process(TProtocol iprot, TProtocol oprot)
        {
            /*  Use the actual underlying protocol (e.g. TBinaryProtocol) to read the
                message header.  This pulls the message "off the wire", which we'll
                deal with at the end of this method. */

            try
            {
                TMessage message = iprot.ReadMessageBegin();

                if ((message.Type != TMessageType.Call) && (message.Type != TMessageType.Oneway))
                {
                    Fail(oprot, message,
                          TApplicationException.ExceptionType.InvalidMessageType,
                          "Message type CALL or ONEWAY expected");
                    return false;
                }

                // Extract the service name
                int index = message.Name.IndexOf(TMultiplexedProtocol.SEPARATOR);
                if (index < 0)
                {
                    Fail(oprot, message,
                          TApplicationException.ExceptionType.InvalidProtocol,
                          "Service name not found in message name: " + message.Name + ". " +
                          "Did you forget to use a TMultiplexProtocol in your client?");
                    return false;
                }

                // Create a new TMessage, something that can be consumed by any TProtocol
                string serviceName = message.Name.Substring(0, index);
                TProcessor actualProcessor;
                if (!ServiceProcessorMap.TryGetValue(serviceName, out actualProcessor))
                {
                    Fail(oprot, message,
                          TApplicationException.ExceptionType.InternalError,
                          "Service name not found: " + serviceName + ". " +
                          "Did you forget to call RegisterProcessor()?");
                    return false;
                }

                // Create a new TMessage, removing the service name
                TMessage newMessage = new TMessage(
                        message.Name.Substring(serviceName.Length + TMultiplexedProtocol.SEPARATOR.Length),
                        message.Type,
                        message.SeqID);

                // Dispatch processing to the stored processor
                return actualProcessor.Process(new StoredMessageProtocol(iprot, newMessage), oprot);

            }
            catch (IOException)
            {
                return false;  // similar to all other processors
            }

        }