hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r603965 - in /jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http: client/ impl/client/
Date Thu, 13 Dec 2007 17:51:10 GMT
Author: rolandw
Date: Thu Dec 13 09:51:03 2007
New Revision: 603965

URL: http://svn.apache.org/viewvc?rev=603965&view=rev
Log:
HTTPCLIENT-714: computation of original route moved to director

Modified:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientRequestDirector.java
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.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/main/java/org/apache/http/client/ClientRequestDirector.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientRequestDirector.java?rev=603965&r1=603964&r2=603965&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientRequestDirector.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/ClientRequestDirector.java
Thu Dec 13 09:51:03 2007
@@ -33,11 +33,11 @@
 
 import java.io.IOException;
 
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpException;
 import org.apache.http.protocol.HttpContext;
-import org.apache.http.conn.HttpRoute; //@@@ replace by HttpTarget
 import org.apache.http.conn.ManagedClientConnection;
 
 
@@ -80,8 +80,11 @@
      * This is the same behavior as for <code>HttpMethodDirector</code>
      * in HttpClient 3.
      *
+     * @param target    the target host for the request.
+     *                  Implementations may accept <code>null</code>
+     *                  if they can still determine a route, for example
+     *                  to a default target or by inspecting the request.
      * @param request   the request to execute
-     * @param route     the route to the target of the request
      * @param context   the context for executing the request
      *
      * @return  the final response to the request.
@@ -91,7 +94,7 @@
      * @throws IOException              in case of an IO problem
      * @throws InterruptedException     in case of an interrupt
      */
-    HttpResponse execute(HttpRequest request, HttpRoute route,
+    HttpResponse execute(HttpHost target, HttpRequest request,
                          HttpContext context)
         throws HttpException, IOException, InterruptedException
         ;

Modified: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java?rev=603965&r1=603964&r2=603965&view=diff
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java
Thu Dec 13 09:51:03 2007
@@ -424,9 +424,9 @@
 
 
     /**
-     * Maps to {@link HttpClient#execute(RoutedRequest,HttpContext)
-     *                           execute(roureq, context)}.
-     * The route is computed by {@link #determineRoute determineRoute}.
+     * Maps to {@link HttpClient#execute(HttpHost,HttpRequest,HttpContext)
+     *                           execute(target, request, context)}.
+     * The target is determined from the URI of the request.
      *
      * @param request   the request to execute
      * @param context   the request-specific execution context,
@@ -442,7 +442,7 @@
         }
 
         // A null target may be acceptable if there is a default target.
-        // Otherwise, the null target is detected in determineRoute().
+        // Otherwise, the null target is detected in the director.
         HttpHost target = null;
         
         URI requestURI = request.getURI();
@@ -453,24 +453,17 @@
                     requestURI.getScheme());
         }
         
-        synchronized (this) {
-            if (context == null) {
-                context = new BasicHttpContext(getDefaultContext());
-            }
-        }
-        
-        RoutedRequest roureq = determineRoute(target, request, context);
-        return execute(roureq, context);
+        return execute(target, request, context);
     }
 
-    
+    //@@@ to be removed with HTTPCLIENT-715
     public HttpResponse execute(RoutedRequest roureq) 
         throws HttpException, IOException, InterruptedException {
         return execute(roureq, null);
     }
 
 
-    // non-javadoc, see interface HttpClient
+    //@@@ to be removed with HTTPCLIENT-715
     public final HttpResponse execute(RoutedRequest roureq,
                                       HttpContext context)
         throws HttpException, IOException, InterruptedException {
@@ -488,6 +481,26 @@
                 ("Route must not be null.");
         }
 
+        //@@@ this is a temporary violation of the API
+        //@@@ this method will be removed with HTTPCLIENT-715
+        return execute(roureq.getRoute().getTargetHost(),
+                       roureq.getRequest(), context);
+    }
+
+
+    // non-javadoc, see interface HttpClient
+    //@@@ currently not in interface, will be changed with HTTPCLIENT-715
+    public final HttpResponse execute(HttpHost target, HttpRequest request,
+                                      HttpContext context)
+        throws HttpException, IOException, InterruptedException {
+
+        if (request == null) {
+            throw new IllegalArgumentException
+                ("Request must not be null.");
+        }
+        // a null target may be acceptable, this depends on the route planner
+        // a null context is acceptable, default context created below
+
         ClientRequestDirector director = null;
         
         // Initialize the request execution context making copies of 
@@ -500,16 +513,16 @@
             director = new DefaultClientRequestDirector(
                     getConnectionManager(),
                     getConnectionReuseStrategy(),
+                    getRoutePlanner(),
                     getHttpProcessor().copy(),
                     getHttpRequestRetryHandler(),
                     getRedirectHandler(),
                     getTargetAuthenticationHandler(),
                     getProxyAuthenticationHandler(),
-                    determineParams(roureq.getRequest()));
+                    determineParams(request));
         }
 
-        HttpResponse response = director.execute(roureq.getRequest(),
-                                                 roureq.getRoute(), context);
+        HttpResponse response = director.execute(target, request, context);
         // If the response depends on the connection, the director
         // will have set up an auto-release input stream.
 
@@ -540,32 +553,6 @@
         return new ClientParamsStack
             (null, getParams(), req.getParams(), null);
     }
-
-
-    /**
-     * Determines the route for a request.
-     * Called by {@link #execute(HttpUriRequest,HttpContext)
-     *                   execute(urirequest, context)}
-     * to map to {@link HttpClient#execute(RoutedRequest,HttpContext)
-     *                             execute(roureq, context)}.
-     *
-     * @param target    the target host for the request.
-     *                  Implementations may accept <code>null</code>
-     *                  if they can still determine a route, for example
-     *                  to a default target or by inspecting the request.
-     * @param request   the request to execute
-     * @param context   the context to use for the execution,
-     *                  never <code>null</code>
-     *
-     * @return  the request along with the route it should take
-     *
-     * @throws HttpException    in case of a problem
-     */
-    protected abstract RoutedRequest determineRoute(HttpHost target,
-                                                    HttpRequest request,
-                                                    HttpContext context)
-        throws HttpException
-        ;
 
 
 } // class AbstractHttpClient

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?rev=603965&r1=603964&r2=603965&view=diff
==============================================================================
--- 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
Thu Dec 13 09:51:03 2007
@@ -71,6 +71,7 @@
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.ConnectionPoolTimeoutException;
 import org.apache.http.conn.HttpRoute;
+import org.apache.http.conn.HttpRoutePlanner;
 import org.apache.http.conn.ManagedClientConnection;
 import org.apache.http.conn.HttpRouteDirector;
 import org.apache.http.conn.BasicRouteDirector;
@@ -108,6 +109,9 @@
     /** The connection manager. */
     protected final ClientConnectionManager connManager;
 
+    /** The route planner. */
+    protected final HttpRoutePlanner routePlanner;
+
     /** The connection re-use strategy. */
     protected final ConnectionReuseStrategy reuseStrategy;
 
@@ -146,6 +150,7 @@
     public DefaultClientRequestDirector(
             final ClientConnectionManager conman,
             final ConnectionReuseStrategy reustrat,
+            final HttpRoutePlanner rouplan,
             final HttpProcessor httpProcessor,
             final HttpRequestRetryHandler retryHandler,
             final RedirectHandler redirectHandler,
@@ -154,31 +159,44 @@
             final HttpParams params) {
 
         if (conman == null) {
-            throw new IllegalArgumentException("Client connection manager may not be null");
+            throw new IllegalArgumentException
+                ("Client connection manager may not be null.");
         }
         if (reustrat == null) {
-            throw new IllegalArgumentException("Connection reuse strategy may not be null");
+            throw new IllegalArgumentException
+                ("Connection reuse strategy may not be null.");
+        }
+        if (rouplan == null) {
+            throw new IllegalArgumentException
+                ("Route planner may not be null.");
         }
         if (httpProcessor == null) {
-            throw new IllegalArgumentException("HTTP protocol processor may not be null");
+            throw new IllegalArgumentException
+                ("HTTP protocol processor may not be null.");
         }
         if (retryHandler == null) {
-            throw new IllegalArgumentException("HTTP request retry handler may not be null");
+            throw new IllegalArgumentException
+                ("HTTP request retry handler may not be null.");
         }
         if (redirectHandler == null) {
-            throw new IllegalArgumentException("Redirect handler may not be null");
+            throw new IllegalArgumentException
+                ("Redirect handler may not be null.");
         }
         if (targetAuthHandler == null) {
-            throw new IllegalArgumentException("Target authentication handler may not be
null");
+            throw new IllegalArgumentException
+                ("Target authentication handler may not be null.");
         }
         if (proxyAuthHandler == null) {
-            throw new IllegalArgumentException("Proxy authentication handler may not be null");
+            throw new IllegalArgumentException
+                ("Proxy authentication handler may not be null.");
         }
         if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
+            throw new IllegalArgumentException
+                ("HTTP parameters may not be null");
         }
         this.connManager       = conman;
         this.reuseStrategy     = reustrat;
+        this.routePlanner      = rouplan;
         this.httpProcessor     = httpProcessor;
         this.retryHandler      = retryHandler;
         this.redirectHandler   = redirectHandler;
@@ -258,11 +276,11 @@
     
     
     // non-javadoc, see interface ClientRequestDirector
-    public HttpResponse execute(HttpRequest request, HttpRoute route,
+    public HttpResponse execute(HttpHost target, HttpRequest request,
                                 HttpContext context)
         throws HttpException, IOException, InterruptedException {
 
-        RoutedRequest roureq = new RoutedRequest.Impl(request, route);
+        RoutedRequest roureq = determineRoute(target, request, context);
 
         final HttpRequest orig = request;
 
@@ -279,7 +297,7 @@
                 // in the method arguments will be replaced. The original
                 // request is still available in 'orig'.
 
-                route = roureq.getRoute();
+                HttpRoute route = roureq.getRoute();
 
                 // Allocate connection if needed
                 if (managedConn == null) {
@@ -316,17 +334,17 @@
                 
                 // Re-write request URI if needed
                 rewriteRequestURI(reqwrap, route);
-                
+
                 // Use virtual host if set
-                HttpHost target = (HttpHost) reqwrap.getParams().getParameter(
+                target = (HttpHost) reqwrap.getParams().getParameter(
                         ClientPNames.VIRTUAL_HOST);
-                
+
                 if (target == null) {
                     target = route.getTargetHost();
                 }
 
                 HttpHost proxy = route.getProxyHost();
-                
+
                 // Populate the execution context
                 context.setAttribute(ExecutionContext.HTTP_TARGET_HOST,
                         target);
@@ -441,6 +459,44 @@
             throw ex;
         }
     } // execute
+
+
+    /**
+     * Determines the route for a request.
+     * Called by {@link #execute}
+     * to determine the route for either the original or a followup request.
+     *
+     * @param target    the target host for the request.
+     *                  Implementations may accept <code>null</code>
+     *                  if they can still determine a route, for example
+     *                  to a default target or by inspecting the request.
+     * @param request   the request to execute
+     * @param context   the context to use for the execution,
+     *                  never <code>null</code>
+     *
+     * @return  the request along with the route it should take
+     *
+     * @throws HttpException    in case of a problem
+     */
+    protected RoutedRequest determineRoute(HttpHost    target,
+                                           HttpRequest request,
+                                           HttpContext context)
+        throws HttpException {
+
+        if (target == null) {
+            target = (HttpHost) request.getParams().getParameter(
+                ClientPNames.DEFAULT_HOST);
+        }
+        if (target == null) {
+            throw new IllegalStateException
+                ("Target host must not be null, or set in parameters.");
+        }
+
+        final HttpRoute route =
+            this.routePlanner.determineRoute(target, request, context);
+
+        return new RoutedRequest.Impl(request, route);
+    }
 
 
     /**

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?rev=603965&r1=603964&r2=603965&view=diff
==============================================================================
--- 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
Thu Dec 13 09:51:03 2007
@@ -286,28 +286,6 @@
 
 
     // non-javadoc, see base class AbstractHttpClient
-    protected RoutedRequest determineRoute(HttpHost target,
-                                           HttpRequest request,
-                                           HttpContext context)
-        throws HttpException {
-
-        if (target == null) {
-            target = (HttpHost) request.getParams().getParameter(
-                ClientPNames.DEFAULT_HOST);
-        }
-        if (target == null) {
-            throw new IllegalStateException
-                ("Target host must not be null, or set in parameters.");
-        }
-
-        HttpRoute route = getRoutePlanner()
-            .determineRoute(target, request, context);
-
-        return new RoutedRequest.Impl(request, route);
-    }
-
-
-    // non-javadoc, see base class AbstractHttpClient
     protected HttpRoutePlanner createHttpRoutePlanner() {
         return new DefaultHttpRoutePlanner(getConnectionManager());
     }



Mime
View raw message