public void inputReady(NHttpServerConnection conn, ContentDecoder decoder) { try { ProtocolState protocolState = SourceContext.getState(conn); if (protocolState != ProtocolState.REQUEST_HEAD && protocolState != ProtocolState.REQUEST_BODY) { handleInvalidState(conn, "Request message body data received"); return; } SourceContext.updateState(conn, ProtocolState.REQUEST_BODY); SourceRequest request = SourceContext.getRequest(conn); int readBytes = request.read(conn, decoder); if (readBytes > 0) { metrics.incrementBytesReceived(readBytes); } } catch (IOException e) { logIOException(conn, e); informReaderError(conn); SourceContext.updateState(conn, ProtocolState.CLOSED); sourceConfiguration.getSourceConnections().shutDownConnection(conn); } }
public void requestReceived(NHttpServerConnection conn) { try { HttpContext _context = conn.getContext(); _context.setAttribute(PassThroughConstants.REQ_ARRIVAL_TIME, System.currentTimeMillis()); if (!SourceContext.assertState(conn, ProtocolState.REQUEST_READY) && !SourceContext.assertState(conn, ProtocolState.WSDL_RESPONSE_DONE)) { handleInvalidState(conn, "Request received"); return; } // we have received a message over this connection. So we must inform the pool sourceConfiguration.getSourceConnections().useConnection(conn); // at this point we have read the HTTP Headers SourceContext.updateState(conn, ProtocolState.REQUEST_HEAD); SourceRequest request = new SourceRequest(sourceConfiguration, conn.getHttpRequest(), conn); SourceContext.setRequest(conn, request); request.start(conn); metrics.incrementMessagesReceived(); /** *** */ String method = request.getRequest() != null ? request.getRequest().getRequestLine().getMethod().toUpperCase() : ""; OutputStream os = null; if ("GET".equals(method) || "HEAD".equals(method)) { HttpContext context = request.getConnection().getContext(); ContentOutputBuffer outputBuffer = new SimpleOutputBuffer(8192, new HeapByteBufferAllocator()); // ContentOutputBuffer outputBuffer // = new SharedOutputBuffer(8192, conn, new // HeapByteBufferAllocator()); context.setAttribute("synapse.response-source-buffer", outputBuffer); os = new ContentOutputStream(outputBuffer); } sourceConfiguration .getWorkerPool() .execute(new ServerWorker(request, sourceConfiguration, os)); } catch (HttpException e) { log.error(e.getMessage(), e); informReaderError(conn); SourceContext.updateState(conn, ProtocolState.CLOSED); sourceConfiguration.getSourceConnections().shutDownConnection(conn); } catch (IOException e) { logIOException(conn, e); informReaderError(conn); SourceContext.updateState(conn, ProtocolState.CLOSED); sourceConfiguration.getSourceConnections().shutDownConnection(conn); } }