You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2007/05/17 12:36:58 UTC

svn commit: r538866 - in /jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client: AbstractHttpClient.java DefaultAuthenticationHandler.java DefaultClientRequestDirector.java DefaultHttpClient.java

Author: olegk
Date: Thu May 17 03:36:55 2007
New Revision: 538866

URL: http://svn.apache.org/viewvc?view=rev&rev=538866
Log:
Obtain HTTP state information from HTTP context

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultAuthenticationHandler.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java?view=diff&rev=538866&r1=538865&r2=538866
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java Thu May 17 03:36:55 2007
@@ -439,7 +439,6 @@
                     getHttpRequestRetryHandler(),
                     getRedirectHandler(),
                     getAuthenticationHandler(),
-                    getState(),
                     getParams());
         }
 

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultAuthenticationHandler.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultAuthenticationHandler.java?view=diff&rev=538866&r1=538865&r2=538866
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultAuthenticationHandler.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultAuthenticationHandler.java Thu May 17 03:36:55 2007
@@ -50,6 +50,7 @@
 import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.client.AuthenticationHandler;
 import org.apache.http.client.params.HttpClientParams;
+import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.message.BufferedHeader;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HTTP;
@@ -68,14 +69,8 @@
             "basic"
     });
     
-    private final AuthSchemeRegistry registry;
-    
-    public DefaultAuthenticationHandler(final AuthSchemeRegistry registry) {
+    public DefaultAuthenticationHandler() {
         super();
-        if (registry == null) {
-            throw new IllegalArgumentException("AuthScheme registry may not be null");
-        }
-        this.registry = registry;
     }
     
     public boolean isTargetAuthenticationRequested(
@@ -157,6 +152,12 @@
             final HttpResponse response,
             final HttpContext context) throws AuthenticationException {
         
+        AuthSchemeRegistry registry = (AuthSchemeRegistry) context.getAttribute(
+                HttpClientContext.AUTHSCHEME_REGISTRY);
+        if (registry == null) {
+            throw new IllegalStateException("AuthScheme registry not set in HTTP context");
+        }
+        
         HttpParams params = response.getParams();
         Collection authPrefs = (Collection) params.getParameter(
                 HttpClientParams.AUTH_SCHEME_PRIORITY);
@@ -177,7 +178,7 @@
                     LOG.debug(id + " authentication scheme selected");
                 }
                 try {
-                    authScheme = this.registry.getAuthScheme(id, params);
+                    authScheme = registry.getAuthScheme(id, params);
                 } catch (IllegalStateException e) {
                     throw new AuthenticationException(e.getMessage());
                 }

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java?view=diff&rev=538866&r1=538865&r2=538866
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultClientRequestDirector.java Thu May 17 03:36:55 2007
@@ -126,9 +126,6 @@
     /** The authentication handler. */
     private final AuthenticationHandler authHandler;
     
-    /** The HTTP state */
-    private final HttpState state;
-    
     /** The HTTP parameters. */
     protected final HttpParams params;
     
@@ -150,7 +147,6 @@
             final HttpRequestRetryHandler retryHandler,
             final RedirectHandler redirectHandler,
             final AuthenticationHandler authHandler,
-            final HttpState state,
             final HttpParams params) {
 
         if (conman == null) {
@@ -171,9 +167,6 @@
         if (authHandler == null) {
             throw new IllegalArgumentException("Authentication handler may not be null");
         }
-        if (state == null) {
-            throw new IllegalArgumentException("HTTP state may not be null");
-        }
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
@@ -183,7 +176,6 @@
         this.retryHandler  = retryHandler;
         this.redirectHandler = redirectHandler;
         this.authHandler   = authHandler;
-        this.state         = state;
         this.params        = params;
         this.requestExec   = new HttpRequestExecutor(params);
 
@@ -658,7 +650,9 @@
             return new RoutedRequest.Impl(redirect, newRoute);
         }
 
-        if (HttpClientParams.isAuthenticating(params)) {
+        HttpState state = (HttpState) context.getAttribute(HttpClientContext.HTTP_STATE);
+        
+        if (state != null && HttpClientParams.isAuthenticating(params)) {
 
             if (this.authHandler.isTargetAuthenticationRequested(response, context)) {
 
@@ -677,7 +671,7 @@
                         return null;
                     }
                 }
-                updateAuthState(this.targetAuthState, target);
+                updateAuthState(this.targetAuthState, target, state);
                 
                 if (this.targetAuthState.getCredentials() != null) {
                     // Re-try the same request via the same route
@@ -702,7 +696,7 @@
                         return null;
                     }
                 }
-                updateAuthState(this.proxyAuthState, proxy);
+                updateAuthState(this.proxyAuthState, proxy, state);
                 
                 if (this.proxyAuthState.getCredentials() != null) {
                     // Re-try the same request via the same route
@@ -801,7 +795,10 @@
     }
     
     
-    private void updateAuthState(final AuthState authState, final HttpHost host) {
+    private void updateAuthState(
+            final AuthState authState, 
+            final HttpHost host,
+            final HttpState state) {
         AuthScheme authScheme = authState.getAuthScheme();
         AuthScope authScope = new AuthScope(
                 host.getHostName(),
@@ -814,7 +811,7 @@
         }
         Credentials creds = authState.getCredentials();
         if (creds == null) {
-            creds = this.state.getCredentials(authScope);
+            creds = state.getCredentials(authScope);
             if (LOG.isDebugEnabled()) {
                 if (creds != null) {
                     LOG.debug("Found credentials");

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java?view=diff&rev=538866&r1=538865&r2=538866
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java (original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/DefaultHttpClient.java Thu May 17 03:36:55 2007
@@ -224,7 +224,7 @@
 
 
     protected AuthenticationHandler createAuthenticationHandler() {
-        return new DefaultAuthenticationHandler(getAuthSchemes());
+        return new DefaultAuthenticationHandler();
     }