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; } }
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; }
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; } }