List of usage examples for org.apache.http.conn.routing HttpRoute equals
@Override public final boolean equals(final Object obj)
From source file:org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.java
@Override public synchronized void responseCompleted(final HttpContext context) { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + this.id + "] Response fully read"); }//from ww w.j a va 2 s . c o m try { if (this.resultCallback.isDone()) { return; } if (this.managedConn.isOpen()) { final long duration = this.keepaliveStrategy.getKeepAliveDuration(this.currentResponse, this.localContext); if (this.log.isDebugEnabled()) { final String s; if (duration > 0) { s = "for " + duration + " " + TimeUnit.MILLISECONDS; } else { s = "indefinitely"; } this.log.debug("[exchange: " + this.id + "] Connection can be kept alive " + s); } this.managedConn.setIdleDuration(duration, TimeUnit.MILLISECONDS); } else { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + this.id + "] Connection cannot be kept alive"); } this.managedConn.unmarkReusable(); if (this.proxyAuthState.getState() == AuthProtocolState.SUCCESS && this.proxyAuthState.getAuthScheme() != null && this.proxyAuthState.getAuthScheme().isConnectionBased()) { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + this.id + "] Resetting proxy auth state"); } this.proxyAuthState.reset(); } if (this.targetAuthState.getState() == AuthProtocolState.SUCCESS && this.targetAuthState.getAuthScheme() != null && this.targetAuthState.getAuthScheme().isConnectionBased()) { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + this.id + "] Resetting target auth state"); } this.targetAuthState.reset(); } } if (this.finalResponse != null) { this.responseConsumer.responseCompleted(this.localContext); if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + this.id + "] Response processed"); } releaseConnection(); final T result = this.responseConsumer.getResult(); final Exception ex = this.responseConsumer.getException(); if (ex == null) { this.resultCallback.completed(result, this); } else { this.resultCallback.failed(ex, this); } } else { if (this.followup != null) { final HttpRoute actualRoute = this.mainRequest.getRoute(); final HttpRoute newRoute = this.followup.getRoute(); if (!actualRoute.equals(newRoute)) { releaseConnection(); } this.mainRequest = this.followup; } if (this.managedConn != null && !this.managedConn.isOpen()) { releaseConnection(); } if (this.managedConn != null) { this.managedConn.requestOutput(); } else { requestConnection(); } } this.followup = null; this.currentRequest = null; this.currentResponse = null; } catch (final RuntimeException runex) { failed(runex); throw runex; } }
From source file:org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.java
private synchronized void connectionRequestCompleted(final ManagedClientAsyncConnection conn) { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + this.id + "] Connection allocated: " + conn); }/*from w w w . ja v a 2 s . c o m*/ this.connRequestCallback = null; try { this.managedConn = conn; if (this.closed) { conn.releaseConnection(); return; } final HttpRoute route = this.mainRequest.getRoute(); if (!conn.isOpen()) { conn.open(route, this.localContext, this.params); } conn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this); conn.requestOutput(); this.routeEstablished = route.equals(conn.getRoute()); if (!conn.isOpen()) { throw new ConnectionClosedException("Connection closed"); } } catch (final IOException ex) { failed(ex); } catch (final RuntimeException runex) { failed(runex); throw runex; } }
From source file:org.apache.http.impl.nio.client.MainClientExec.java
@Override public void responseCompleted(final InternalState state, final AbstractClientExchangeHandler<?> handler) throws IOException, HttpException { final HttpClientContext localContext = state.getLocalContext(); final HttpResponse currentResponse = handler.getCurrentResponse(); if (!handler.isRouteEstablished()) { final int status = currentResponse.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_OK) { handler.setCurrentResponse(null); return; }//from w w w. j a v a2 s.co m } final boolean keepAlive = handler.manageConnectionPersistence(); if (!keepAlive) { handler.releaseConnection(); final AuthState proxyAuthState = localContext.getProxyAuthState(); if (proxyAuthState.getState() == AuthProtocolState.SUCCESS && proxyAuthState.getAuthScheme() != null && proxyAuthState.getAuthScheme().isConnectionBased()) { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + state.getId() + "] Resetting proxy auth state"); } proxyAuthState.reset(); } final AuthState targetAuthState = localContext.getTargetAuthState(); if (targetAuthState.getState() == AuthProtocolState.SUCCESS && targetAuthState.getAuthScheme() != null && targetAuthState.getAuthScheme().isConnectionBased()) { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + state.getId() + "] Resetting target auth state"); } targetAuthState.reset(); } } Object userToken = localContext.getUserToken(); if (userToken == null) { userToken = this.userTokenHandler.getUserToken(localContext); localContext.setAttribute(HttpClientContext.USER_TOKEN, userToken); } if (state.getFinalResponse() != null) { final HttpAsyncResponseConsumer<?> responseConsumer = state.getResponseConsumer(); responseConsumer.responseCompleted(localContext); if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + state.getId() + "] Response processed"); } handler.releaseConnection(); } else { if (state.getRedirect() != null) { final HttpUriRequest redirect = state.getRedirect(); final URI uri = redirect.getURI(); if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + state.getId() + "] Redirecting to '" + uri + "'"); } state.setRedirect(null); final HttpHost newTarget = URIUtils.extractHost(uri); if (newTarget == null) { throw new ProtocolException("Redirect URI does not specify a valid host name: " + uri); } // Reset auth states if redirecting to another host final HttpRoute route = handler.getRoute(); if (!route.getTargetHost().equals(newTarget)) { final AuthState targetAuthState = localContext.getTargetAuthState(); if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + state.getId() + "] Resetting target auth state"); } targetAuthState.reset(); final AuthState proxyAuthState = localContext.getProxyAuthState(); final AuthScheme authScheme = proxyAuthState.getAuthScheme(); if (authScheme != null && authScheme.isConnectionBased()) { if (this.log.isDebugEnabled()) { this.log.debug("[exchange: " + state.getId() + "] Resetting proxy auth state"); } proxyAuthState.reset(); } } if (!redirect.headerIterator().hasNext()) { final HttpRequest original = state.getMainRequest().getOriginal(); redirect.setHeaders(original.getAllHeaders()); } final HttpRequestWrapper newRequest = HttpRequestWrapper.wrap(redirect); final HttpRoute newRoute = this.routePlanner.determineRoute(newTarget, newRequest, localContext); if (!route.equals(newRoute)) { handler.releaseConnection(); } handler.setRoute(newRoute); handler.setCurrentRequest(newRequest); state.setMainRequest(newRequest); prepareRequest(state, handler); } } handler.setCurrentResponse(null); }