/** * 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); }
/** * Finish a response. * This includes post-processing of the response object. * It does <i>not</i> read the response entity, if any. * It does <i>not</i> allow for immediate re-use of the * connection over which the response is coming in. * * @param response the response object to finish * @param processor the processor to use * @param context the context for post-processing the response * * @throws HttpException in case of a protocol or processing problem * @throws IOException in case of an I/O problem */ public void postProcess( final HttpResponse response, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP response 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(response, context); }
@Override public HttpRequest generateRequest() throws IOException, HttpException { Asserts.check(this.requestProducerRef.get() == null, "Inconsistent state: request producer is not null"); final HttpAsyncRequestProducer requestProducer = this.requestProducerQueue.poll(); if (requestProducer == null) { return null; } this.requestProducerRef.set(requestProducer); final HttpRequest request = requestProducer.generateRequest(); this.httppocessor.process(request, this.localContext); this.requestQueue.add(request); return request; }
@Override public HttpRequest generateRequest() throws IOException, HttpException { Asserts.check(this.requestProducerRef.get() == null, "Inconsistent state: request producer is not null"); final HttpAsyncRequestProducer requestProducer = this.requestProducerQueue.poll(); if (requestProducer == null) { return null; } this.requestProducerRef.set(requestProducer); final HttpRequest request = requestProducer.generateRequest(); this.httppocessor.process(request, this.localContext); this.requestQueue.add(request); return request; }
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 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); }
@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)); }
@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)); }
@Override public void responseReceived(final HttpResponse response) throws IOException, HttpException { Asserts.check(this.responseConsumerRef.get() == null, "Inconsistent state: response consumer is not null"); final HttpAsyncResponseConsumer<T> responseConsumer = this.responseConsumerQueue.poll(); Asserts.check(responseConsumer != null, "Inconsistent state: response consumer queue is empty"); this.responseConsumerRef.set(responseConsumer); final HttpRequest request = this.requestQueue.poll(); Asserts.check(request != null, "Inconsistent state: request queue is empty"); this.localContext.setAttribute(HttpCoreContext.HTTP_REQUEST, request); this.localContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); this.httppocessor.process(response, this.localContext); responseConsumer.responseReceived(response); this.keepAlive.set(this.connReuseStrategy.keepAlive(response, this.localContext)); }
@Override public void responseReceived(final HttpResponse response) throws IOException, HttpException { Asserts.check(this.responseConsumerRef.get() == null, "Inconsistent state: response consumer is not null"); final HttpAsyncResponseConsumer<T> responseConsumer = this.responseConsumerQueue.poll(); Asserts.check(responseConsumer != null, "Inconsistent state: response consumer queue is empty"); this.responseConsumerRef.set(responseConsumer); final HttpRequest request = this.requestQueue.poll(); Asserts.check(request != null, "Inconsistent state: request queue is empty"); this.localContext.setAttribute(HttpCoreContext.HTTP_REQUEST, request); this.localContext.setAttribute(HttpCoreContext.HTTP_RESPONSE, response); this.httppocessor.process(response, this.localContext); responseConsumer.responseReceived(response); this.keepAlive.set(this.connReuseStrategy.keepAlive(response, this.localContext)); }
@Override public HttpRequest generateRequest() throws IOException, HttpException { if (isDone()) { return null; } final HttpRequest request = this.requestProducer.generateRequest(); this.localContext.setAttribute(HttpCoreContext.HTTP_REQUEST, request); this.localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, this.conn); this.httppocessor.process(request, this.localContext); return request; }
@Override public HttpRequest generateRequest() throws IOException, HttpException { if (isDone()) { return null; } final HttpRequest request = this.requestProducer.generateRequest(); this.localContext.setAttribute(HttpCoreContext.HTTP_REQUEST, request); this.localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, this.conn); this.httppocessor.process(request, this.localContext); return request; }
/** * 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); }
/** * Commit the response to the connection. Processes the response through the configured * HttpProcessor and submits it to be sent out. This method hides any exceptions and is targetted * for non critical (i.e. browser requests etc) requests, which are not core messages * @param conn the connection being processed * @param response the response to commit over the connection */ public void commitResponseHideExceptions( final NHttpServerConnection conn, final HttpResponse response) { try { conn.suspendInput(); httpProcessor.process(response, conn.getContext()); conn.submitResponse(response); } catch (HttpException e) { handleException("Unexpected HTTP protocol error : " + e.getMessage(), e, conn); } catch (IOException e) { handleException("IO error submiting response : " + e.getMessage(), e, conn); } }
/** * Commit the response to the connection. Processes the response through the configured * HttpProcessor and submits it to be sent out. This method hides any exceptions and is targetted * for non critical (i.e. browser requests etc) requests, which are not core messages * @param conn the connection being processed * @param response the response to commit over the connection */ public void commitResponseHideExceptions( final NHttpServerConnection conn, final HttpResponse response) { try { conn.suspendInput(); sourceConfiguration.getHttpProcessor().process(response, conn.getContext()); conn.submitResponse(response); } catch (HttpException e) { handleException("Unexpected HTTP protocol error : " + e.getMessage(), e, conn); } catch (IOException e) { handleException("IO error submiting response : " + e.getMessage(), e, conn); } } /**
public HttpRequest generateRequest(final HttpContext context) throws IOException, HttpException { HttpHost target = this.route.getTargetHost(); HttpRequest connect = new BasicHttpRequest("CONNECT", target.toHostString(), HttpVersion.HTTP_1_1); connect.setHeader(HttpHeaders.HOST, target.toHostString()); this.httpProcessor.process(connect, context); context.setAttribute(SynapseHTTPRequestFactory.ENDPOINT_URL, target.toString()); return connect; }
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); }
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); }
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); } }