Ejemplo n.º 1
0
            public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
            {
                if (requestMsg != null)
                {
                    return(NextChannelSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream,
                                                          out responseMsg, out responseHeaders, out responseStream));
                }

                IHttpRequest  request  = GetRequest(requestHeaders, requestStream);
                IHttpResponse response = GetResponse(request);

                foreach (IServiceProvider provider in _webServer._serviceProviders)
                {
                    if (provider.Accept(request))
                    {
                        provider.Process(request, response);
                        break;
                    }
                }

                response.AppendHeader("Server", _webServer._name);

                responseHeaders = (response as RemotingHttpResponse).Headers;
                responseStream  = response.OutputStream;
                responseMsg     = null;

                return(ServerProcessing.Complete);
            }
Ejemplo n.º 2
0
    public ServerProcessing ProcessMessage(
        IServerChannelSinkStack sinkStack, IMessage requestMsg,
        ITransportHeaders requestHeaders, Stream requestStream,
        out IMessage responseMsg, out ITransportHeaders responseHeaders,
        out Stream responseStream)
    {
        if (requestMsg != null || !ShouldIntercept(requestHeaders))
        {
            return(NextChannelSink.ProcessMessage(
                       sinkStack, requestMsg, requestHeaders, requestStream,
                       out responseMsg, out responseHeaders, out responseStream));
        }

        responseHeaders = new TransportHeaders();
        responseHeaders["Content-Type"] = "text/xml";
        responseStream = new MemoryStream(Encoding.UTF8.GetBytes(
                                              @"<?xml version=""1.0""?><!DOCTYPE cross-domain-policy SYSTEM "
                                              + @"""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">"
                                              + @"<cross-domain-policy><allow-access-from domain=""*"" />"
                                              + @"</cross-domain-policy>"))
        {
            Position = 0
        };
        responseMsg = null;
        return(ServerProcessing.Complete);
    }
Ejemplo n.º 3
0
        private void ProcessRequestInternal(Stream requestStream, GiopServerConnection serverCon)
        {
#if DEBUG
            OutputHelper.LogStream(requestStream);
#endif
            requestStream.Seek(0, SeekOrigin.Begin); // assure stream is read from beginning in formatter
            // the out params returned form later sinks
            IMessage          responseMsg;
            ITransportHeaders responseHeaders;
            Stream            responseStream;

            // create the sink stack for async processing of message
            ServerChannelSinkStack sinkStack = new ServerChannelSinkStack();
            sinkStack.Push(this, serverCon);
            // empty transport headers for this protocol
            ITransportHeaders requestHeaders = new TransportHeaders();
            requestHeaders[GiopServerConnection.SERVER_TR_HEADER_KEY] = serverCon;
            requestHeaders[CommonTransportKeys.IPAddress]             = serverCon.TransportHandler.GetPeerAddress();

            // next sink will process the request-message
            ServerProcessing result =
                NextChannelSink.ProcessMessage(sinkStack, null, /* no RequestMessage in transport handler */
                                               requestHeaders, requestStream,
                                               out responseMsg, out responseHeaders,
                                               out responseStream);
            switch (result)
            {
            case ServerProcessing.Complete:
                try {
                    sinkStack.Pop(this);
                } catch (Exception) { }
#if DEBUG
                Debug.WriteLine("Send response sync");
                OutputHelper.LogStream(responseStream);
#endif
                serverCon.TransportHandler.SendResponse(responseStream);
                break;

            case ServerProcessing.Async:
                sinkStack.StoreAndDispatch(this, serverCon);     // this sink wants to handle response
                // no reply, async
                break;

            case ServerProcessing.OneWay:
                try {
                    sinkStack.Pop(this);
                } catch (Exception) { }
                // no message to send
                break;

            default:
                // should not arrive here
                Trace.WriteLine("internal problem, invalid processing state: " + result);
                throw new omg.org.CORBA.INTERNAL(568, omg.org.CORBA.CompletionStatus.Completed_MayBe);
            }
        }
Ejemplo n.º 4
0
        public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack,
                                               IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream,
                                               out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            if (requestHeaders["SOAPAction"] != null)
            {
                // pass to next sink if this is a SOAP request with SOAPAction header.
                return(NextChannelSink.ProcessMessage(sinkStack,
                                                      requestMsg, requestHeaders, requestStream,
                                                      out responseMsg, out responseHeaders, out responseStream));
            }

            XmlRpcHttpRequestConfig requestConfig = GetConfig(requestHeaders);

            try
            {
                MethodCall call = DeserializeRequest(requestHeaders, requestStream, requestConfig);
                sinkStack.Push(this, call);
                // forward to next sink in chain - pass request stream as null to
                // indicate that we have deserialized the request
                NextChannelSink.ProcessMessage(sinkStack, call, requestHeaders, null,
                                               out responseMsg, out responseHeaders, out responseStream);
                SerializeResponse(responseMsg, ref responseHeaders, ref responseStream, requestConfig);
            }
            catch (Exception ex)
            {
                responseMsg    = new ReturnMessage(ex, (IMethodCallMessage)requestMsg);
                responseStream = new MemoryStream();
                XmlRpcResponseSerializer serializer    = new XmlRpcResponseSerializer();
                XmlRpcResponse           faultResponse = new XmlRpcResponse();
                faultResponse.Fault = new XmlRpcFault(0, ex.Message);
                serializer.WriteResponse(responseStream, faultResponse, requestConfig, TypeSerializerFactory);
                responseHeaders = new TransportHeaders();
                responseHeaders["Content-Type"] = "text/xml; charset=\"utf-8\"";
            }

            return(ServerProcessing.Complete);
        }
Ejemplo n.º 5
0
        void ProcessMessage(IPEndPoint remote, ITransportHeaders requestHeaders, Stream requestStream)
        {
            // parse request uri
            var    url = requestHeaders[CommonTransportKeys.RequestUri].ToString();
            string objectUri;

            UdpChannelHelper.Parse(url, out objectUri);
            objectUri = objectUri ?? url;
            requestHeaders[CommonTransportKeys.RequestUri] = objectUri;

            IMessage          responseMsg;
            ITransportHeaders responseHeaders;
            Stream            responseStream;

            // process message
            var stack = new ServerChannelSinkStack();

            stack.Push(this, null);
            var operation = NextChannelSink.ProcessMessage(stack, null, requestHeaders, requestStream,
                                                           out responseMsg, out responseHeaders, out responseStream);

            switch (operation)
            {
            case ServerProcessing.Complete:
                stack.Pop(this);
                var transport = new UdpTransport(new UdpClient());
                transport.Write(responseHeaders, responseStream, remote);
                break;

            case ServerProcessing.Async:
                stack.StoreAndDispatch(NextChannelSink, null);
                break;

            case ServerProcessing.OneWay:
                break;
            }
        }
Ejemplo n.º 6
0
        private void ProcessMessage(object waitCallbackState)
        {
            var requestMessage = (NullMessages.RequestMessage)waitCallbackState;

            // replace full url with object url
            var    url = requestMessage.RequestHeaders[CommonTransportKeys.RequestUri].ToString();
            string objectUri;

            NullChannel.ParseUrl(url, out objectUri);
            objectUri = objectUri ?? url;
            requestMessage.RequestHeaders[CommonTransportKeys.RequestUri] = objectUri;
            requestMessage.Message.Properties["__Uri"] = objectUri;

            // add client address property for compatibility
            var callContext = requestMessage.Message.Properties["__CallContext"] as LogicalCallContext;

            callContext.SetData(ClientAddressSink.CallContextSlotName, IPAddress.Loopback);

            IMessage          responseMsg;
            ITransportHeaders responseHeaders;
            Stream            responseStream;

            // create sink stack to process request message
            var stack = new ServerChannelSinkStack();

            stack.Push(this, null);

            // process request message
            ServerProcessing serverProcessing;

            if (NextChannelSink != null)
            {
                // full processing mode, with deserialization
                serverProcessing = NextChannelSink.ProcessMessage(stack, null,
                                                                  requestMessage.RequestHeaders, requestMessage.RequestStream,
                                                                  out responseMsg, out responseHeaders, out responseStream);
            }
            else
            {
                // fast processing mode, bypassing deserialization
                serverProcessing = ChannelServices.DispatchMessage(stack, requestMessage.Message, out responseMsg);
                responseHeaders  = null;
                responseStream   = null;
            }

            // send back the reply
            switch (serverProcessing)
            {
            case ServerProcessing.Complete:
                stack.Pop(this);
                NullMessages.AddResponse(requestMessage, new NullMessages.ResponseMessage
                {
                    Message         = responseMsg,
                    ResponseHeaders = responseHeaders,
                    ResponseStream  = responseStream
                });
                break;

            case ServerProcessing.Async:
                stack.StoreAndDispatch(NextChannelSink, null);
                break;

            case ServerProcessing.OneWay:
                stack.Pop(this);
                break;
            }
        }