hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r883855 - in /httpcomponents/httpclient/trunk: ./ httpclient/src/main/java/org/apache/http/client/ httpclient/src/main/java/org/apache/http/impl/client/
Date Tue, 24 Nov 2009 20:27:19 GMT
Author: olegk
Date: Tue Nov 24 20:27:18 2009
New Revision: 883855

URL: http://svn.apache.org/viewvc?rev=883855&view=rev
Log:
HTTPCLIENT-862: Extended client's redirect handling interface to allow control of the content
of the redirect

Added:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectStrategy.java
      - copied, changed from r833339, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java
      - copied, changed from r833339, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategyAdaptor.java
  (with props)
Removed:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/HttpRedirect.java
Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=883855&r1=883854&r2=883855&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Tue Nov 24 20:27:18 2009
@@ -1,6 +1,10 @@
 Changes since 4.0
 -------------------
 
+* [HTTPCLIENT-862] Extended client's redirect handling interface to allow 
+  control of the content of the redirect.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-872] HttpClient can now persist authentication data between request 
   executions as long as they share the same execution context. It has also become
   much easier to make HttpClient authenticate preemptively by pre-populating 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java?rev=883855&r1=883854&r2=883855&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java
Tue Nov 24 20:27:18 2009
@@ -43,7 +43,10 @@
  * from multiple threads.
  *
  * @since 4.0
+ * 
+ * @deprecated use {@link RedirectStrategy}
  */
+@Deprecated
 public interface RedirectHandler {
 
     /**

Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectStrategy.java
(from r833339, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectStrategy.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectStrategy.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java&r1=833339&r2=883855&rev=883855&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectHandler.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/RedirectStrategy.java
Tue Nov 24 20:27:18 2009
@@ -27,14 +27,14 @@
 
 package org.apache.http.client;
 
-import java.net.URI;
-
+import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.ProtocolException;
+import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.protocol.HttpContext;
 
 /**
- * A handler for determining if an HTTP request should be redirected to 
+ * A strategy for determining if an HTTP request should be redirected to 
  * a new location in response to an HTTP response received from the target
  * server.
  * <p>
@@ -42,33 +42,40 @@
  * data must be synchronized as methods of this interface may be executed 
  * from multiple threads.
  *
- * @since 4.0
+ * @since 4.1
  */
-public interface RedirectHandler {
+public interface RedirectStrategy {
 
     /**
      * Determines if a request should be redirected to a new location
      * given the response from the target server.
      * 
+     * @param request the executed request
      * @param response the response received from the target server
      * @param context the context for the request execution
      * 
      * @return <code>true</code> if the request should be redirected, <code>false</code>
      * otherwise
      */
-    boolean isRedirectRequested(HttpResponse response, HttpContext context);
+    boolean isRedirected(
+            HttpRequest request,
+            HttpResponse response, 
+            HttpContext context) throws ProtocolException;
     
     /**
-     * Determines the location request is expected to be redirected to 
-     * given the response from the target server and the current request
-     * execution context.
+     * Determines the redirect location given the response from the target 
+     * server and the current request execution context and generates a new 
+     * request to be sent to the location.
      * 
+     * @param request the executed request
      * @param response the response received from the target server
      * @param context the context for the request execution
      * 
-     * @return redirect URI 
+     * @return redirected request 
      */
-    URI getLocationURI(HttpResponse response, HttpContext context)
-            throws ProtocolException;
-
-}
+    HttpUriRequest getRedirect(
+            HttpRequest request,
+            HttpResponse response, 
+            HttpContext context) throws ProtocolException;
+    
+}
\ No newline at end of file

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java?rev=883855&r1=883854&r2=883855&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
Tue Nov 24 20:27:18 2009
@@ -47,13 +47,13 @@
 import org.apache.http.auth.AuthSchemeRegistry;
 import org.apache.http.client.AuthenticationHandler;
 import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.RedirectStrategy;
 import org.apache.http.client.RequestDirector;
 import org.apache.http.client.ResponseHandler;
 import org.apache.http.client.CookieStore;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.HttpRequestRetryHandler;
-import org.apache.http.client.RedirectHandler;
 import org.apache.http.client.UserTokenHandler;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
@@ -127,10 +127,10 @@
  *    may involve multiple intermediate hops. 
  *    The {@link #createHttpRoutePlanner()} must be implemented 
  *    by concrete super classes to instantiate this object.
- *   <li>{@link RedirectHandler}</li> object used to determine if an HTTP 
+ *   <li>{@link RedirectStrategy}</li> object used to determine if an HTTP 
  *    request should be redirected to a new location in response to an HTTP 
  *    response received from the target server. 
- *    The {@link #createRedirectHandler()} must be implemented 
+ *    The {@link #createRedirectStrategy()} must be implemented 
  *    by concrete super classes to instantiate this object.
  *   <li>{@link UserTokenHandler}</li> object used to determine if the 
  *    execution context is user identity specific. 
@@ -200,7 +200,7 @@
 
     /** The redirect handler. */
     @GuardedBy("this")
-    private RedirectHandler redirectHandler;
+    private RedirectStrategy redirectStrategy;
 
     /** The target authentication handler. */
     @GuardedBy("this")
@@ -270,9 +270,15 @@
     protected abstract HttpRequestRetryHandler createHttpRequestRetryHandler();
 
     
-    protected abstract RedirectHandler createRedirectHandler();
+    @Deprecated
+    protected abstract org.apache.http.client.RedirectHandler createRedirectHandler();
 
+    /**
+     * @since 4.1
+     */
+    protected abstract RedirectStrategy createRedirectStrategy();
     
+
     protected abstract AuthenticationHandler createTargetAuthenticationHandler();
 
     
@@ -392,16 +398,32 @@
     }
 
 
-    public synchronized final RedirectHandler getRedirectHandler() {
-        if (redirectHandler == null) {
-            redirectHandler = createRedirectHandler();
-        }
-        return redirectHandler;
+    @Deprecated
+    public synchronized final org.apache.http.client.RedirectHandler getRedirectHandler()
{
+        return createRedirectHandler();
+    }
+
+
+    @Deprecated
+    public synchronized void setRedirectHandler(final org.apache.http.client.RedirectHandler
redirectHandler) {
+        this.redirectStrategy = new DefaultRedirectStrategyAdaptor(redirectHandler);
     }
 
+    /**
+     * @since 4.1
+     */
+    public synchronized final RedirectStrategy getRedirectStrategy() {
+        if (redirectStrategy == null) {
+            redirectStrategy = createRedirectStrategy();
+        }
+        return redirectStrategy;
+    }
 
-    public synchronized void setRedirectHandler(final RedirectHandler redirectHandler) {
-        this.redirectHandler = redirectHandler;
+    /**
+     * @since 4.1
+     */
+    public synchronized void setRedirectStrategy(final RedirectStrategy redirectStrategy)
{
+        this.redirectStrategy = redirectStrategy;
     }
 
 
@@ -677,6 +699,7 @@
         }
     }
 
+    @Deprecated
     protected RequestDirector createClientRequestDirector(
             final HttpRequestExecutor requestExec,
             final ClientConnectionManager conman,
@@ -685,7 +708,7 @@
             final HttpRoutePlanner rouplan,
             final HttpProcessor httpProcessor,
             final HttpRequestRetryHandler retryHandler,
-            final RedirectHandler redirectHandler,
+            final org.apache.http.client.RedirectHandler redirectHandler,
             final AuthenticationHandler targetAuthHandler,
             final AuthenticationHandler proxyAuthHandler,
             final UserTokenHandler stateHandler,
@@ -706,6 +729,36 @@
     }
 
     /**
+     * @since 4.1
+     */
+    protected RequestDirector createClientRequestDirector(
+            final HttpRequestExecutor requestExec,
+            final ClientConnectionManager conman,
+            final ConnectionReuseStrategy reustrat,
+            final ConnectionKeepAliveStrategy kastrat,
+            final HttpRoutePlanner rouplan,
+            final HttpProcessor httpProcessor,
+            final HttpRequestRetryHandler retryHandler,
+            final RedirectStrategy redirectStrategy,
+            final AuthenticationHandler targetAuthHandler,
+            final AuthenticationHandler proxyAuthHandler,
+            final UserTokenHandler stateHandler,
+            final HttpParams params) {
+        return new DefaultRequestDirector(
+                requestExec,
+                conman,
+                reustrat,
+                kastrat,
+                rouplan,
+                httpProcessor,
+                retryHandler,
+                redirectStrategy,
+                targetAuthHandler,
+                proxyAuthHandler,
+                stateHandler,
+                params);
+    }
+    /**
      * Obtains parameters for executing a request.
      * The default implementation in this class creates a new
      * {@link ClientParamsStack} from the request parameters

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java?rev=883855&r1=883854&r2=883855&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java
Tue Nov 24 20:27:18 2009
@@ -36,7 +36,7 @@
 import org.apache.http.client.CookieStore;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.HttpRequestRetryHandler;
-import org.apache.http.client.RedirectHandler;
+import org.apache.http.client.RedirectStrategy;
 import org.apache.http.client.UserTokenHandler;
 import org.apache.http.client.params.AuthPolicy;
 import org.apache.http.client.params.ClientPNames;
@@ -354,10 +354,19 @@
 
 
     @Override
-    protected RedirectHandler createRedirectHandler() {
+    @Deprecated
+    protected org.apache.http.client.RedirectHandler createRedirectHandler() {
         return new DefaultRedirectHandler();
     }
 
+    /**
+     * @since 4.1
+     */
+    @Override
+    protected RedirectStrategy createRedirectStrategy() {
+        return new DefaultRedirectStrategy();
+    }
+
 
     @Override
     protected AuthenticationHandler createTargetAuthenticationHandler() {

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java?rev=883855&r1=883854&r2=883855&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
Tue Nov 24 20:27:18 2009
@@ -54,8 +54,11 @@
  * Default implementation of {@link RedirectHandler}.
  *
  * @since 4.0
+ * 
+ * @deprecated use {@link DefaultRedirectStrategy}.
  */
 @Immutable
+@Deprecated
 public class DefaultRedirectHandler implements RedirectHandler {
 
     private final Log log = LogFactory.getLog(getClass());

Copied: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java
(from r833339, httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java?p2=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java&p1=httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java&r1=833339&r2=883855&rev=883855&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategy.java
Tue Nov 24 20:27:18 2009
@@ -41,9 +41,10 @@
 import org.apache.http.HttpStatus;
 import org.apache.http.ProtocolException;
 import org.apache.http.client.CircularRedirectException;
-import org.apache.http.client.RedirectHandler;
+import org.apache.http.client.RedirectStrategy;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.params.ClientPNames;
 import org.apache.http.client.utils.URIUtils;
 import org.apache.http.params.HttpParams;
@@ -51,24 +52,25 @@
 import org.apache.http.protocol.ExecutionContext;
 
 /**
- * Default implementation of {@link RedirectHandler}.
+ * Default implementation of {@link RedirectStrategy}.
  *
- * @since 4.0
+ * @since 4.1
  */
 @Immutable
-public class DefaultRedirectHandler implements RedirectHandler {
+public class DefaultRedirectStrategy implements RedirectStrategy {
 
     private final Log log = LogFactory.getLog(getClass());
     
     private static final String REDIRECT_LOCATIONS = "http.protocol.redirect-locations";
 
-    public DefaultRedirectHandler() {
+    public DefaultRedirectStrategy() {
         super();
     }
     
-    public boolean isRedirectRequested(
-            final HttpResponse response,
-            final HttpContext context) {
+    public boolean isRedirected(
+            final HttpRequest request,
+            final HttpResponse response, 
+            final HttpContext context) throws ProtocolException {
         if (response == null) {
             throw new IllegalArgumentException("HTTP response may not be null");
         }
@@ -78,8 +80,6 @@
         case HttpStatus.SC_MOVED_TEMPORARILY:
         case HttpStatus.SC_MOVED_PERMANENTLY:
         case HttpStatus.SC_TEMPORARY_REDIRECT:
-            HttpRequest request = (HttpRequest) context.getAttribute(
-                    ExecutionContext.HTTP_REQUEST);
             String method = request.getRequestLine().getMethod();
             return method.equalsIgnoreCase(HttpGet.METHOD_NAME) 
                 || method.equalsIgnoreCase(HttpHead.METHOD_NAME);
@@ -91,6 +91,7 @@
     }
  
     public URI getLocationURI(
+            final HttpRequest request,
             final HttpResponse response, 
             final HttpContext context) throws ProtocolException {
         if (response == null) {
@@ -131,10 +132,6 @@
                 throw new IllegalStateException("Target host not available " +
                         "in the HTTP context");
             }
-            
-            HttpRequest request = (HttpRequest) context.getAttribute(
-                    ExecutionContext.HTTP_REQUEST);
-            
             try {
                 URI requestURI = new URI(request.getRequestLine().getUri());
                 URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true);
@@ -180,4 +177,17 @@
         return uri;
     }
 
-}
+    public HttpUriRequest getRedirect(
+            final HttpRequest request,
+            final HttpResponse response, 
+            final HttpContext context) throws ProtocolException {
+        URI uri = getLocationURI(request, response, context);
+        String method = request.getRequestLine().getMethod();
+        if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
+            return new HttpHead(uri);
+        } else {
+            return new HttpGet(uri);
+        }
+    }
+    
+}
\ No newline at end of file

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategyAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategyAdaptor.java?rev=883855&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategyAdaptor.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategyAdaptor.java
Tue Nov 24 20:27:18 2009
@@ -0,0 +1,77 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.client;
+
+import java.net.URI;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolException;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.client.RedirectStrategy;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @since 4.1
+ */
+@Immutable
+@Deprecated
+class DefaultRedirectStrategyAdaptor implements RedirectStrategy {
+
+    private final org.apache.http.client.RedirectHandler handler;
+    
+    @Deprecated
+    public DefaultRedirectStrategyAdaptor(final org.apache.http.client.RedirectHandler handler)
{
+        super();
+        this.handler = handler;
+    }
+    
+    public boolean isRedirected(
+            final HttpRequest request,
+            final HttpResponse response, 
+            final HttpContext context) throws ProtocolException {
+        return this.handler.isRedirectRequested(response, context);
+    }
+ 
+    public HttpUriRequest getRedirect(
+            final HttpRequest request,
+            final HttpResponse response, 
+            final HttpContext context) throws ProtocolException {
+        URI uri = this.handler.getLocationURI(response, context);
+        String method = request.getRequestLine().getMethod();
+        if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) {
+            return new HttpHead(uri);
+        } else {
+            return new HttpGet(uri);
+        }
+    }
+    
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategyAdaptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategyAdaptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRedirectStrategyAdaptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=883855&r1=883854&r2=883855&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Tue Nov 24 20:27:18 2009
@@ -56,14 +56,15 @@
 import org.apache.http.auth.Credentials;
 import org.apache.http.auth.MalformedChallengeException;
 import org.apache.http.client.AuthenticationHandler;
+import org.apache.http.client.RedirectStrategy;
 import org.apache.http.client.RequestDirector;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.client.NonRepeatableRequestException;
 import org.apache.http.client.RedirectException;
-import org.apache.http.client.RedirectHandler;
 import org.apache.http.client.UserTokenHandler;
 import org.apache.http.client.methods.AbortableHttpRequest;
+import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.params.ClientPNames;
 import org.apache.http.client.params.HttpClientParams;
 import org.apache.http.client.protocol.ClientContext;
@@ -158,7 +159,11 @@
     protected final HttpRequestRetryHandler retryHandler;
     
     /** The redirect handler. */
-    protected final RedirectHandler redirectHandler;
+    @Deprecated
+    protected final org.apache.http.client.RedirectHandler redirectHandler = null;
+    
+    /** The redirect strategy. */
+    protected final RedirectStrategy redirectStrategy;
     
     /** The target authentication handler. */
     protected final AuthenticationHandler targetAuthHandler;
@@ -184,7 +189,30 @@
     private int maxRedirects;
     
     private HttpHost virtualHost;
+
+    @Deprecated
+    public DefaultRequestDirector(
+            final HttpRequestExecutor requestExec,
+            final ClientConnectionManager conman,
+            final ConnectionReuseStrategy reustrat,
+            final ConnectionKeepAliveStrategy kastrat,
+            final HttpRoutePlanner rouplan,
+            final HttpProcessor httpProcessor,
+            final HttpRequestRetryHandler retryHandler,
+            final org.apache.http.client.RedirectHandler redirectHandler,
+            final AuthenticationHandler targetAuthHandler,
+            final AuthenticationHandler proxyAuthHandler,
+            final UserTokenHandler userTokenHandler,
+            final HttpParams params) {
+        this(requestExec, conman, reustrat, kastrat, rouplan, httpProcessor, retryHandler,
+                new DefaultRedirectStrategyAdaptor(redirectHandler), 
+                targetAuthHandler, proxyAuthHandler, userTokenHandler, params);
+    }    
+    
     
+    /**
+     * @since 4.1
+     */
     public DefaultRequestDirector(
             final HttpRequestExecutor requestExec,
             final ClientConnectionManager conman,
@@ -193,7 +221,7 @@
             final HttpRoutePlanner rouplan,
             final HttpProcessor httpProcessor,
             final HttpRequestRetryHandler retryHandler,
-            final RedirectHandler redirectHandler,
+            final RedirectStrategy redirectStrategy,
             final AuthenticationHandler targetAuthHandler,
             final AuthenticationHandler proxyAuthHandler,
             final UserTokenHandler userTokenHandler,
@@ -227,9 +255,9 @@
             throw new IllegalArgumentException
                 ("HTTP request retry handler may not be null.");
         }
-        if (redirectHandler == null) {
+        if (redirectStrategy == null) {
             throw new IllegalArgumentException
-                ("Redirect handler may not be null.");
+                ("Redirect strategy may not be null.");
         }
         if (targetAuthHandler == null) {
             throw new IllegalArgumentException
@@ -254,7 +282,7 @@
         this.routePlanner      = rouplan;
         this.httpProcessor     = httpProcessor;
         this.retryHandler      = retryHandler;
-        this.redirectHandler   = redirectHandler;
+        this.redirectStrategy  = redirectStrategy;
         this.targetAuthHandler = targetAuthHandler;
         this.proxyAuthHandler  = proxyAuthHandler;
         this.userTokenHandler  = userTokenHandler; 
@@ -810,7 +838,6 @@
             }
         }
 
-        @SuppressWarnings("null")
         int status = response.getStatusLine().getStatusCode(); // can't be null
 
         if (status > 299) {
@@ -936,7 +963,7 @@
         
         HttpParams params = request.getParams();
         if (HttpClientParams.isRedirecting(params) && 
-                this.redirectHandler.isRedirectRequested(response, context)) {
+                this.redirectStrategy.isRedirected(request, response, context)) {
 
             if (redirectCount >= maxRedirects) {
                 throw new RedirectException("Maximum redirects ("
@@ -947,7 +974,11 @@
             // Virtual host cannot be used any longer
             virtualHost = null;
             
-            URI uri = this.redirectHandler.getLocationURI(response, context);
+            HttpUriRequest redirect = redirectStrategy.getRedirect(request, response, context);

+            HttpRequest orig = request.getOriginal();
+            redirect.setHeaders(orig.getAllHeaders());
+            
+            URI uri = redirect.getURI();
 
             HttpHost newTarget = new HttpHost(
                     uri.getHost(), 
@@ -967,10 +998,6 @@
                 }
             }
 
-            HttpRedirect redirect = new HttpRedirect(request.getMethod(), uri); 
-            HttpRequest orig = request.getOriginal();
-            redirect.setHeaders(orig.getAllHeaders());
-            
             RequestWrapper wrapper = new RequestWrapper(redirect);
             wrapper.setParams(params);
             



Mime
View raw message