private void WebRequestCallback(IAsyncResult result) { if (false == httpListener.IsListening) return; HttpListenerContext context = httpListener.EndGetContext(result); string requestId = IncidentIdGenerator.GenerateIncidentId(); ThreadContext.Properties["requestId"] = requestId; httpListener.BeginGetContext(WebRequestCallback, httpListener); BufferedInputStream requestStream = new BufferedInputStream(); requestStream.BufferStream(context.Request.InputStream); HttpListenerWrappedContext wrappedContext = new HttpListenerWrappedContext( context, requestStream, applicationRootUrl, applicationPath); CurrentHttpContext.Current = wrappedContext; wrappedContext.SetRequestId(requestId); if (log.IsDebugEnabled) log.DebugFormat("Received request: {0}", requestStream.DataToString(Encoding.UTF8)); IHttpResponse response = null; try { response = detergentHttpHandler.ProcessRequest(wrappedContext); } catch (Exception ex) { log.Error("Error processing the request", ex); response = new ExceptionStackHttpResponse(HttpStatusCode.InternalServerError, ex); response.Send(wrappedContext); return; } try { if (response != null) { if (log.IsDebugEnabled) log.DebugFormat("Sending response type {0}", response.GetType().FullName); response.Send(wrappedContext); } else if (log.IsDebugEnabled) log.Debug("Request has been processed without any response"); } catch (Exception ex) { log.Error("Could not send the response", ex); response = new ExceptionStackHttpResponse(HttpStatusCode.InternalServerError, ex); response.Send(wrappedContext); } }
private void WebRequestCallback(IAsyncResult result) { if (false == httpListener.IsListening) { return; } HttpListenerContext context = httpListener.EndGetContext(result); string requestId = IncidentIdGenerator.GenerateIncidentId(); ThreadContext.Properties["requestId"] = requestId; httpListener.BeginGetContext(WebRequestCallback, httpListener); BufferedInputStream requestStream = new BufferedInputStream(); requestStream.BufferStream(context.Request.InputStream); HttpListenerWrappedContext wrappedContext = new HttpListenerWrappedContext( context, requestStream, applicationRootUrl, applicationPath); CurrentHttpContext.Current = wrappedContext; wrappedContext.SetRequestId(requestId); if (log.IsDebugEnabled) { log.DebugFormat("Received request: {0}", requestStream.DataToString(Encoding.UTF8)); } IHttpResponse response = null; try { response = detergentHttpHandler.ProcessRequest(wrappedContext); } catch (Exception ex) { log.Error("Error processing the request", ex); response = new ExceptionStackHttpResponse(HttpStatusCode.InternalServerError, ex); response.Send(wrappedContext); return; } try { if (response != null) { if (log.IsDebugEnabled) { log.DebugFormat("Sending response type {0}", response.GetType().FullName); } response.Send(wrappedContext); } else if (log.IsDebugEnabled) { log.Debug("Request has been processed without any response"); } } catch (Exception ex) { log.Error("Could not send the response", ex); response = new ExceptionStackHttpResponse(HttpStatusCode.InternalServerError, ex); response.Send(wrappedContext); } }