Пример #1
0
        /// <summary>
        /// This method receives requests from the HTTP agent and passes the request to the Site Controller.
        /// </summary>
        /// <param name="httpContext">The current context.</param>
        /// <param name="job">The job.</param>
        /// <param name="Data">The request data.</param>
        /// <returns>Returns true if the connection should be reset.</returns>
        public override bool Receive(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, 
            SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data)
        {
            RQCallbackServer Request = Data.ContractRequest;
            RSCallbackServer Response = Data.ContractResponse;

            HTTPRequestMessage httpRQ = null;
            RQRSContract<SiteControllerRequest, SiteControllerResponse> Env = null;
            try
            {
                httpRQ = Request.Message as HTTPRequestMessage;

                Env = context.EnvelopeHelper.Get(mSiteManager) as
                    RQRSContract<SiteControllerRequest, SiteControllerResponse>;

                context.SenderIdentitySet((IXimuraRQRSEnvelope)Env);
                Env.DestinationAddress = new EnvelopeAddress(mSiteManager, "Receive");

                //HTTPServerContext httpContext = context as HTTPServerContext;

                Env.ContractRequest.MessageMethod = httpRQ.Instruction.Verb;
                Env.ContractRequest.Message = httpRQ;
                Env.ContractRequest.MessageUri = ExtractUri(httpRQ, context.URILocal);
                Env.ContractRequest.MessageUserAgent = ExtractUserAgent(httpRQ);

                Env.ContractRequest.ServerType = "http";

                Env.ContractRequest.URILocal = context.URILocal;
                Env.ContractRequest.URIRemote = context.URIRemote;

                context.ExpiryTime = null;

                Guid signatureID = context.SignatureID.Value;
                //Send the request synchronously to the server using the current job, 
                //so that it is processed on the current thread.
                job.ProcessRequest((IXimuraRQRSEnvelope)Env);

                //Check whether the context has been reset during the call to the Site Controller.
                if (context == null || !context.SignatureID.HasValue || context.SignatureID.Value != signatureID)
                {
                    Response.Status = CH.HTTPCodes.InternalServerError_500;
                    Response.CloseNotify = true;
                    return false;
                }

                context.ExpiryTimeSet();

                Response.MessageResponse = Env.ContractResponse.Message;
                Response.MessageRequestType = typeof(HTTPRequestMessage);
                Response.MaxLength = 2000000;

                Response.Status = CH.HTTPCodes.OK_200;
            }
            catch (Exception ex)
            {
                Response.Status = CH.HTTPCodes.InternalServerError_500;
                Response.Substatus = ex.Message;
            }
            finally
            {
                Response.ProtocolContextID = Request.ProtocolContextID;
                Response.ServerContextID = context.SignatureID;

                if (httpRQ != null || httpRQ.ObjectPoolCanReturn)
                {
                    httpRQ.ObjectPoolReturn();
                }
                if (Env != null || Env.ObjectPoolCanReturn)
                {
                    Env.ObjectPoolReturn();
                }

                context.ChangeState("AwaitRequest");
            }
            return false;
        }