hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r558131 - in /jakarta/httpcomponents/httpclient/trunk/module-client/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/
Date Fri, 20 Jul 2007 20:53:25 GMT
Author: olegk
Date: Fri Jul 20 13:53:23 2007
New Revision: 558131

URL: http://svn.apache.org/viewvc?view=rev&rev=558131
Log:
* Changed protocol cookie interceptors to use CookieStore instead of HttpState 
* Changed default client request redirector to use CredentialsProvider instead of HttpState
* Deprecated HttpState

Modified:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpState.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ClientContext.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java?view=diff&rev=558131&r1=558130&r2=558131
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientCustomContext.java
Fri Jul 20 13:53:23 2007
@@ -33,6 +33,7 @@
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
+import org.apache.http.client.CookieStore;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.HttpState;
 import org.apache.http.client.methods.HttpGet;
@@ -53,15 +54,15 @@
         
         HttpClient httpclient = new DefaultHttpClient();
 
-        // Create a local instance of HttpState
-        HttpState localState = new HttpState();
+        // Create a local instance of cookie store
+        CookieStore cookieStore = new HttpState();
         
         // Obtain default HTTP context
         HttpContext defaultContext = httpclient.getDefaultContext();
         // Create local HTTP context
         HttpContext localContext = new BasicHttpContext(defaultContext);
-        // Bind custom HTTP state to the local context
-        localContext.setAttribute(ClientContext.HTTP_STATE, localState);
+        // Bind custom cookie store to the local context
+        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
         
         HttpGet httpget = new HttpGet("http://www.google.com/"); 
 
@@ -77,7 +78,7 @@
             System.out.println("Response content length: " + entity.getContentLength());
             System.out.println("Chunked?: " + entity.isChunked());
         }
-        Cookie[] cookies = localState.getCookies();
+        Cookie[] cookies = cookieStore.getCookies();
         for (int i = 0; i < cookies.length; i++) {
             System.out.println("Local cookie: " + cookies[i]);
         }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpState.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpState.java?view=diff&rev=558131&r1=558130&r2=558131
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpState.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/HttpState.java
Fri Jul 20 13:53:23 2007
@@ -59,6 +59,7 @@
  * 
  * @version $Revision$ $Date$
  * 
+ * @deprecated
  */
 public class HttpState implements CookieStore, CredentialsProvider {
 

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ClientContext.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ClientContext.java?view=diff&rev=558131&r1=558130&r2=558131
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ClientContext.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ClientContext.java
Fri Jul 20 13:53:23 2007
@@ -40,9 +40,10 @@
     
     public static final String COOKIESPEC_REGISTRY   = "http.cookiespec-registry"; 
     public static final String AUTHSCHEME_REGISTRY   = "http.authscheme-registry"; 
-    public static final String HTTP_STATE            = "http.state"; 
+    public static final String COOKIE_STORE          = "http.cookie-store"; 
     public static final String COOKIE_SPEC           = "http.cookie-spec"; 
     public static final String COOKIE_ORIGIN         = "http.cookie-origin"; 
+    public static final String CREDS_PROVIDER        = "http.auth.credentials-provider";

     public static final String TARGET_AUTH_STATE     = "http.auth.target-scope"; 
     public static final String PROXY_AUTH_STATE      = "http.auth.proxy-scope"; 
 }

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java?view=diff&rev=558131&r1=558130&r2=558131
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/RequestAddCookies.java
Fri Jul 20 13:53:23 2007
@@ -45,7 +45,7 @@
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.ProtocolException;
-import org.apache.http.client.HttpState;
+import org.apache.http.client.CookieStore;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.params.HttpClientParams;
 import org.apache.http.conn.ManagedClientConnection;
@@ -84,11 +84,11 @@
             throw new IllegalArgumentException("HTTP context may not be null");
         }
         
-        // Obtain HTTP state
-        HttpState state = (HttpState) context.getAttribute(
-                ClientContext.HTTP_STATE);
-        if (state == null) {
-            LOG.info("HTTP state not available in HTTP context");
+        // Obtain cookie store
+        CookieStore cookieStore = (CookieStore) context.getAttribute(
+                ClientContext.COOKIE_STORE);
+        if (cookieStore == null) {
+            LOG.info("Cookie store not available in HTTP context");
             return;
         }
         
@@ -146,7 +146,7 @@
         // Get an instance of the selected cookie policy
         CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());
         // Get all cookies available in the HTTP state
-        Cookie[] cookies = state.getCookies();
+        Cookie[] cookies = cookieStore.getCookies();
         // Find cookies matching the given origin
         List matchedCookies = new ArrayList(cookies.length);
         for (int i = 0; i < cookies.length; i++) {

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java?view=diff&rev=558131&r1=558130&r2=558131
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/protocol/ResponseProcessCookies.java
Fri Jul 20 13:53:23 2007
@@ -39,7 +39,7 @@
 import org.apache.http.HttpException;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpResponseInterceptor;
-import org.apache.http.client.HttpState;
+import org.apache.http.client.CookieStore;
 import org.apache.http.cookie.Cookie;
 import org.apache.http.cookie.CookieOrigin;
 import org.apache.http.cookie.CookieSpec;
@@ -74,11 +74,11 @@
             throw new IllegalArgumentException("HTTP context may not be null");
         }
         
-        // Obtain HTTP state
-        HttpState state = (HttpState) context.getAttribute(
-                ClientContext.HTTP_STATE);
-        if (state == null) {
-            LOG.info("HTTP state not available in HTTP context");
+        // Obtain cookie store
+        CookieStore cookieStore = (CookieStore) context.getAttribute(
+                ClientContext.COOKIE_STORE);
+        if (cookieStore == null) {
+            LOG.info("Cookie store not available in HTTP context");
             return;
         }
         // Obtain actual CookieSpec instance
@@ -96,14 +96,14 @@
             return;
         }
         Header[] headers = response.getHeaders(SM.SET_COOKIE);
-        processCookies(headers, cookieSpec, cookieOrigin, state);
+        processCookies(headers, cookieSpec, cookieOrigin, cookieStore);
     }
      
     private static void processCookies(
             final Header[] headers, 
             final CookieSpec cookieSpec,
             final CookieOrigin cookieOrigin,
-            final HttpState state) {
+            final CookieStore cookieStore) {
         for (int i = 0; i < headers.length; i++) {
             Header header = headers[i];
             try {
@@ -112,7 +112,7 @@
                     Cookie cookie = cookies[c];
                     try {
                         cookieSpec.validate(cookie, cookieOrigin);
-                        state.addCookie(cookie);
+                        cookieStore.addCookie(cookie);
                         
                         if (LOG.isDebugEnabled()) {
                             LOG.debug("Cookie accepted: \""

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java?view=diff&rev=558131&r1=558130&r2=558131
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
Fri Jul 20 13:53:23 2007
@@ -59,8 +59,8 @@
 import org.apache.http.client.AuthState;
 import org.apache.http.client.AuthenticationHandler;
 import org.apache.http.client.ClientRequestDirector;
+import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.HttpRequestRetryHandler;
-import org.apache.http.client.HttpState;
 import org.apache.http.client.RedirectException;
 import org.apache.http.client.RedirectHandler;
 import org.apache.http.client.RoutedRequest;
@@ -580,10 +580,10 @@
                         response.getStatusLine());
             }
             
-            HttpState state = (HttpState)
-                context.getAttribute(ClientContext.HTTP_STATE);
+            CredentialsProvider credsProvider = (CredentialsProvider)
+                context.getAttribute(ClientContext.CREDS_PROVIDER);
             
-            if (state != null && HttpClientParams.isAuthenticating(params)) {
+            if (credsProvider != null && HttpClientParams.isAuthenticating(params))
{
                 if (this.authHandler.isProxyAuthenticationRequested(response, context)) {
 
                     LOG.debug("Proxy requested authentication");
@@ -596,7 +596,7 @@
                             break;
                         }
                     }
-                    updateAuthState(this.proxyAuthState, proxy, state);
+                    updateAuthState(this.proxyAuthState, proxy, credsProvider);
                     
                     if (this.proxyAuthState.getCredentials() != null) {
                         done = false;
@@ -758,10 +758,10 @@
             return new RoutedRequest.Impl(redirect, newRoute);
         }
 
-        HttpState state = (HttpState)
-            context.getAttribute(ClientContext.HTTP_STATE);
-        
-        if (state != null && HttpClientParams.isAuthenticating(params)) {
+        CredentialsProvider credsProvider = (CredentialsProvider)
+            context.getAttribute(ClientContext.CREDS_PROVIDER);
+    
+        if (credsProvider != null && HttpClientParams.isAuthenticating(params)) {
 
             if (this.authHandler.isTargetAuthenticationRequested(response, context)) {
 
@@ -781,7 +781,7 @@
                         return null;
                     }
                 }
-                updateAuthState(this.targetAuthState, target, state);
+                updateAuthState(this.targetAuthState, target, credsProvider);
                 
                 if (this.targetAuthState.getCredentials() != null) {
                     // Re-try the same request via the same route
@@ -806,7 +806,7 @@
                         return null;
                     }
                 }
-                updateAuthState(this.proxyAuthState, proxy, state);
+                updateAuthState(this.proxyAuthState, proxy, credsProvider);
                 
                 if (this.proxyAuthState.getCredentials() != null) {
                     // Re-try the same request via the same route
@@ -879,7 +879,7 @@
     private void updateAuthState(
             final AuthState authState, 
             final HttpHost host,
-            final HttpState state) {
+            final CredentialsProvider credsProvider) {
         
         String hostname = host.getHostName();
         int port = host.getPort();
@@ -900,7 +900,7 @@
         }
         Credentials creds = authState.getCredentials();
         if (creds == null) {
-            creds = state.getCredentials(authScope);
+            creds = credsProvider.getCredentials(authScope);
             if (LOG.isDebugEnabled()) {
                 if (creds != null) {
                     LOG.debug("Found credentials");

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java?view=diff&rev=558131&r1=558130&r2=558131
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
Fri Jul 20 13:53:23 2007
@@ -251,7 +251,10 @@
                 ClientContext.COOKIESPEC_REGISTRY, 
                 getCookieSpecs());
         context.setAttribute(
-                ClientContext.HTTP_STATE, 
+                ClientContext.COOKIE_STORE, 
+                getState());
+        context.setAttribute(
+                ClientContext.CREDS_PROVIDER, 
                 getState());
     }
 



Mime
View raw message