Esempio n. 1
0
        /// <summary>
        /// The Request will be processed here.
        /// The main function in this class
        /// </summary>
        public void ProcessRequest()
        {
            //Get references to sockets input & output streams
            m_stream = new NetworkStream(m_socket, FileAccess.ReadWrite, true);
            MemoryStream memoryStream = new MemoryStream();

            //Reads the Header of HTTP Message
            try {
                ReadHeaders();
            } catch (NotSupportedException e) {
                SendError(500, "Close");
                m_socket.Close();
                m_stream.Close();
                return;
            }
            AbstractHessianInput  inHessian      = new CHessianInput(m_stream);
            AbstractHessianOutput tempOutHessian = new CHessianOutput(memoryStream);

            /// Proxy object
            CHessianSkeleton objectSkeleton = null;

            try {
                objectSkeleton = new CHessianSkeleton(m_apiType, m_Service);
                objectSkeleton.invoke(inHessian, tempOutHessian);
                WriteResponse(memoryStream.ToArray());
            } catch (Exception e) {
                SendError(500, "Close");
            } finally {
                m_socket.Close();
                m_stream.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Execute a request.
        /// </summary>
        public void ProcessRequest(HttpContext ctx)
        {
            try
            {
                context = ctx;
                Stream       inStream  = ctx.Request.InputStream;
                MemoryStream outStream = new MemoryStream();

                ctx.Response.BufferOutput = true;
                ctx.Response.ContentType  = "text/xml";

                AbstractHessianInput  inHessian  = new CHessianInput(inStream);
                AbstractHessianOutput outHessian = new CHessianOutput(outStream);

                if (m_objectSkeleton == null)
                {
                    //Vieleicht das Interface als API übergeben???
                    m_objectSkeleton = new CHessianSkeleton(this.GetType(), this);
                }

                m_objectSkeleton.invoke(inHessian, outHessian);
                byte [] arrData   = outStream.ToArray();
                int     intLength = arrData.Length;
                //Set length
                ctx.Response.AppendHeader("Content-Length", intLength.ToString());
                //Write stream
                ctx.Response.OutputStream.Write(arrData, 0, intLength);
                return;
            }
            catch (Exception ex)
            {
                ctx.Response.StatusCode        = 500; // "Internal server error"
                ctx.Response.StatusDescription = ex.Message;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// The Request will be processed here.
        /// The main function in this class
        /// </summary>
        public void ProcessRequest()
        {
            //Get references to sockets input & output streams
            m_stream = new NetworkStream(m_socket, FileAccess.ReadWrite, true);
            MemoryStream memoryStream = new MemoryStream();
            //BufferedStream bs = new BufferedStream(m_stream);

            var serviceUrl = string.Empty;

            //Reads the Header of HTTP Message
            try
            {
                serviceUrl = ReadHeaders();
            }
            catch (NotSupportedException e)
            {
                SendError(500, "Close");
                m_socket.Shutdown(SocketShutdown.Both);
                m_socket.Close();
                m_stream.Close();
                return;
            }
            AbstractHessianInput  inHessian      = new CHessianInput(m_stream);
            AbstractHessianOutput tempOutHessian = new CHessianOutput(memoryStream);

            /// Proxy object
            CHessianSkeleton objectSkeleton = null;

            try
            {
                var m_Service = ServiceFactory.SelectService(serviceUrl);
                if (m_Service == null)
                {
                    throw new NotSupportedException("This ServiceUrl is not supported");
                }
                objectSkeleton = new CHessianSkeleton(m_Service.GetType(), m_Service);
                //SendOk(bs, 0);
                objectSkeleton.invoke(inHessian, tempOutHessian);
                WriteResponse(memoryStream.ToArray());
            }
            catch (Exception e)
            {
                SendError(500, e.GetBaseException().Message);
            }
            finally
            {
                m_socket.Shutdown(SocketShutdown.Both);
                m_socket.Close();
                m_stream.Close();
            }
        }
Esempio n. 4
0
        public void TestEnumSerializing()
        {
            MemoryStream   stream = new MemoryStream();
            CHessianOutput out1   = new CHessianOutput(stream);

            TestDto obj = new TestDto();

            out1.StartReply();
            out1.WriteObject(obj);
            out1.CompleteReply();
            byte[] data = stream.ToArray();

            File.WriteAllBytes(@"C:\Users\disap\Desktop\Projects\hessianscharp\HessianTestProject\test.txt", data);
            CHessianInput input  = new CHessianInput(new MemoryStream(data));
            var           result = input.ReadReply(typeof(TestDto));

            Assert.IsTrue(true);
        }
Esempio n. 5
0
        internal AbstractHessianOutput GetHessianOutput(Stream os)
        {
            AbstractHessianOutput abstractHessianOutput;

            if (_isHessian2Request)
            {
                abstractHessianOutput = new CHessian2Output(os);
            }
            else
            {
                CHessianOutput out1 = new CHessianOutput(os);
                abstractHessianOutput = out1;

                if (_isHessian2Reply)
                {
                    out1.SetVersion(2);
                }
            }
            return(abstractHessianOutput);
        }
        /// <summary>
        /// Translates the method call to a request byte array.
        /// </summary>
        /// <param name="arrMethodArgs"></param>
        /// <param name="methodInfo"></param>
        /// <returns></returns>
        protected byte[] GetRequestBytes(object[] arrMethodArgs, MethodInfo methodInfo)
        {
            Type[]         argumentTypes  = GetArgTypes(arrMethodArgs);
            MemoryStream   memoryStream   = new MemoryStream(4096);
            CHessianOutput cHessianOutput = this.GetHessianOutput(memoryStream);
            string         strMethodName  = methodInfo.Name;

            if (m_CHessianProxyFactory.IsOverloadEnabled)
            {
                if (arrMethodArgs != null)
                {
                    strMethodName = strMethodName + "__" + arrMethodArgs.Length;
                }
                else
                {
                    strMethodName = strMethodName + "__0";
                }
            }
            cHessianOutput.Call(strMethodName, arrMethodArgs);
            return(memoryStream.ToArray());
        }
        /// <summary>
        /// Instantiation of the hessian output (not cached)
        /// </summary>
        /// <param name="stream">Strean for HessianOutput - Instantiation</param>
        /// <returns>New HessianOutput - Instance</returns>
        protected CHessianOutput GetHessianOutput(Stream stream)
        {
            CHessianOutput cHessianOut = new CHessianOutput(stream);

            return(cHessianOut);
        }
Esempio n. 8
0
        public async Task <ReturnT> InvokeService(MethodBase method, List <string> paramTypes, params object[] parameters)
        {
            var methodName = method.Name.Substring(0, 1).ToLower() + method.Name.Substring(1);
            var request    = new RpcRequest()
            {
                createMillisTime = DateTimeExtensions.CurrentTimeMillis(),
                accessToken      = _executorOption.Value.AccessToken,
                className        = "com.xxl.job.core.biz.AdminBiz",
                methodName       = methodName,
                parameterTypes   = new ArrayList(paramTypes.Select(item => new Class(item)).ToArray()),
                parameters       = new ArrayList(parameters)
            };

            var ms         = new MemoryStream();
            var serializer = new CHessianOutput(ms);

            serializer.WriteObject(request);
            var responseBody = ms.ToArray();

            int triedTimes = 0;

            while (triedTimes++ < _addresses.Count)
            {
                var item = _addresses[_currentAdminIndex];
                _currentAdminIndex = (_currentAdminIndex + 1) % _addresses.Count;
                if (!item.CheckAccessable())
                {
                    continue;
                }

                Stream responseStream;
                try
                {
                    var content = new ByteArrayContent(responseBody);
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                    var responseMessage = await _client.PostAsync(item.RequestUri, content);

                    responseMessage.EnsureSuccessStatusCode();
                    responseStream = await responseMessage.Content.ReadAsStreamAsync();

                    item.Reset();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "request admin error.");
                    item.SetFail();
                    continue;
                }

                var rpcResponse = (RpcResponse) new CHessianInput(responseStream).ReadObject();
                if (rpcResponse == null)
                {
                    throw new Exception("xxl-rpc response not found.");
                }
                if (rpcResponse.IsError)
                {
                    throw new Exception(rpcResponse.error);
                }
                else
                {
                    return(rpcResponse.result as ReturnT);
                }
            }

            throw new Exception("xxl-rpc server address not accessable.");
        }
Esempio n. 9
0
        /// <summary>
        /// Instantiation of the hessian output (not cached)
        /// </summary>
        /// <param name="stream">Strean for HessianOutput - Instantiation</param>
        /// <returns>New HessianOutput - Instance</returns>
        private CHessianOutput GetHessianOutput(Stream stream)
        {
            CHessianOutput cHessianOut = new CHessianOutput(stream);

            return(cHessianOut);
        }