Refine search
final HttpContext context) throws IOException, HttpException { context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_CONTINUE, context); response.setParams( new DefaultedHttpParams(response.getParams(), this.params)); new DefaultedHttpParams(response.getParams(), this.params)); context.setAttribute(ExecutionContext.HTTP_REQUEST, request); context.setAttribute(ExecutionContext.HTTP_RESPONSE, response); this.processor.process(request, context); doService(request, response, context); this.processor.process(response, context); conn.sendResponseHeader(response); conn.sendResponseEntity(response); conn.flush(); if (!this.connStrategy.keepAlive(response, context)) { conn.close();
final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException { Args.notNull(route, "HTTP route"); Args.notNull(request, "HTTP request"); Args.notNull(context, "HTTP context"); context.setAttribute(HttpClientContext.HTTP_ROUTE, route); httpProcessor.process(request, context); final HttpResponse response = requestExecutor.execute(request, managedConn, context); httpProcessor.process(response, context); if (reuseStrategy.keepAlive(response, context)) { final HttpEntity entity = response.getEntity(); if (entity == null || !entity.isStreaming()) {
final HttpContext context) throws IOException, HttpException { context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn); if (response.getStatusLine().getStatusCode() < 200) { context.setAttribute(HttpCoreContext.HTTP_REQUEST, request); this.processor.process(request, context); doService(request, response, context); context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); this.processor.process(response, context); conn.sendResponseHeader(response); conn.sendResponseEntity(response); conn.flush(); if (!this.connStrategy.keepAlive(response, context)) { conn.close();
final HttpResponse response) throws IOException, HttpException { try { BasicHttpEntity entity = (BasicHttpEntity) response.getEntity(); Header[] headers = response.getAllHeaders(); int contentLength = -1; if (canResponseHaveBody(response, conn)) { if (header.getName().equals(HTTP.CONTENT_LEN) && Integer.parseInt(header.getValue()) > 0) { contentLength = Integer.parseInt(header.getValue()); response.removeHeader(header); conn.suspendInput(); HttpContext context = conn.getContext(); httpProcessor.process(response, context); conn.getContext().setAttribute(NhttpConstants.RES_TO_CLIENT_WRITE_START_TIME, System.currentTimeMillis()); conn.submitResponse(response);
private void commitFinalResponse( final NHttpServerConnection conn, final State state) throws IOException, HttpException { final Outgoing outgoing = state.getOutgoing(); Asserts.notNull(outgoing, "Outgoing response"); final HttpRequest request = outgoing.getRequest(); final HttpResponse response = outgoing.getResponse(); final HttpContext context = outgoing.getContext(); context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); this.httpProcessor.process(response, context); HttpEntity entity = response.getEntity(); if (entity != null && !canResponseHaveBody(request, response)) { response.setEntity(null); entity = null; } conn.submitResponse(response); if (entity == null) { completeResponse(outgoing, conn, state); } else { state.setResponseState(MessageState.BODY_STREAM); } }
protected void sendResponse( final NHttpServerConnection conn, final HttpResponse response) throws IOException, HttpException { HttpContext context = conn.getContext(); ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE); ContentOutputBuffer buffer = connState.getOutbuffer(); this.httpProcessor.process(response, context); if (!canResponseHaveBody(connState.getRequest(), response)) { response.setEntity(null); } conn.submitResponse(response); // Update connection state connState.setOutputState(ServerConnState.RESPONSE_SENT); HttpEntity entity = response.getEntity(); if (entity != null) { OutputStream outstream = new ContentOutputStream(buffer); entity.writeTo(outstream); outstream.flush(); outstream.close(); } else { connState.resetOutput(); if (!this.connStrategy.keepAlive(response, context)) { conn.close(); } else { conn.requestInput(); } } }
response.setStatusLine(version, status, statusLine); } else { response.setStatusLine(request.getVersion(), status, statusLine); response.setStatusLine(version, status); } else { response.setStatusCode(status); conn.getContext().setAttribute(ExecutionContext.HTTP_CONNECTION, conn); conn.getContext().setAttribute(ExecutionContext.HTTP_RESPONSE, response); conn.getContext().setAttribute(ExecutionContext.HTTP_REQUEST, SourceContext.getRequest(conn).getRequest()); sourceConfiguration.getHttpProcessor().process(response, conn.getContext());
/** * Pre-process the given request using the given protocol processor and * initiates the process of request execution. * * @param request the request to prepare * @param processor the processor to use * @param context the context for sending the request * * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ public void preProcess( final HttpRequest request, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException { Args.notNull(request, "HTTP request"); Args.notNull(processor, "HTTP processor"); Args.notNull(context, "HTTP context"); context.setAttribute(HttpCoreContext.HTTP_REQUEST, request); processor.process(request, context); }
ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); response.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE); httpContext.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); httpContext.setAttribute(ExecutionContext.HTTP_REQUEST, null); httpContext.setAttribute(ExecutionContext.HTTP_RESPONSE, response); httpProcessor.process(response, httpContext);
public void prepare() throws IOException, HttpException { this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, this.conn); this.context.setAttribute(ExecutionContext.HTTP_REQUEST, this.request); this.httpproc.process(this.request, this.context); }
public void commit() throws IOException, HttpException { if (this.commited) { return; } this.commited = true; this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, this.conn); this.context.setAttribute(ExecutionContext.HTTP_RESPONSE, this.response); BasicHttpEntity entity = new BasicHttpEntity(); entity.setChunked(true); entity.setContentType(this.contentType); this.response.setEntity(entity); this.httpproc.process(this.response, this.context); this.conn.sendResponse(this.response); }
/** * Closes the source side HTTP connection. * * @param conn HTTP server connection reference */ private void dropSourceConnection(NHttpServerConnection conn) { try { HttpContext httpContext = conn.getContext(); HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_REQUEST_TOO_LONG, "Payload Too Large"); response.setParams(new DefaultedHttpParams(sourceConfiguration.getHttpParams(), response.getParams())); response.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE); httpContext.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); httpContext.setAttribute(ExecutionContext.HTTP_REQUEST, null); httpContext.setAttribute(ExecutionContext.HTTP_RESPONSE, response); sourceConfiguration.getHttpProcessor().process(response, httpContext); conn.submitResponse(response); SourceContext.updateState(conn, ProtocolState.CLOSED); conn.close(); } catch (Exception ex) { log.error(ex.getMessage(), ex); SourceContext.updateState(conn, ProtocolState.CLOSED); sourceConfiguration.getSourceConnections().shutDownConnection(conn, true); } }
@Override public void responseReceived(final HttpResponse response) throws IOException, HttpException { this.localContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); this.httppocessor.process(response, this.localContext); this.responseConsumer.responseReceived(response); this.keepAlive.set(this.connReuseStrategy.keepAlive(response, this.localContext)); }
context.setAttribute(ExecutionContext.HTTP_REQUEST, request); context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); this.httpProcessor.process(request, context); HttpResponse response = this.responseFactory.newHttpResponse( ver, HttpStatus.SC_OK, conn.getContext()); response.setParams(this.params); context.setAttribute(ExecutionContext.HTTP_RESPONSE, response); handler.handle(request, response, context); sendResponse(conn, response); response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); response.setParams(this.params); handleException(ex, response); sendResponse(conn, response);
request.setParams(this.params); context.setAttribute(ExecutionContext.HTTP_REQUEST, request); context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); context.setAttribute(ExecutionContext.HTTP_RESPONSE, response); this.httpProcessor.process(request, context); handler.handle(request, response, context); } else { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
final HttpExecutionAware execAware) throws IOException, HttpException { Args.notNull(route, "HTTP route"); Args.notNull(request, "HTTP request"); Args.notNull(context, "HTTP context"); context.setAttribute(HttpCoreContext.HTTP_REQUEST, request); this.httpProcessor.process(request, context); this.httpProcessor.process(response, context); return response; } catch (final RuntimeException ex) {
response.setParams( new DefaultedHttpParams(response.getParams(), this.params)); HttpResponse ack = this.responseFactory.newHttpResponse (ver, HttpStatus.SC_CONTINUE, context); ack.setParams( new DefaultedHttpParams(ack.getParams(), this.params)); conn.sendResponse(ack); new DefaultedHttpParams(response.getParams(), this.params)); handleException(ex, response); this.httpProcessor.process(response, context); conn.sendResponse(response); if (!this.connStrategy.keepAlive(response, context)) { conn.close(); } else {
/** * Prepare a request for sending. * * @param request the request to prepare * @param processor the processor to use * @param context the context for sending the request * * @throws HttpException in case of a protocol or processing problem * @throws IOException in case of an I/O problem */ public void preProcess( final HttpRequest request, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (processor == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } processor.process(request, context); }
final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException { Args.notNull(route, "HTTP route"); Args.notNull(request, "HTTP request"); Args.notNull(context, "HTTP context"); context.setAttribute(HttpClientContext.HTTP_ROUTE, route); httpProcessor.process(request, context); final HttpResponse response = requestExecutor.execute(request, managedConn, context); httpProcessor.process(response, context); if (reuseStrategy.keepAlive(response, context)) { final HttpEntity entity = response.getEntity(); if (entity == null || !entity.isStreaming()) {
final HttpContext context) throws IOException, HttpException { context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn); if (response.getStatusLine().getStatusCode() < 200) { context.setAttribute(HttpCoreContext.HTTP_REQUEST, request); this.processor.process(request, context); doService(request, response, context); context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); this.processor.process(response, context); conn.sendResponseHeader(response); if (canResponseHaveBody(request, response)) { if (!this.connStrategy.keepAlive(response, context)) { conn.close();