ReadMessageBegin() public abstract method

public abstract ReadMessageBegin ( ) : Thrift.Protocol.TMessage
return Thrift.Protocol.TMessage
Example #1
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;
 }
        /**
         * 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
            }
        }
Example #3
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. */

            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);
        }
        public bool Process(TProtocol iprot, TProtocol oprot)
        {
            TProcessor tProcessor;
            bool       flag;

            try
            {
                TMessage tMessage = iprot.ReadMessageBegin();
                if (tMessage.Type == TMessageType.Call || tMessage.Type == TMessageType.Oneway)
                {
                    int num = tMessage.Name.IndexOf(TMultiplexedProtocol.SEPARATOR);
                    if (num >= 0)
                    {
                        string str = tMessage.Name.Substring(0, num);
                        if (this.ServiceProcessorMap.TryGetValue(str, out tProcessor))
                        {
                            TMessage tMessage1 = new TMessage(tMessage.Name.Substring(str.Length + TMultiplexedProtocol.SEPARATOR.Length), tMessage.Type, tMessage.SeqID);
                            flag = tProcessor.Process(new TMultiplexedProcessor.StoredMessageProtocol(iprot, tMessage1), oprot);
                        }
                        else
                        {
                            this.Fail(oprot, tMessage, TApplicationException.ExceptionType.InternalError, string.Concat("Service name not found: ", str, ". Did you forget to call RegisterProcessor()?"));
                            flag = false;
                        }
                    }
                    else
                    {
                        this.Fail(oprot, tMessage, TApplicationException.ExceptionType.InvalidProtocol, string.Concat("Service name not found in message name: ", tMessage.Name, ". Did you forget to use a TMultiplexProtocol in your client?"));
                        flag = false;
                    }
                }
                else
                {
                    this.Fail(oprot, tMessage, TApplicationException.ExceptionType.InvalidMessageType, "Message type CALL or ONEWAY expected");
                    flag = false;
                }
            }
            catch (IOException oException)
            {
                flag = false;
            }
            return(flag);
        }
Example #5
0
 public override TMessage ReadMessageBegin()
 {
     return(WrappedProtocol.ReadMessageBegin());
 }