예제 #1
0
        /// <summary>
        /// This state manages connection requests from HTTP browsers.
        /// </summary>
        /// <param name="context">The current context.</param>
        /// <param name="job">The current job.</param>
        /// <param name="Data">The data in the request.</param>
        /// <returns>Returns false if the connection is successful, true if the connection should be reset.</returns>
        public override bool ConnectionRequest(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, 
            SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data)
        {
            RQCallbackServer Request = Data.ContractRequest;
            RSCallbackServer Response = Data.ContractResponse;

            Response.ServerContextID = context.SignatureID;
            Response.Status = CH.HTTPCodes.OK_200;
            Response.MessageResponse = null;
            Response.MessageRequestType = typeof(HTTPRequestMessage);

            context.URILocal = Request.LocalUri;
            context.URIRemote = Request.RemoteUri;
            context.ProtocolCommandID = Data.Sender;
            context.ProtocolContextID = Request.ProtocolContextID;

            context.ExpiryTimeSet();
            context.ChangeState("AwaitRequest");

            return false;
        }
예제 #2
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;
        }