[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpcomponents-commits
Subject:    svn commit: r559874 - in /jakarta/httpcomponents/httpclient/trunk: ./
From:       rolandw () apache ! org
Date:       2007-07-26 16:29:07
Message-ID: 20070726162907.EF5E01A981D () eris ! apache ! org
[Download RAW message or body]

Author: rolandw
Date: Thu Jul 26 09:29:05 2007
New Revision: 559874

URL: http://svn.apache.org/viewvc?view=rev&rev=559874
Log:
HTTPCLIENT-669: contributed by Andrea Selva, reviewd by Roland Weber

Added:
    jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpRoutePlanner.java \
(with props)  jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpRoutePlanner.java \
(with props) Modified:
    jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    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/DefaultHttpClient.java


Modified: jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?view=diff&rev=559874&r1=559873&r2=559874
 ==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Thu Jul 26 09:29:05 \
2007 @@ -1,5 +1,8 @@
 Changes since release 4.0 Alpha 1
 
+* [HTTPCLIENT-669] new HttpRoutePlanner interface and implementation
+  Contributed by Andrea Selva <selva.andre at gmail.com>
+
 * [HTTPCLIENT-653] detached connection wrapper no longer prevents
   garbage collection of ThreadSafeClientConnManager
   Contributed by Roland Weber <rolandw at apache.org>

Added: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpRoutePlanner.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpRoutePlanner.java?view=auto&rev=559874
 ==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpRoutePlanner.java \
                (added)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpRoutePlanner.java \
Thu Jul 26 09:29:05 2007 @@ -0,0 +1,69 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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.conn;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.protocol.HttpContext;
+
+
+
+/**
+ * Encapsulates logic to compute a {@link HttpRoute} to a target host.
+ * Implementations may for example be based on parameters, or on the
+ * standard Java system properties.
+ */
+public interface HttpRoutePlanner {
+    
+    /**
+     * Determines the route for a 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 subsequent execution.
+     *                  Implementations may accept <code>null</code>.
+     *
+     * @return  the route that the request should take
+     *
+     * @throws HttpException    in case of a problem
+     */        
+    public HttpRoute determineRoute(HttpHost target,
+                                    HttpRequest request,
+                                    HttpContext context)
+        throws HttpException
+        ;
+    
+}

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpRoutePlanner.java
                
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpRoutePlanner.java
                
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpRoutePlanner.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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-clien \
t/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java?view=diff&rev=559874&r1=559873&r2=559874
 ==============================================================================
--- 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 Jul 26 09:29:05 2007 @@ -53,6 +53,7 @@
 import org.apache.http.client.RoutedRequest;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.HttpRoutePlanner;
 import org.apache.http.cookie.CookieSpecRegistry;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.BasicHttpProcessor;
@@ -113,6 +114,10 @@
 
     /** The credentials provider. */
     private CredentialsProvider credsProvider;
+    
+    /** The HttpRoutePlanner object. */
+    private HttpRoutePlanner routePlanner;
+
 
     /**
      * Creates a new HTTP client.
@@ -127,7 +132,6 @@
         connManager          = conman;
     } // constructor
 
-
     protected abstract HttpParams createHttpParams();
 
     
@@ -165,7 +169,23 @@
     
     
     protected abstract void populateContext(HttpContext context);
+    
+    
+    protected abstract HttpRoutePlanner createHttpRoutePlanner();
 
+    
+    public synchronized final HttpRoutePlanner getRoutePlanner() {
+        if (this.routePlanner == null) {
+            this.routePlanner = createHttpRoutePlanner();
+        }
+        return this.routePlanner;
+    }
+
+
+    public synchronized void setRoutePlanner(final HttpRoutePlanner routePlanner) {
+        this.routePlanner = routePlanner;
+    }
+    
     
     // non-javadoc, see interface HttpClient
     public synchronized final HttpParams getParams() {

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-clien \
t/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java?view=diff&rev=559874&r1=559873&r2=559874
 ==============================================================================
--- 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 Jul 26 09:29:05 2007 @@ -54,6 +54,7 @@
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.ClientConnectionManagerFactory;
 import org.apache.http.conn.HttpRoute;
+import org.apache.http.conn.HttpRoutePlanner;
 import org.apache.http.conn.PlainSocketFactory;
 import org.apache.http.conn.Scheme;
 import org.apache.http.conn.SchemeRegistry;
@@ -62,6 +63,7 @@
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.auth.BasicSchemeFactory;
 import org.apache.http.impl.auth.DigestSchemeFactory;
+import org.apache.http.impl.client.DefaultHttpRoutePlanner; //@@@ move to conn
 import org.apache.http.impl.conn.SingleClientConnManager;
 import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
 import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
@@ -109,8 +111,8 @@
             final HttpParams params) {
         super(conman, params);
     }
-
     
+       
     public DefaultHttpClient(final HttpParams params) {
         super(null, params);
     }
@@ -280,30 +282,23 @@
 
         if (target == null) {
             target = (HttpHost) request.getParams().getParameter(
-                    HttpClientParams.DEFAULT_HOST);
+                HttpClientParams.DEFAULT_HOST);
         }
         if (target == null) {
             throw new IllegalStateException
-                ("Target host must not be null.");
+                ("Target host must not be null, or set in parameters.");
         }
 
-        HttpHost proxy = (HttpHost) request.getParams().getParameter(
-                HttpClientParams.DEFAULT_PROXY);
+        HttpRoute route = getRoutePlanner()
+            .determineRoute(target, request, context);
 
-        Scheme schm = getConnectionManager().getSchemeRegistry().
-            getScheme(target.getSchemeName());
-        // as it is typically used for TLS/SSL, we assume that
-        // a layered scheme implies a secure connection
-        boolean secure = schm.isLayered();
-        
-        HttpRoute route;
-        if (proxy == null) {
-            route = new HttpRoute(target, null, secure);
-        } else {
-            route = new HttpRoute(target, null, proxy, secure);
-        }
         return new RoutedRequest.Impl(request, route);
     }
-
-
+    
+    
+    //non-javadoc, see base class AbstractHttpClient
+    protected HttpRoutePlanner createHttpRoutePlanner() {
+        return new DefaultHttpRoutePlanner(getConnectionManager());
+    }
+    
 } // class DefaultHttpClient

Added: jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpRoutePlanner.java
                
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/module-clien \
t/src/main/java/org/apache/http/impl/client/DefaultHttpRoutePlanner.java?view=auto&rev=559874
 ==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpRoutePlanner.java \
                (added)
+++ jakarta/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultHttpRoutePlanner.java \
Thu Jul 26 09:29:05 2007 @@ -0,0 +1,104 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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 org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.protocol.HttpContext;
+
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.HttpRoute;
+import org.apache.http.conn.HttpRoutePlanner;
+import org.apache.http.conn.Scheme;
+
+//@@@ move this class to conn when this dependency is gone:
+import org.apache.http.client.params.HttpClientParams; //@@@
+
+
+/**
+ * Default implementation of an {@link HttpRoutePlanner}.
+ * This implementation is based on parameters.
+ * It will not make use of any Java system properties.
+ */
+public class DefaultHttpRoutePlanner implements HttpRoutePlanner {
+    
+    private ClientConnectionManager connectionManager;
+    
+    public DefaultHttpRoutePlanner(ClientConnectionManager aConnManager) {
+        setConnectionManager(aConnManager);
+    }
+
+
+    // default constructor
+
+    
+    public void setConnectionManager(ClientConnectionManager aConnManager) {
+        this.connectionManager = aConnManager;
+    }
+
+
+    // non-javadoc, see interface HttpRoutePlanner
+    public HttpRoute determineRoute(HttpHost target,
+                                    HttpRequest request,
+                                    HttpContext context)
+        throws HttpException {
+
+        if (target == null) {
+            throw new IllegalStateException
+                ("Target host must not be null.");
+        }
+        if (request == null) {
+            throw new IllegalStateException
+                ("Request must not be null.");
+        }
+
+        HttpHost proxy = (HttpHost)
+            request.getParams().getParameter(HttpClientParams.DEFAULT_PROXY);
+
+        Scheme schm = this.connectionManager.getSchemeRegistry().
+            getScheme(target.getSchemeName());
+        // as it is typically used for TLS/SSL, we assume that
+        // a layered scheme implies a secure connection
+        boolean secure = schm.isLayered();
+
+        HttpRoute route = null;
+        if (proxy == null) {
+            route = new HttpRoute(target, null, secure);
+        } else {
+            route = new HttpRoute(target, null, proxy, secure);
+        }
+        return route;
+    }
+    
+    
+}

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

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

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic