if (this.reuseStrategy.keepAlive(response, context)) { this.log.debug("Connection kept alive");
if (this.reuseStrategy.keepAlive(response, context)) { this.log.debug("Connection kept alive");
reuse = reuseStrategy.keepAlive(response, context); if (reuse) {
reuse = reuseStrategy.keepAlive(response, context); if(reuse) {
conn.flush(); if (!this.connStrategy.keepAlive(response, context)) { conn.close();
@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)); }
private void get(final HttpResponseHandler responseHandler, final String... paths) throws IOException, HttpException { ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); try (DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024)) { for (String path : paths) { if (!conn.isOpen()) { Socket socket = new Socket(httpHost.getHostName(), httpHost.getPort()); conn.bind(socket); } BasicHttpRequest request = new BasicHttpRequest("GET", path); System.out.println(">> Request IRI: " + request.getRequestLine().getUri()); httpExecutor.preProcess(request, httpProcessor, httpContext); HttpResponse response = httpExecutor.execute(request, conn, httpContext); httpExecutor.postProcess(response, httpProcessor, httpContext); responseHandler.handle(response); if (!connStrategy.keepAlive(response, httpContext)) { conn.close(); } else { System.out.println("Connection kept alive..."); } } } }
private void post(final String path, final HttpResponseHandler responseHandler, final HttpEntity... requests) throws IOException, HttpException { ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy(); try (DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024)) { for (HttpEntity requestBody : requests) { if (!conn.isOpen()) { Socket socket = new Socket(httpHost.getHostName(), httpHost.getPort()); conn.bind(socket); } BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", path); request.setEntity(requestBody); System.out.println(">> Request IRI: " + request.getRequestLine().getUri()); httpExecutor.preProcess(request, httpProcessor, httpContext); HttpResponse response = httpExecutor.execute(request, conn, httpContext); httpExecutor.postProcess(response, httpProcessor, httpContext); responseHandler.handle(response); if (!connStrategy.keepAlive(response, httpContext)) { conn.close(); } else { System.out.println("Connection kept alive..."); } } } }
if (!connStrategy.keepAlive(response, context)) { conn.close(); } else {
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(); } } }
public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) { HttpContext context = conn.getContext(); HttpResponse response = conn.getHttpResponse(); ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE); ContentOutputBuffer buffer = connState.getOutbuffer(); // Update connection state connState.setOutputState(ServerConnState.RESPONSE_BODY_STREAM); try { buffer.produceContent(encoder); if (encoder.isCompleted()) { connState.setOutputState(ServerConnState.RESPONSE_BODY_DONE); connState.resetOutput(); if (!this.connStrategy.keepAlive(response, context)) { conn.close(); } else { conn.requestInput(); } } } catch (IOException ex) { shutdownConnection(conn, ex); if (this.eventListener != null) { this.eventListener.fatalIOException(ex, conn); } } }
private void completeResponse( final Outgoing outgoing, final NHttpServerConnection conn, final State state) throws IOException, HttpException { final HttpContext context = outgoing.getContext(); final HttpResponse response = outgoing.getResponse(); final HttpAsyncResponseProducer responseProducer = outgoing.getProducer(); try { responseProducer.responseCompleted(context); state.setOutgoing(null); state.setCancellable(null); state.setResponseState(MessageState.READY); } finally { responseProducer.close(); } if (!this.connStrategy.keepAlive(response, context)) { conn.close(); } else { conn.requestInput(); } }
conn.getMetrics().getReceivedBytesCount()); if (!this.connStrategy.keepAlive(response, conn.getContext()) || forceShutdownConnectionOnComplete) { TargetContext.updateState(conn, ProtocolState.CLOSED);
private void completeResponse( final Outgoing outgoing, final NHttpServerConnection conn, final State state) throws IOException, HttpException { final HttpContext context = outgoing.getContext(); final HttpResponse response = outgoing.getResponse(); final HttpAsyncResponseProducer responseProducer = outgoing.getProducer(); try { responseProducer.responseCompleted(context); state.setOutgoing(null); state.setCancellable(null); state.setResponseState(MessageState.READY); } finally { responseProducer.close(); } if (!this.connStrategy.keepAlive(response, context)) { conn.close(); } else { conn.requestInput(); } }
if (!connStrategy.keepAlive(response, conn.getContext()) || forceShutdownConnectionOnComplete) { try {
if (!this.connStrategy.keepAlive(response, context)) { conn.close();
notifySentMessageSize(conn.getMetrics().getSentBytesCount()); if (response != null && !this.connStrategy.keepAlive(response, conn.getContext())) { SourceContext.updateState(conn, ProtocolState.CLOSING);