hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1694620 - in /httpcomponents/httpclient/trunk/httpclient/src: examples/org/apache/http/examples/client/ main/java/org/apache/http/client/ main/java/org/apache/http/client/protocol/ main/java/org/apache/http/impl/client/ main/java/org/apach...
Date Fri, 07 Aug 2015 07:34:14 GMT
Author: olegk
Date: Fri Aug  7 07:34:13 2015
New Revision: 1694620

URL: http://svn.apache.org/r1694620
Log:
Support for auth exchanges with multiple hosts

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/UserTokenHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientConfiguration.java Fri Aug  7 07:34:13 2015
@@ -257,10 +257,8 @@ public class ClientConfiguration {
                 context.getRequest();
                 // Execution route
                 context.getHttpRoute();
-                // Target auth state
-                context.getTargetAuthState();
-                // Proxy auth state
-                context.getTargetAuthState();
+                // Auth exchanges
+                context.getAuthExchanges();
                 // Cookie origin
                 context.getCookieOrigin();
                 // Cookie spec used

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/UserTokenHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/UserTokenHandler.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/UserTokenHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/UserTokenHandler.java Fri Aug  7 07:34:13 2015
@@ -27,6 +27,7 @@
 
 package org.apache.http.client;
 
+import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -49,11 +50,12 @@ public interface UserTokenHandler {
      * identify the current user if the context is user specific or to be
      * {@code null} if it is not.
      *
+     * @param route HTTP route
      * @param context the execution context
      *
      * @return user token that uniquely identifies the user or
      * {@code null} if the context is not user specific.
      */
-    Object getUserToken(HttpContext context);
+    Object getUserToken(HttpRoute route, HttpContext context);
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/HttpClientContext.java Fri Aug  7 07:34:13 2015
@@ -28,10 +28,14 @@
 package org.apache.http.client.protocol;
 
 import java.net.URI;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.http.HttpHost;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.auth.AuthExchange;
+import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthSchemeProvider;
 import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.client.AuthCache;
@@ -106,16 +110,10 @@ public class HttpClientContext extends H
     public static final String AUTH_CACHE            = "http.auth.auth-cache";
 
     /**
-     * Attribute name of a {@link org.apache.http.auth.AuthExchange}
-     * object that represents the actual target authentication state.
+     * Attribute name of a map containing actual {@link AuthExchange}s keyed by their respective
+     * {@link org.apache.http.HttpHost}.
      */
-    public static final String TARGET_AUTH_STATE     = "http.auth.target-scope";
-
-    /**
-     * Attribute name of a {@link org.apache.http.auth.AuthExchange}
-     * object that represents the actual proxy authentication state.
-     */
-    public static final String PROXY_AUTH_STATE      = "http.auth.proxy-scope";
+    public static final String AUTH_EXCHANGE_MAP     = "http.auth.exchanges";
 
     /**
      * Attribute name of a {@link java.lang.Object} object that represents
@@ -217,12 +215,48 @@ public class HttpClientContext extends H
         setAttribute(AUTH_CACHE, authCache);
     }
 
-    public AuthExchange getTargetAuthState() {
-        return getAttribute(TARGET_AUTH_STATE, AuthExchange.class);
+    /**
+     * @since 5.0
+     */
+    @SuppressWarnings("unchecked")
+    public Map<HttpHost, AuthExchange> getAuthExchanges() {
+        Map<HttpHost, AuthExchange> map = (Map<HttpHost, AuthExchange>) getAttribute(AUTH_EXCHANGE_MAP);
+        if (map == null) {
+            map = new HashMap<>();
+            setAttribute(AUTH_EXCHANGE_MAP, map);
+        }
+        return map;
+    }
+
+    /**
+     * @since 5.0
+     */
+    public AuthExchange getAuthExchange(final HttpHost host) {
+        final Map<HttpHost, AuthExchange> authExchangeMap = getAuthExchanges();
+        AuthExchange authExchange = authExchangeMap.get(host);
+        if (authExchange == null) {
+            authExchange = new AuthExchange();
+            authExchangeMap.put(host, authExchange);
+        }
+        return authExchange;
     }
 
-    public AuthExchange getProxyAuthState() {
-        return getAttribute(PROXY_AUTH_STATE, AuthExchange.class);
+    /**
+     * @since 5.0
+     */
+    public void setAuthExchange(final HttpHost host, final AuthExchange authExchange) {
+        final Map<HttpHost, AuthExchange> authExchangeMap = getAuthExchanges();
+        authExchangeMap.put(host, authExchange);
+    }
+
+    /**
+     * @since 5.0
+     */
+    public void resetAuthExchange(final HttpHost host, final AuthScheme authScheme) {
+        final AuthExchange authExchange = new AuthExchange();
+        authExchange.select(authScheme);
+        final Map<HttpHost, AuthExchange> authExchangeMap = getAuthExchanges();
+        authExchangeMap.put(host, authExchange);
     }
 
     public <T> T getUserToken(final Class<T> clazz) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/protocol/RequestAuthCache.java Fri Aug  7 07:34:13 2015
@@ -36,8 +36,8 @@ import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.annotation.Immutable;
-import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthExchange;
+import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.client.AuthCache;
 import org.apache.http.conn.routing.RouteInfo;
@@ -99,26 +99,28 @@ public class RequestAuthCache implements
                     target.getSchemeName());
         }
 
-        final AuthExchange targetState = clientContext.getTargetAuthState();
-        if (targetState != null && targetState.getState() == AuthExchange.State.UNCHALLENGED) {
+        final AuthExchange targetAuthExchange = clientContext.getAuthExchange(target);
+        if (targetAuthExchange.getState() == AuthExchange.State.UNCHALLENGED) {
             final AuthScheme authScheme = authCache.get(target);
             if (authScheme != null) {
                 if (this.log.isDebugEnabled()) {
                     this.log.debug("Re-using cached '" + authScheme.getName() + "' auth scheme for " + target);
                 }
-                targetState.select(authScheme);
+                targetAuthExchange.select(authScheme);
             }
         }
 
         final HttpHost proxy = route.getProxyHost();
-        final AuthExchange proxyState = clientContext.getProxyAuthState();
-        if (proxy != null && proxyState != null && proxyState.getState() == AuthExchange.State.UNCHALLENGED) {
-            final AuthScheme authScheme = authCache.get(proxy);
-            if (authScheme != null) {
-                if (this.log.isDebugEnabled()) {
-                    this.log.debug("Re-using cached '" + authScheme.getName() + "' auth scheme for " + proxy);
+        if (proxy != null) {
+            final AuthExchange proxyAuthExchange = clientContext.getAuthExchange(proxy);
+            if (proxyAuthExchange.getState() == AuthExchange.State.UNCHALLENGED) {
+                final AuthScheme authScheme = authCache.get(proxy);
+                if (authScheme != null) {
+                    if (this.log.isDebugEnabled()) {
+                        this.log.debug("Re-using cached '" + authScheme.getName() + "' auth scheme for " + proxy);
+                    }
+                    proxyAuthExchange.select(authScheme);
                 }
-                proxyState.select(authScheme);
             }
         }
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultUserTokenHandler.java Fri Aug  7 07:34:13 2015
@@ -32,11 +32,12 @@ import javax.net.ssl.SSLSession;
 
 import org.apache.http.HttpConnection;
 import org.apache.http.annotation.Immutable;
-import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthExchange;
+import org.apache.http.auth.AuthScheme;
 import org.apache.http.client.UserTokenHandler;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.conn.ManagedHttpClientConnection;
+import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -59,18 +60,18 @@ public class DefaultUserTokenHandler imp
     public static final DefaultUserTokenHandler INSTANCE = new DefaultUserTokenHandler();
 
     @Override
-    public Object getUserToken(final HttpContext context) {
+    public Object getUserToken(final HttpRoute route, final HttpContext context) {
 
         final HttpClientContext clientContext = HttpClientContext.adapt(context);
 
         Principal userPrincipal = null;
 
-        final AuthExchange targetAuthState = clientContext.getTargetAuthState();
-        if (targetAuthState != null) {
-            userPrincipal = getAuthPrincipal(targetAuthState);
-            if (userPrincipal == null) {
-                final AuthExchange proxyAuthState = clientContext.getProxyAuthState();
-                userPrincipal = getAuthPrincipal(proxyAuthState);
+        final AuthExchange targetAuthExchnage = clientContext.getAuthExchange(route.getTargetHost());
+        if (targetAuthExchnage != null) {
+            userPrincipal = getAuthPrincipal(targetAuthExchnage);
+            if (userPrincipal == null && route.getProxyHost() != null) {
+                final AuthExchange proxyAuthExchange = clientContext.getAuthExchange(route.getProxyHost());
+                userPrincipal = getAuthPrincipal(proxyAuthExchange);
             }
         }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/InternalHttpClient.java Fri Aug  7 07:34:13 2015
@@ -38,7 +38,6 @@ import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.auth.AuthSchemeProvider;
-import org.apache.http.auth.AuthExchange;
 import org.apache.http.auth.CredentialsProvider;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.CookieStore;
@@ -111,12 +110,6 @@ class InternalHttpClient extends Closeab
     }
 
     private void setupContext(final HttpClientContext context) {
-        if (context.getAttribute(HttpClientContext.TARGET_AUTH_STATE) == null) {
-            context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, new AuthExchange());
-        }
-        if (context.getAttribute(HttpClientContext.PROXY_AUTH_STATE) == null) {
-            context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, new AuthExchange());
-        }
         if (context.getAttribute(HttpClientContext.AUTHSCHEME_REGISTRY) == null) {
             context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
         }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/NoopUserTokenHandler.java Fri Aug  7 07:34:13 2015
@@ -28,6 +28,7 @@ package org.apache.http.impl.client;
 
 import org.apache.http.annotation.Immutable;
 import org.apache.http.client.UserTokenHandler;
+import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.protocol.HttpContext;
 
 /**
@@ -41,7 +42,7 @@ public class NoopUserTokenHandler implem
     public static final NoopUserTokenHandler INSTANCE = new NoopUserTokenHandler();
 
     @Override
-    public Object getUserToken(final HttpContext context) {
+    public Object getUserToken(final HttpRoute route, final HttpContext context) {
         return null;
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/ProxyClient.java Fri Aug  7 07:34:13 2015
@@ -38,9 +38,9 @@ import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
+import org.apache.http.auth.AuthExchange;
 import org.apache.http.auth.AuthSchemeProvider;
 import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.AuthExchange;
 import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.Credentials;
 import org.apache.http.client.AuthenticationStrategy;
@@ -90,7 +90,7 @@ public class ProxyClient {
     private final HttpRequestExecutor requestExec;
     private final AuthenticationStrategy proxyAuthStrategy;
     private final HttpAuthenticator authenticator;
-    private final AuthExchange proxyAuthState;
+    private final AuthExchange proxyAuthExchange;
     private final Lookup<AuthSchemeProvider> authSchemeRegistry;
     private final ConnectionReuseStrategy reuseStrategy;
 
@@ -110,7 +110,7 @@ public class ProxyClient {
         this.requestExec = new HttpRequestExecutor();
         this.proxyAuthStrategy = new DefaultAuthenticationStrategy();
         this.authenticator = new HttpAuthenticator();
-        this.proxyAuthState = new AuthExchange();
+        this.proxyAuthExchange = new AuthExchange();
         this.authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
                 .register(AuthSchemes.BASIC, new BasicSchemeFactory())
                 .register(AuthSchemes.DIGEST, new DigestSchemeFactory())
@@ -164,7 +164,6 @@ public class ProxyClient {
         context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
         context.setAttribute(HttpCoreContext.HTTP_REQUEST, connect);
         context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
-        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
         context.setAttribute(HttpClientContext.CREDS_PROVIDER, credsProvider);
         context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
         context.setAttribute(HttpClientContext.REQUEST_CONFIG, this.requestConfig);
@@ -177,7 +176,7 @@ public class ProxyClient {
                 conn.bind(socket);
             }
 
-            this.authenticator.addAuthResponse(proxy, ChallengeType.PROXY, connect, this.proxyAuthState, context);
+            this.authenticator.addAuthResponse(proxy, ChallengeType.PROXY, connect, this.proxyAuthExchange, context);
 
             response = this.requestExec.execute(connect, conn, context);
 
@@ -186,9 +185,9 @@ public class ProxyClient {
                 throw new HttpException("Unexpected response to CONNECT request: " +
                         response.getStatusLine());
             }
-            if (this.authenticator.isChallenged(proxy, ChallengeType.PROXY, response, this.proxyAuthState, context)) {
+            if (this.authenticator.isChallenged(proxy, ChallengeType.PROXY, response, this.proxyAuthExchange, context)) {
                 if (this.authenticator.prepareAuthResponse(proxy, ChallengeType.PROXY, response,
-                        this.proxyAuthStrategy, this.proxyAuthState, context)) {
+                        this.proxyAuthStrategy, this.proxyAuthExchange, context)) {
                     // Retry request
                     if (this.reuseStrategy.keepAlive(response, context)) {
                         // Consume response content

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/MainClientExec.java Fri Aug  7 07:34:13 2015
@@ -154,17 +154,6 @@ public class MainClientExec implements C
         Args.notNull(request, "HTTP request");
         Args.notNull(context, "HTTP context");
 
-        AuthExchange targetAuthState = context.getTargetAuthState();
-        if (targetAuthState == null) {
-            targetAuthState = new AuthExchange();
-            context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, targetAuthState);
-        }
-        AuthExchange proxyAuthState = context.getProxyAuthState();
-        if (proxyAuthState == null) {
-            proxyAuthState = new AuthExchange();
-            context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState);
-        }
-
         if (request instanceof HttpEntityEnclosingRequest) {
             RequestEntityProxy.enhance((HttpEntityEnclosingRequest) request);
         }
@@ -206,6 +195,10 @@ public class MainClientExec implements C
                 execAware.setCancellable(connHolder);
             }
 
+            final AuthExchange targetAuthExchange = context.getAuthExchange(route.getTargetHost());
+            final AuthExchange proxyAuthExchange = route.getProxyHost() != null ?
+                    context.getAuthExchange(route.getProxyHost()) : new AuthExchange();
+
             HttpResponse response;
             for (int execCount = 1;; execCount++) {
 
@@ -221,7 +214,7 @@ public class MainClientExec implements C
                 if (!managedConn.isOpen()) {
                     this.log.debug("Opening connection " + route);
                     try {
-                        establishRoute(proxyAuthState, managedConn, route, request, context);
+                        establishRoute(managedConn, route, request, context);
                     } catch (final TunnelRefusedException ex) {
                         if (this.log.isDebugEnabled()) {
                             this.log.debug(ex.getMessage());
@@ -245,17 +238,17 @@ public class MainClientExec implements C
 
                 if (!request.containsHeader(HttpHeaders.AUTHORIZATION)) {
                     if (this.log.isDebugEnabled()) {
-                        this.log.debug("Target auth state: " + targetAuthState.getState());
+                        this.log.debug("Target auth state: " + targetAuthExchange.getState());
                     }
                     this.authenticator.addAuthResponse(
-                            route.getTargetHost(), ChallengeType.TARGET, request, targetAuthState, context);
+                            route.getTargetHost(), ChallengeType.TARGET, request, targetAuthExchange, context);
                 }
                 if (!request.containsHeader(HttpHeaders.PROXY_AUTHORIZATION) && !route.isTunnelled()) {
                     if (this.log.isDebugEnabled()) {
-                        this.log.debug("Proxy auth state: " + proxyAuthState.getState());
+                        this.log.debug("Proxy auth state: " + proxyAuthExchange.getState());
                     }
                     this.authenticator.addAuthResponse(
-                            route.getProxyHost(), ChallengeType.PROXY, request, proxyAuthState, context);
+                            route.getProxyHost(), ChallengeType.PROXY, request, proxyAuthExchange, context);
                 }
 
                 response = requestExecutor.execute(request, managedConn, context);
@@ -285,24 +278,24 @@ public class MainClientExec implements C
                 }
 
                 if (needAuthentication(
-                        targetAuthState, proxyAuthState, route, response, context)) {
+                        targetAuthExchange, proxyAuthExchange, route, response, context)) {
                     // Make sure the response body is fully consumed, if present
                     final HttpEntity entity = response.getEntity();
                     if (connHolder.isReusable()) {
                         EntityUtils.consume(entity);
                     } else {
                         managedConn.close();
-                        if (proxyAuthState.getState() == AuthExchange.State.SUCCESS
-                                && proxyAuthState.getAuthScheme() != null
-                                && proxyAuthState.getAuthScheme().isConnectionBased()) {
+                        if (proxyAuthExchange.getState() == AuthExchange.State.SUCCESS
+                                && proxyAuthExchange.getAuthScheme() != null
+                                && proxyAuthExchange.getAuthScheme().isConnectionBased()) {
                             this.log.debug("Resetting proxy auth state");
-                            proxyAuthState.reset();
+                            proxyAuthExchange.reset();
                         }
-                        if (targetAuthState.getState() == AuthExchange.State.SUCCESS
-                                && targetAuthState.getAuthScheme() != null
-                                && targetAuthState.getAuthScheme().isConnectionBased()) {
+                        if (targetAuthExchange.getState() == AuthExchange.State.SUCCESS
+                                && targetAuthExchange.getAuthScheme() != null
+                                && targetAuthExchange.getAuthScheme().isConnectionBased()) {
                             this.log.debug("Resetting target auth state");
-                            targetAuthState.reset();
+                            targetAuthExchange.reset();
                         }
                     }
                     // discard previous auth headers
@@ -319,7 +312,7 @@ public class MainClientExec implements C
             }
 
             if (userToken == null) {
-                userToken = userTokenHandler.getUserToken(context);
+                userToken = userTokenHandler.getUserToken(route, context);
                 context.setAttribute(HttpClientContext.USER_TOKEN, userToken);
             }
             if (userToken != null) {
@@ -350,7 +343,6 @@ public class MainClientExec implements C
      * Establishes the target route.
      */
     void establishRoute(
-            final AuthExchange proxyAuthState,
             final HttpClientConnection managedConn,
             final HttpRoute route,
             final HttpRequest request,
@@ -383,8 +375,7 @@ public class MainClientExec implements C
                 tracker.connectProxy(proxy, false);
                 break;
             case HttpRouteDirector.TUNNEL_TARGET: {
-                final boolean secure = createTunnelToTarget(
-                        proxyAuthState, managedConn, route, request, context);
+                final boolean secure = createTunnelToTarget(managedConn, route, request, context);
                 this.log.debug("Tunnel to target created.");
                 tracker.tunnelTarget(secure);
             }   break;
@@ -428,7 +419,6 @@ public class MainClientExec implements C
      * information about the tunnel, that is left to the caller.
      */
     private boolean createTunnelToTarget(
-            final AuthExchange proxyAuthState,
             final HttpClientConnection managedConn,
             final HttpRoute route,
             final HttpRequest request,
@@ -439,6 +429,7 @@ public class MainClientExec implements C
 
         final HttpHost target = route.getTargetHost();
         final HttpHost proxy = route.getProxyHost();
+        final AuthExchange proxyAuthExchange = context.getAuthExchange(proxy);
         HttpResponse response = null;
 
         final String authority = target.toHostString();
@@ -456,7 +447,7 @@ public class MainClientExec implements C
             }
 
             connect.removeHeaders(HttpHeaders.PROXY_AUTHORIZATION);
-            this.authenticator.addAuthResponse(proxy, ChallengeType.PROXY, connect, proxyAuthState, context);
+            this.authenticator.addAuthResponse(proxy, ChallengeType.PROXY, connect, proxyAuthExchange, context);
 
             response = this.requestExecutor.execute(connect, managedConn, context);
 
@@ -468,9 +459,9 @@ public class MainClientExec implements C
 
             if (config.isAuthenticationEnabled()) {
                 if (this.authenticator.isChallenged(proxy, ChallengeType.PROXY, response,
-                        proxyAuthState, context)) {
+                        proxyAuthExchange, context)) {
                     if (this.authenticator.prepareAuthResponse(proxy, ChallengeType.PROXY, response,
-                            this.proxyAuthStrategy, proxyAuthState, context)) {
+                            this.proxyAuthStrategy, proxyAuthExchange, context)) {
                         // Retry request
                         if (this.reuseStrategy.keepAlive(response, context)) {
                             this.log.debug("Connection kept alive");
@@ -531,8 +522,8 @@ public class MainClientExec implements C
     }
 
     private boolean needAuthentication(
-            final AuthExchange targetAuthState,
-            final AuthExchange proxyAuthState,
+            final AuthExchange targetAuthExchange,
+            final AuthExchange proxyAuthExchange,
             final HttpRoute route,
             final HttpResponse response,
             final HttpClientContext context) {
@@ -549,7 +540,7 @@ public class MainClientExec implements C
                         target.getSchemeName());
             }
             final boolean targetAuthRequested = this.authenticator.isChallenged(
-                    target, ChallengeType.TARGET, response, targetAuthState, context);
+                    target, ChallengeType.TARGET, response, targetAuthExchange, context);
 
             HttpHost proxy = route.getProxyHost();
             // if proxy is not set use target host instead
@@ -557,15 +548,15 @@ public class MainClientExec implements C
                 proxy = route.getTargetHost();
             }
             final boolean proxyAuthRequested = this.authenticator.isChallenged(
-                    proxy, ChallengeType.PROXY, response, proxyAuthState, context);
+                    proxy, ChallengeType.PROXY, response, proxyAuthExchange, context);
 
             if (targetAuthRequested) {
                 return this.authenticator.prepareAuthResponse(target, ChallengeType.TARGET, response,
-                        this.targetAuthStrategy, targetAuthState, context);
+                        this.targetAuthStrategy, targetAuthExchange, context);
             }
             if (proxyAuthRequested) {
                 return this.authenticator.prepareAuthResponse(proxy, ChallengeType.PROXY, response,
-                        this.proxyAuthStrategy, proxyAuthState, context);
+                        this.proxyAuthStrategy, proxyAuthExchange, context);
             }
         }
         return false;

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/execchain/RedirectExec.java Fri Aug  7 07:34:13 2015
@@ -139,17 +139,15 @@ public class RedirectExec implements Cli
 
                     // Reset virtual host and auth states if redirecting to another host
                     if (!currentRoute.getTargetHost().equals(newTarget)) {
-                        final AuthExchange targetAuthState = context.getTargetAuthState();
-                        if (targetAuthState != null) {
-                            this.log.debug("Resetting target auth state");
-                            targetAuthState.reset();
-                        }
-                        final AuthExchange proxyAuthState = context.getProxyAuthState();
-                        if (proxyAuthState != null) {
-                            final AuthScheme authScheme = proxyAuthState.getAuthScheme();
+                        final AuthExchange targetAuthExchange = context.getAuthExchange(currentRoute.getTargetHost());
+                        this.log.debug("Resetting target auth state");
+                        targetAuthExchange.reset();
+                        if (currentRoute.getProxyHost() != null) {
+                            final AuthExchange proxyAuthExchange = context.getAuthExchange(currentRoute.getProxyHost());
+                            final AuthScheme authScheme = proxyAuthExchange.getAuthScheme();
                             if (authScheme != null && authScheme.isConnectionBased()) {
                                 this.log.debug("Resetting proxy auth state");
-                                proxyAuthState.reset();
+                                proxyAuthExchange.reset();
                             }
                         }
                     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/protocol/TestRequestAuthCache.java Fri Aug  7 07:34:13 2015
@@ -29,8 +29,8 @@ package org.apache.http.client.protocol;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.AuthExchange;
+import org.apache.http.auth.AuthScope;
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthCache;
@@ -55,8 +55,6 @@ public class TestRequestAuthCache {
     private BasicScheme authscheme1;
     private BasicScheme authscheme2;
     private BasicCredentialsProvider credProvider;
-    private AuthExchange targetState;
-    private AuthExchange proxyState;
 
     @Before
     public void setUp() {
@@ -73,9 +71,6 @@ public class TestRequestAuthCache {
 
         this.credProvider.setCredentials(this.authscope1, this.creds1);
         this.credProvider.setCredentials(this.authscope2, this.creds2);
-
-        this.targetState = new AuthExchange();
-        this.proxyState = new AuthExchange();
     }
 
     @Test(expected=IllegalArgumentException.class)
@@ -100,8 +95,6 @@ public class TestRequestAuthCache {
         context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
         context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
         context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
-        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
-        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);
 
         final AuthCache authCache = new BasicAuthCache();
         authCache.put(this.target, this.authscheme1);
@@ -111,8 +104,14 @@ public class TestRequestAuthCache {
 
         final HttpRequestInterceptor interceptor = new RequestAuthCache();
         interceptor.process(request, context);
-        Assert.assertNotNull(this.targetState.getAuthScheme());
-        Assert.assertNotNull(this.proxyState.getAuthScheme());
+
+        final AuthExchange targetAuthExchange = context.getAuthExchange(this.target);
+        final AuthExchange proxyAuthExchange = context.getAuthExchange(this.proxy);
+
+        Assert.assertNotNull(targetAuthExchange);
+        Assert.assertNotNull(targetAuthExchange.getAuthScheme());
+        Assert.assertNotNull(proxyAuthExchange);
+        Assert.assertNotNull(proxyAuthExchange.getAuthScheme());
     }
 
     @Test
@@ -123,8 +122,6 @@ public class TestRequestAuthCache {
         context.setAttribute(HttpClientContext.CREDS_PROVIDER, null);
         context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
         context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
-        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
-        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);
 
         final AuthCache authCache = new BasicAuthCache();
         authCache.put(this.target, this.authscheme1);
@@ -134,8 +131,14 @@ public class TestRequestAuthCache {
 
         final HttpRequestInterceptor interceptor = new RequestAuthCache();
         interceptor.process(request, context);
-        Assert.assertNull(this.targetState.getAuthScheme());
-        Assert.assertNull(this.proxyState.getAuthScheme());
+
+        final AuthExchange targetAuthExchange = context.getAuthExchange(this.target);
+        final AuthExchange proxyAuthExchange = context.getAuthExchange(this.proxy);
+
+        Assert.assertNotNull(targetAuthExchange);
+        Assert.assertNull(targetAuthExchange.getAuthScheme());
+        Assert.assertNotNull(proxyAuthExchange);
+        Assert.assertNull(proxyAuthExchange.getAuthScheme());
     }
 
     @Test
@@ -146,14 +149,18 @@ public class TestRequestAuthCache {
         context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
         context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
         context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
-        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
-        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);
         context.setAttribute(HttpClientContext.AUTH_CACHE, null);
 
         final HttpRequestInterceptor interceptor = new RequestAuthCache();
         interceptor.process(request, context);
-        Assert.assertNull(this.targetState.getAuthScheme());
-        Assert.assertNull(this.proxyState.getAuthScheme());
+
+        final AuthExchange targetAuthExchange = context.getAuthExchange(this.target);
+        final AuthExchange proxyAuthExchange = context.getAuthExchange(this.proxy);
+
+        Assert.assertNotNull(targetAuthExchange);
+        Assert.assertNull(targetAuthExchange.getAuthScheme());
+        Assert.assertNotNull(proxyAuthExchange);
+        Assert.assertNull(proxyAuthExchange.getAuthScheme());
     }
 
     @Test
@@ -164,44 +171,20 @@ public class TestRequestAuthCache {
         context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
         context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
         context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
-        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
-        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);
 
         final AuthCache authCache = new BasicAuthCache();
         context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
 
         final HttpRequestInterceptor interceptor = new RequestAuthCache();
         interceptor.process(request, context);
-        Assert.assertNull(this.targetState.getAuthScheme());
-        Assert.assertNull(this.proxyState.getAuthScheme());
-    }
-
-    @Test
-    public void testAuthSchemeAlreadySet() throws Exception {
-        final HttpRequest request = new BasicHttpRequest("GET", "/");
 
-        final HttpClientContext context = HttpClientContext.create();
-        context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credProvider);
-        context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
-        context.setAttribute(HttpClientContext.HTTP_ROUTE, new HttpRoute(this.target, null, this.proxy, false));
-        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, this.targetState);
-        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, this.proxyState);
+        final AuthExchange targetAuthExchange = context.getAuthExchange(this.target);
+        final AuthExchange proxyAuthExchange = context.getAuthExchange(this.proxy);
 
-        final AuthCache authCache = new BasicAuthCache();
-        authCache.put(this.target, this.authscheme1);
-        authCache.put(this.proxy, this.authscheme2);
-
-        context.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
-
-        this.targetState.setState(AuthExchange.State.CHALLENGED);
-        this.targetState.select(new BasicScheme());
-        this.proxyState.setState(AuthExchange.State.CHALLENGED);
-        this.proxyState.select(new BasicScheme());
-
-        final HttpRequestInterceptor interceptor = new RequestAuthCache();
-        interceptor.process(request, context);
-        Assert.assertNotSame(this.authscheme1, this.targetState.getAuthScheme());
-        Assert.assertNotSame(this.authscheme2, this.proxyState.getAuthScheme());
+        Assert.assertNotNull(targetAuthExchange);
+        Assert.assertNull(targetAuthExchange.getAuthScheme());
+        Assert.assertNotNull(proxyAuthExchange);
+        Assert.assertNull(proxyAuthExchange.getAuthScheme());
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestStatefulConnManagement.java Fri Aug  7 07:34:13 2015
@@ -38,6 +38,7 @@ import org.apache.http.client.HttpClient
 import org.apache.http.client.UserTokenHandler;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.conn.routing.HttpRoute;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.localserver.LocalServerTestBase;
 import org.apache.http.protocol.BasicHttpContext;
@@ -83,7 +84,7 @@ public class TestStatefulConnManagement
         final UserTokenHandler userTokenHandler = new UserTokenHandler() {
 
             @Override
-            public Object getUserToken(final HttpContext context) {
+            public Object getUserToken(final HttpRoute route, final HttpContext context) {
                 final String id = (String) context.getAttribute("user");
                 return id;
             }
@@ -209,7 +210,7 @@ public class TestStatefulConnManagement
         final UserTokenHandler userTokenHandler = new UserTokenHandler() {
 
             @Override
-            public Object getUserToken(final HttpContext context) {
+            public Object getUserToken(final HttpRoute route, final HttpContext context) {
                 return context.getAttribute("user");
             }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestMainClientExec.java Fri Aug  7 07:34:13 2015
@@ -46,9 +46,9 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.auth.AuthChallenge;
+import org.apache.http.auth.AuthExchange;
 import org.apache.http.auth.AuthScheme;
 import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.AuthExchange;
 import org.apache.http.auth.ChallengeType;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.AuthenticationStrategy;
@@ -162,8 +162,6 @@ public class TestMainClientExec {
         Mockito.verify(managedConn, Mockito.times(1)).close();
         Mockito.verify(connManager).releaseConnection(managedConn, null, 0, TimeUnit.MILLISECONDS);
 
-        Assert.assertNotNull(context.getTargetAuthState());
-        Assert.assertNotNull(context.getProxyAuthState());
         Assert.assertSame(managedConn, context.getConnection());
         Assert.assertNull(context.getUserToken());
         Assert.assertNotNull(finalResponse);
@@ -219,6 +217,7 @@ public class TestMainClientExec {
                 Mockito.same(response),
                 Mockito.<HttpClientContext>any())).thenReturn(Boolean.TRUE);
         Mockito.when(userTokenHandler.getUserToken(
+                Mockito.same(route),
                 Mockito.<HttpClientContext>any())).thenReturn("this and that");
 
         mainClientExec.execute(route, request, context, execAware);
@@ -424,7 +423,7 @@ public class TestMainClientExec {
 
     @Test
     public void testExecEntityEnclosingRequestRetryOnAuthChallenge() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
+        final HttpRoute route = new HttpRoute(target, proxy);
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
         final HttpResponse response1 = new BasicHttpResponse(HttpVersion.HTTP_1_1, 401, "Huh?");
         response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
@@ -438,12 +437,12 @@ public class TestMainClientExec {
                 .setStream(instream2)
                 .build());
 
-        final AuthExchange proxyAuthState = new AuthExchange();
-        proxyAuthState.setState(AuthExchange.State.SUCCESS);
-        proxyAuthState.select(new NTLMScheme());
-
         final HttpClientContext context = new HttpClientContext();
-        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState);
+
+        final AuthExchange proxyAuthExchange = new AuthExchange();
+        proxyAuthExchange.setState(AuthExchange.State.SUCCESS);
+        proxyAuthExchange.select(new NTLMScheme());
+        context.setAuthExchange(proxy, proxyAuthExchange);
 
         final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
         credentialsProvider.setCredentials(new AuthScope(target), new UsernamePasswordCredentials("user:pass"));
@@ -472,7 +471,7 @@ public class TestMainClientExec {
 
         Assert.assertNotNull(finalResponse);
         Assert.assertEquals(200, finalResponse.getStatusLine().getStatusCode());
-        Assert.assertNull(proxyAuthState.getAuthScheme());
+        Assert.assertNull(proxyAuthExchange.getAuthScheme());
     }
 
     @Test(expected = NonRepeatableRequestException.class)
@@ -601,14 +600,13 @@ public class TestMainClientExec {
 
     @Test
     public void testEstablishDirectRoute() throws Exception {
-        final AuthExchange authState = new AuthExchange();
         final HttpRoute route = new HttpRoute(target);
         final HttpClientContext context = new HttpClientContext();
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
 
         Mockito.when(managedConn.isOpen()).thenReturn(Boolean.TRUE);
 
-        mainClientExec.establishRoute(authState, managedConn, route, request, context);
+        mainClientExec.establishRoute(managedConn, route, request, context);
 
         Mockito.verify(connManager).connect(managedConn, route, 0, context);
         Mockito.verify(connManager).routeComplete(managedConn, route, context);
@@ -616,14 +614,13 @@ public class TestMainClientExec {
 
     @Test
     public void testEstablishRouteDirectProxy() throws Exception {
-        final AuthExchange authState = new AuthExchange();
         final HttpRoute route = new HttpRoute(target, null, proxy, false);
         final HttpClientContext context = new HttpClientContext();
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
 
         Mockito.when(managedConn.isOpen()).thenReturn(Boolean.TRUE);
 
-        mainClientExec.establishRoute(authState, managedConn, route, request, context);
+        mainClientExec.establishRoute(managedConn, route, request, context);
 
         Mockito.verify(connManager).connect(managedConn, route, 0, context);
         Mockito.verify(connManager).routeComplete(managedConn, route, context);
@@ -631,7 +628,6 @@ public class TestMainClientExec {
 
     @Test
     public void testEstablishRouteViaProxyTunnel() throws Exception {
-        final AuthExchange authState = new AuthExchange();
         final HttpRoute route = new HttpRoute(target, null, proxy, true);
         final HttpClientContext context = new HttpClientContext();
         final RequestConfig config = RequestConfig.custom()
@@ -647,7 +643,7 @@ public class TestMainClientExec {
                 Mockito.<HttpClientConnection>any(),
                 Mockito.<HttpClientContext>any())).thenReturn(response);
 
-        mainClientExec.establishRoute(authState, managedConn, route, request, context);
+        mainClientExec.establishRoute(managedConn, route, request, context);
 
         Mockito.verify(connManager).connect(managedConn, route, 321, context);
         Mockito.verify(connManager).routeComplete(managedConn, route, context);
@@ -665,7 +661,6 @@ public class TestMainClientExec {
 
     @Test(expected = HttpException.class)
     public void testEstablishRouteViaProxyTunnelUnexpectedResponse() throws Exception {
-        final AuthExchange authState = new AuthExchange();
         final HttpRoute route = new HttpRoute(target, null, proxy, true);
         final HttpClientContext context = new HttpClientContext();
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
@@ -677,12 +672,11 @@ public class TestMainClientExec {
                 Mockito.<HttpClientConnection>any(),
                 Mockito.<HttpClientContext>any())).thenReturn(response);
 
-        mainClientExec.establishRoute(authState, managedConn, route, request, context);
+        mainClientExec.establishRoute(managedConn, route, request, context);
     }
 
     @Test(expected = HttpException.class)
     public void testEstablishRouteViaProxyTunnelFailure() throws Exception {
-        final AuthExchange authState = new AuthExchange();
         final HttpRoute route = new HttpRoute(target, null, proxy, true);
         final HttpClientContext context = new HttpClientContext();
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
@@ -696,7 +690,7 @@ public class TestMainClientExec {
                 Mockito.<HttpClientContext>any())).thenReturn(response);
 
         try {
-            mainClientExec.establishRoute(authState, managedConn, route, request, context);
+            mainClientExec.establishRoute(managedConn, route, request, context);
         } catch (final TunnelRefusedException ex) {
             final HttpResponse r = ex.getResponse();
             Assert.assertEquals("Ka-boom", EntityUtils.toString(r.getEntity()));
@@ -709,7 +703,6 @@ public class TestMainClientExec {
 
     @Test
     public void testEstablishRouteViaProxyTunnelRetryOnAuthChallengePersistentConnection() throws Exception {
-        final AuthExchange authState = new AuthExchange();
         final HttpRoute route = new HttpRoute(target, null, proxy, true);
         final HttpClientContext context = new HttpClientContext();
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
@@ -739,7 +732,7 @@ public class TestMainClientExec {
                 Mockito.<Map<String, AuthChallenge>>any(),
                 Mockito.<HttpClientContext>any())).thenReturn(Collections.<AuthScheme>singletonList(new BasicScheme()));
 
-        mainClientExec.establishRoute(authState, managedConn, route, request, context);
+        mainClientExec.establishRoute(managedConn, route, request, context);
 
         Mockito.verify(connManager).connect(managedConn, route, 0, context);
         Mockito.verify(connManager).routeComplete(managedConn, route, context);
@@ -748,7 +741,6 @@ public class TestMainClientExec {
 
     @Test
     public void testEstablishRouteViaProxyTunnelRetryOnAuthChallengeNonPersistentConnection() throws Exception {
-        final AuthExchange authState = new AuthExchange();
         final HttpRoute route = new HttpRoute(target, null, proxy, true);
         final HttpClientContext context = new HttpClientContext();
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(new HttpGet("http://bar/test"));
@@ -778,7 +770,7 @@ public class TestMainClientExec {
                 Mockito.<Map<String, AuthChallenge>>any(),
                 Mockito.<HttpClientContext>any())).thenReturn(Collections.<AuthScheme>singletonList(new BasicScheme()));
 
-        mainClientExec.establishRoute(authState, managedConn, route, request, context);
+        mainClientExec.establishRoute(managedConn, route, request, context);
 
         Mockito.verify(connManager).connect(managedConn, route, 0, context);
         Mockito.verify(connManager).routeComplete(managedConn, route, context);
@@ -788,7 +780,6 @@ public class TestMainClientExec {
 
     @Test(expected = HttpException.class)
     public void testEstablishRouteViaProxyTunnelMultipleHops() throws Exception {
-        final AuthExchange authState = new AuthExchange();
         final HttpHost proxy1 = new HttpHost("this", 8888);
         final HttpHost proxy2 = new HttpHost("that", 8888);
         final HttpRoute route = new HttpRoute(target, null, new HttpHost[] {proxy1, proxy2},
@@ -798,7 +789,7 @@ public class TestMainClientExec {
 
         Mockito.when(managedConn.isOpen()).thenReturn(Boolean.TRUE);
 
-        mainClientExec.establishRoute(authState, managedConn, route, request, context);
+        mainClientExec.establishRoute(managedConn, route, request, context);
     }
 
 }
\ No newline at end of file

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java?rev=1694620&r1=1694619&r2=1694620&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/execchain/TestRedirectExec.java Fri Aug  7 07:34:13 2015
@@ -230,19 +230,21 @@ public class TestRedirectExec {
 
     @Test
     public void testCrossSiteRedirect() throws Exception {
-        final HttpRoute route = new HttpRoute(target);
+
+        final HttpHost proxy = new HttpHost("proxy");
+        final HttpRoute route = new HttpRoute(target, proxy);
         final HttpGet get = new HttpGet("/test");
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(get);
         final HttpClientContext context = HttpClientContext.create();
 
-        final AuthExchange targetAuthState = new AuthExchange();
-        targetAuthState.setState(AuthExchange.State.SUCCESS);
-        targetAuthState.select(new BasicScheme());
-        final AuthExchange proxyAuthState = new AuthExchange();
-        proxyAuthState.setState(AuthExchange.State.SUCCESS);
-        proxyAuthState.select(new NTLMScheme());
-        context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, targetAuthState);
-        context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, proxyAuthState);
+        final AuthExchange targetAuthExchange = new AuthExchange();
+        targetAuthExchange.setState(AuthExchange.State.SUCCESS);
+        targetAuthExchange.select(new BasicScheme());
+        final AuthExchange proxyAuthExchange = new AuthExchange();
+        proxyAuthExchange.setState(AuthExchange.State.SUCCESS);
+        proxyAuthExchange.select(new NTLMScheme());
+        context.setAuthExchange(target, targetAuthExchange);
+        context.setAuthExchange(proxy, proxyAuthExchange);
 
         final CloseableHttpResponse response1 = Mockito.mock(CloseableHttpResponse.class);
         final CloseableHttpResponse response2 = Mockito.mock(CloseableHttpResponse.class);
@@ -272,12 +274,14 @@ public class TestRedirectExec {
 
         redirectExec.execute(route, request, context, execAware);
 
-        Assert.assertNotNull(context.getTargetAuthState());
-        Assert.assertEquals(AuthExchange.State.UNCHALLENGED, context.getTargetAuthState().getState());
-        Assert.assertEquals(null, context.getTargetAuthState().getAuthScheme());
-        Assert.assertNotNull(context.getProxyAuthState());
-        Assert.assertEquals(AuthExchange.State.UNCHALLENGED, context.getProxyAuthState().getState());
-        Assert.assertEquals(null, context.getProxyAuthState().getAuthScheme());
+        final AuthExchange authExchange1 = context.getAuthExchange(target);
+        Assert.assertNotNull(authExchange1);
+        Assert.assertEquals(AuthExchange.State.UNCHALLENGED, authExchange1.getState());
+        Assert.assertEquals(null, authExchange1.getAuthScheme());
+        final AuthExchange authExchange2 = context.getAuthExchange(proxy);
+        Assert.assertNotNull(authExchange2);
+        Assert.assertEquals(AuthExchange.State.UNCHALLENGED, authExchange2.getState());
+        Assert.assertEquals(null, authExchange2.getAuthScheme());
     }
 
     @Test(expected = RuntimeException.class)



Mime
View raw message