private void Fail( TProtocol oprot, TMessage message, TApplicationException.ExceptionType extype, string etxt)
        {
            TApplicationException appex = new TApplicationException( extype, etxt);

            TMessage newMessage = new TMessage(message.Name, TMessageType.Exception, message.SeqID);

            oprot.WriteMessageBegin(newMessage);
            appex.Write( oprot);
            oprot.WriteMessageEnd();
            oprot.Transport.Flush();
        }
Пример #2
0
		public override void WriteMessageBegin(TMessage message)
		{
			if (strictWrite_)
			{
				uint version = VERSION_1 | (uint)(message.Type);
				WriteI32((int)version);
				WriteString(message.Name);
				WriteI32(message.SeqID);
			}
			else
			{
				WriteString(message.Name);
				WriteByte((sbyte)message.Type);
				WriteI32(message.SeqID);
			}
		}
        /**
         * Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR.
         * Args:
         *   tMessage     The original message.
         */
        public override void WriteMessageBegin(TMessage tMessage) 
        {
            switch(tMessage.Type)
            {
                case TMessageType.Call:
                case TMessageType.Oneway:
                    base.WriteMessageBegin(new TMessage(
                        ServiceName + SEPARATOR + tMessage.Name,
                        tMessage.Type,
                        tMessage.SeqID));
                    break;

                default:
                    base.WriteMessageBegin(tMessage);
                    break;
            }
        }
Пример #4
0
        /**
         * Prepends the service name to the function name, separated by TMultiplexedProtocol.SEPARATOR.
         * Args:
         *   tMessage     The original message.
         */
        public override void WriteMessageBegin(TMessage tMessage)
        {
            switch (tMessage.Type)
            {
            case TMessageType.Call:
            case TMessageType.Oneway:
                base.WriteMessageBegin(new TMessage(
                                           ServiceName + SEPARATOR + tMessage.Name,
                                           tMessage.Type,
                                           tMessage.SeqID));
                break;

            default:
                base.WriteMessageBegin(tMessage);
                break;
            }
        }
        public override TMessage ReadMessageBegin()
        {
            TMessage message = new TMessage();

            ReadJSONArrayStart();
            if (ReadJSONInteger() != VERSION)
            {
                throw new TProtocolException(TProtocolException.BAD_VERSION,
                                             "Message contained bad version.");
            }

            var buf = ReadJSONString(false);

            message.Name  = utf8Encoding.GetString(buf, 0, buf.Length);
            message.Type  = (TMessageType)ReadJSONInteger();
            message.SeqID = (int)ReadJSONInteger();
            return(message);
        }
Пример #6
0
		public override TMessage ReadMessageBegin()
		{
			TMessage message = new TMessage();
			ReadJSONArrayStart();
			if (ReadJSONInteger() != VERSION)
			{
				throw new TProtocolException(TProtocolException.BAD_VERSION,
											 "Message contained bad version.");
			}

            var buf = ReadJSONString(false);
			message.Name = utf8Encoding.GetString(buf,0,buf.Length);
			message.Type = (TMessageType)ReadJSONInteger();
			message.SeqID = (int)ReadJSONInteger();
			return message;
		}
Пример #7
0
		public override void WriteMessageBegin(TMessage message)
		{
			WriteJSONArrayStart();
			WriteJSONInteger(VERSION);

			byte[] b = utf8Encoding.GetBytes(message.Name);
			WriteJSONString(b);

			WriteJSONInteger((long)message.Type);
			WriteJSONInteger(message.SeqID);
		}
Пример #8
0
 /**
 * Write a message header to the wire. Compact Protocol messages contain the
 * protocol version so we can migrate forwards in the future if need be.
 */
 public override void WriteMessageBegin(TMessage message)
 {
     WriteByteDirect(PROTOCOL_ID);
     WriteByteDirect((byte)((VERSION & VERSION_MASK) | ((((uint)message.Type) << TYPE_SHIFT_AMOUNT) & TYPE_MASK)));
     WriteVarint32((uint)message.SeqID);
     WriteString(message.Name);
 }
Пример #9
0
		public abstract void WriteMessageBegin(TMessage message);
Пример #10
0
 public abstract void WriteMessageBegin(TMessage message);
Пример #11
0
		public override TMessage ReadMessageBegin()
		{
			TMessage message = new TMessage();
			int size = ReadI32();
			if (size < 0)
			{
				uint version = (uint)size & VERSION_MASK;
				if (version != VERSION_1)
				{
					throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in ReadMessageBegin: " + version);
				}
				message.Type = (TMessageType)(size & 0x000000ff);
				message.Name = ReadString();
				message.SeqID = ReadI32();
			}
			else
			{
				if (strictRead_)
				{
					throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?");
				}
				message.Name = ReadStringBody(size);
				message.Type = (TMessageType)ReadByte();
				message.SeqID = ReadI32();
			}
			return message;
		}
Пример #12
0
 public override void WriteMessageBegin(TMessage tMessage)
 {
     WrappedProtocol.WriteMessageBegin(tMessage);
 }
Пример #13
0
 public override void WriteMessageBegin(TMessage tMessage) 
 {
     WrappedProtocol.WriteMessageBegin(tMessage);
 }
        /**
         * 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
            }

        }
 public StoredMessageProtocol(TProtocol protocol, TMessage messageBegin) 
     :base(protocol)
 {
     this.MsgBegin = messageBegin;
 }
Пример #16
0
 public StoredMessageProtocol(TProtocol protocol, TMessage messageBegin)
     : base(protocol)
 {
     this.MsgBegin = messageBegin;
 }