예제 #1
0
            public void Process(IHttpRequest httpRequest, IHttpResponse httpResponse)
            {
                try {
                    Request coapRequest = HttpTranslator.GetCoapRequest(httpRequest, _localResource, _proxyingEnabled);

                    WaitFuture <Request, Response> wf = new WaitFuture <Request, Response>(coapRequest);
                    _httpStack._exchangeMap[coapRequest] = wf;

                    // send the coap request to the upper layers
                    _httpStack._executor.Start(() => _httpStack.DoReceiveMessage(coapRequest));

                    Response coapResponse;
                    try {
                        wf.Wait(GatewayTimeout);
                        coapResponse = wf.Response;
                    }
                    catch (System.Threading.ThreadInterruptedException) {
                        httpResponse.StatusCode = (int)HttpStatusCode.InternalServerError;
                        return;
                    }

                    if (coapResponse == null)
                    {
                        httpResponse.StatusCode = (int)HttpStatusCode.GatewayTimeout;
                    }
                    else
                    {
                        HttpTranslator.GetHttpResponse(httpRequest, coapResponse, httpResponse);
                    }
                }
                catch (TranslationException) {
                    httpResponse.StatusCode = (int)HttpStatusCode.BadGateway;
                }
            }
예제 #2
0
 public WaitFuture<IServiceRequest, IServiceResponse> Send(IServiceRequest request)
 {
     WaitFuture<IServiceRequest, IServiceResponse> wf = new WaitFuture<IServiceRequest, IServiceResponse>(request);
     _channel._waitingRequests[request.Token] = wf;
     _sendingQueue.Enqueue(request);
     return wf;
 }
예제 #3
0
            public void Process(IHttpRequest httpRequest, IHttpResponse httpResponse)
            {
                try
                {
                    Request coapRequest = HttpTranslator.GetCoapRequest(httpRequest, _localResource, _proxyingEnabled);

                    WaitFuture<Request, Response> wf = new WaitFuture<Request, Response>(coapRequest);
                    _httpStack._exchangeMap[coapRequest] = wf;

                    // send the coap request to the upper layers
                    _httpStack._executor.Start(() => _httpStack.DoReceiveMessage(coapRequest));

                    Response coapResponse;
                    try
                    {
                        wf.Wait(GatewayTimeout);
                        coapResponse = wf.Response;
                    }
                    catch (System.Threading.ThreadInterruptedException)
                    {
                        httpResponse.StatusCode = (Int32)HttpStatusCode.InternalServerError;
                        return;
                    }

                    if (coapResponse == null)
                    {
                        httpResponse.StatusCode = (Int32)HttpStatusCode.GatewayTimeout;
                    }
                    else
                    {
                        HttpTranslator.GetHttpResponse(httpRequest, coapResponse, httpResponse);
                    }
                }
                catch (TranslationException)
                {
                    httpResponse.StatusCode = (Int32)HttpStatusCode.BadGateway;
                }
            }