/// <seealso cref= CustomSerializer#deserializeContent(RequestCommand) </seealso>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public <T extends com.alipay.remoting.rpc.RequestCommand> boolean deserializeContent(T req) throws com.alipay.remoting.exception.DeserializationException
        public override bool deserializeContent(RequestCommand req)
        {
            deserialFlag.set(true);
            RpcRequestCommand rpcReq = (RpcRequestCommand)req;

            byte[]      content = rpcReq.Content;
            IByteBuffer bb      = Unpooled.WrappedBuffer(content);
            int         a       = bb.ReadInt();

            byte[] dst = new byte[content.Length - 4];
            bb.ReadBytes(dst, 0, dst.Length);
            try
            {
                string      b  = Encoding.UTF8.GetString(dst);
                RequestBody bd = new RequestBody(a, b);
                rpcReq.RequestObject = bd;
            }
            catch (UnsupportedEncodingException e)
            {
                System.Console.WriteLine(e.ToString());
                System.Console.Write(e.StackTrace);
            }

            contentDeserializer = rpcReq.Serializer;
            return(true);
        }
        /// <seealso cref= CustomSerializer#serializeContent(RequestCommand, InvokeContext) </seealso>
        public override bool serializeContent(RequestCommand req, InvokeContext invokeContext)
        {
            serialFlag.set(true);
            RpcRequestCommand rpcReq = (RpcRequestCommand)req;
            RequestBody       bd     = (RequestBody)rpcReq.RequestObject;
            int id = bd.Id;

            byte[] msg;
            try
            {
                msg = Encoding.UTF8.GetBytes(bd.Msg);
                IByteBuffer bb = UnpooledByteBufferAllocator.Default.Buffer(4 + msg.Length);
                bb.WriteInt(id);
                bb.WriteBytes(msg);
                rpcReq.Content = bb.Array;
            }
            catch (UnsupportedEncodingException e)
            {
                System.Console.WriteLine(e.ToString());
                System.Console.Write(e.StackTrace);
            }

            contentSerializer = rpcReq.Serializer;
            return(true);
        }
 /// <seealso cref= remoting.CustomSerializer#serializeHeader(com.alipay.remoting.rpc.RequestCommand, InvokeContext) </seealso>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: @Override public <T extends com.alipay.remoting.rpc.RequestCommand> boolean serializeHeader(T request, com.alipay.remoting.InvokeContext invokeContext) throws com.alipay.remoting.exception.SerializationException
 public override bool serializeHeader(RequestCommand request, InvokeContext invokeContext)
 {
     if (request is RpcRequestCommand)
     {
         RpcRequestCommand requestCommand = (RpcRequestCommand)request;
         try
         {
             requestCommand.Header = Encoding.UTF8.GetBytes(DefaultExecutorSelector.EXECUTOR1);
         }
         catch (UnsupportedEncodingException)
         {
             System.Console.Error.WriteLine("UnsupportedEncodingException");
         }
         return(true);
     }
     return(false);
 }
 /// <seealso cref= remoting.CustomSerializer#deserializeHeader(com.alipay.remoting.rpc.RequestCommand) </seealso>
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: @Override public <T extends com.alipay.remoting.rpc.RequestCommand> boolean deserializeHeader(T request) throws com.alipay.remoting.exception.DeserializationException
 public override bool deserializeHeader(RequestCommand request)
 {
     if (request is RpcRequestCommand)
     {
         RpcRequestCommand requestCommand = (RpcRequestCommand)request;
         byte[]            header         = requestCommand.Header;
         try
         {
             requestCommand.RequestHeader = Encoding.UTF8.GetString(header);
         }
         catch (UnsupportedEncodingException)
         {
             System.Console.Error.WriteLine("UnsupportedEncodingException");
         }
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
        /// <summary>
        /// Convert application request object to remoting request command.
        /// </summary>
        /// <param name="request"> </param>
        /// <param name="conn"> </param>
        /// <param name="timeoutMillis">
        /// @return </param>
        /// <exception cref="CodecException"> </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: protected RemotingCommand toRemotingCommand(Object request, Connection conn, InvokeContext invokeContext, int timeoutMillis) throws exception.SerializationException
        protected internal virtual RemotingCommand toRemotingCommand(object request, Connection conn, InvokeContext invokeContext, int timeoutMillis)
        {
            RpcRequestCommand command = (RpcRequestCommand)CommandFactory.createRequestCommand(request);

            if (null != invokeContext)
            {
                // set client custom serializer for request command if not null
                object clientCustomSerializer = invokeContext.get(InvokeContext.BOLT_CUSTOM_SERIALIZER);
                if (null != clientCustomSerializer)
                {
                    try
                    {
                        command.Serializer = ((byte?)clientCustomSerializer).Value;
                    }
                    catch (System.InvalidCastException)
                    {
                        //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                        throw new System.ArgumentException("Illegal custom serializer [" + clientCustomSerializer + "], the type of value should be [byte], but now is [" + clientCustomSerializer.GetType().FullName + "].");
                    }
                }

                // enable crc by default, user can disable by set invoke context `false` for key `InvokeContext.BOLT_CRC_SWITCH`
                bool?crcSwitch = (bool)invokeContext.get(InvokeContext.BOLT_CRC_SWITCH, ProtocolSwitch.CRC_SWITCH_DEFAULT_VALUE);
                if (null != crcSwitch && crcSwitch.HasValue && crcSwitch.Value)
                {
                    command.ProtocolSwitch = ProtocolSwitch.create(new int[] { ProtocolSwitch.CRC_SWITCH_INDEX });
                }
            }
            else
            {
                // enable crc by default, if there is no invoke context.
                command.ProtocolSwitch = ProtocolSwitch.create(new int[] { ProtocolSwitch.CRC_SWITCH_INDEX });
            }
            command.Timeout = timeoutMillis;
            //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            command.RequestClass  = request.GetType();
            command.InvokeContext = invokeContext;
            command.serialize();
            logDebugInfo(command);
            return(command);
        }
        /// <seealso cref= CustomSerializer#serializeContent(RequestCommand, InvokeContext) </seealso>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: @Override public <T extends com.alipay.remoting.rpc.RequestCommand> boolean serializeContent(T req, com.alipay.remoting.InvokeContext invokeContext) throws com.alipay.remoting.exception.SerializationException
        public override bool serializeContent(RequestCommand req, InvokeContext invokeContext)
        {
            serialFlag.set(true);
            RpcRequestCommand rpcReq = (RpcRequestCommand)req;

            if (string.Equals(SERIALTYPE1_value, (string)invokeContext.get(SERIALTYPE_KEY)))
            {
                RequestBody bd = (RequestBody)rpcReq.RequestObject;
                int         id = bd.Id;
                byte[]      msg;
                try
                {
                    msg = Encoding.UTF8.GetBytes(bd.Msg);
                    IByteBuffer bb = UnpooledByteBufferAllocator.Default.Buffer(4 + msg.Length);
                    bb.WriteInt(id);
                    bb.WriteBytes(msg);
                    rpcReq.Content = bb.Array;
                }
                catch (UnsupportedEncodingException e)
                {
                    System.Console.WriteLine(e.ToString());
                    System.Console.Write(e.StackTrace);
                }
            }
            else
            {
                try
                {
                    rpcReq.Content = Encoding.UTF8.GetBytes(UNIVERSAL_REQ);
                }
                catch (UnsupportedEncodingException e)
                {
                    System.Console.WriteLine(e.ToString());
                    System.Console.Write(e.StackTrace);
                }
            }

            return(true);
        }