Ejemplo n.º 1
0
        private void SendResponse(httpResponseType outgoingResponse)
        {
            MemoryStream msgBody = new MemoryStream();
            XmlSerializer xs = new XmlSerializer(typeof(httpResponseType));
            xs.Serialize(msgBody, outgoingResponse);

            Message msgResponse = new Message(x_httpResponseMessageType, msgBody);
            s_currentConversation.Send(msgResponse, s_connection, s_transaction);        
        }
Ejemplo n.º 2
0
        private void ServiceRequest(httpRequestType incomingRequest)
        {
            RequestFilterAction reqAction = MatchRequestFilter(incomingRequest);

            switch (reqAction)
            {
                case RequestFilterAction.Deny:
                    ErrorConversation(2, "Proxy does not accept this type of request to given URL.");
                    return;
            }

            HttpWebRequest outgoingRequest = CreateWebRequest(incomingRequest);

            if (outgoingRequest == null)
            {
                SavePendingRequest(incomingRequest);
                BeginTimer();
                return;
            }

            HttpWebResponse incomingResponse = null;
            ResponseFilterAction respAction = TryWebRequest(outgoingRequest, out incomingResponse);
            SqlContext.Pipe.Send(respAction.ToString());

            switch (respAction)
            {
                case ResponseFilterAction.Respond:
                    httpResponseType outgoingResponse = CreateBrokerResponse(incomingResponse);
                    SendResponse(outgoingResponse);
                    EndConversation();

                    // Deletes the pending request, if there was one stored...
                    DeletePendingRequest();
                    break;

                case ResponseFilterAction.Retry:
                    if (m_numRetries == m_numRetriesUsed)
                    {
                        ErrorConversation(5, m_lastError);
                    }
                    else
                    {
                        SavePendingRequest(incomingRequest);
                        BeginTimer();
                    }
                    break;

                case ResponseFilterAction.Error:
                    if (incomingResponse != null)
                    {
                        ErrorConversation(4, m_lastError);
                    }
                    break;
            }
        }
Ejemplo n.º 3
0
        private httpResponseType CreateBrokerResponse(HttpWebResponse incomingResponse)
        {
            httpResponseType outgoingResponse = new httpResponseType();
            outgoingResponse.protocolVersion = incomingResponse.ProtocolVersion.ToString();
            outgoingResponse.statusCode = (int)incomingResponse.StatusCode;
            SqlContext.Pipe.Send("statusCode = " + outgoingResponse.statusCode);
            outgoingResponse.statusDescription = incomingResponse.StatusDescription;

            List<headerType> headers = new List<headerType>();

            if (incomingResponse.ContentEncoding != null)
            {
                headerType h = new headerType();
                h.name = "Content-Encoding";
                h.value = incomingResponse.ContentEncoding;
                headers.Add(h);
            }

            if (incomingResponse.ContentLength >= 0)
            {
                headerType h = new headerType();
                h.name = "Content-Length";
                h.value = incomingResponse.ContentLength.ToString();
                headers.Add(h);
            }

            if (incomingResponse.ContentType != null)
            {
                headerType h = new headerType();
                h.name = "Content-Type";
                h.value = incomingResponse.ContentType;
                headers.Add(h);
            }

            if (incomingResponse.LastModified != null)
            {
                headerType h = new headerType();
                h.name = "Last-Modified";
                h.value = incomingResponse.LastModified.ToString();
                headers.Add(h);
            }

            if (incomingResponse.Server != null)
            {
                headerType h = new headerType();
                h.name = "Server";
                h.value = incomingResponse.Server;
                headers.Add(h);
            }
            SqlContext.Pipe.Send("done common headers");
            for (int i = 0; i < incomingResponse.Headers.Count; i++)
            {
                headerType h = new headerType();
                h.name = incomingResponse.Headers.Keys[i];
                h.value = incomingResponse.Headers[i];
                headers.Add(h);
            }
            if (headers.Count > 0)
            {
                outgoingResponse.headers = headers.ToArray();
            }
            SqlContext.Pipe.Send("done headers");

            int n;
            byte[] buffer = new byte[512];
            MemoryStream body = new MemoryStream();

            Stream ins = incomingResponse.GetResponseStream();
            while ((n = ins.Read(buffer, 0, 512)) > 0)
            {
                body.Write(buffer, 0, n);
            }
            SqlContext.Pipe.Send("done copying response stream");

            outgoingResponse.body = body.ToArray();
            incomingResponse.Close();
            return outgoingResponse;
        }