hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r537141 - in /jakarta/httpcomponents/httpclient/trunk/src: examples/org/apache/http/examples/client/ java/org/apache/http/client/ java/org/apache/http/client/methods/ java/org/apache/http/client/protocol/ java/org/apache/http/impl/client/
Date Fri, 11 May 2007 08:59:56 GMT
Author: olegk
Date: Fri May 11 01:59:55 2007
New Revision: 537141

URL: http://svn.apache.org/viewvc?view=rev&rev=537141
Log:
* Changed HttpClient interface to take a single HttpUriRequest parameter instead HttpHost
/ HttpRequest pair
* Fixed bug in the RequestAddCookies protocol interceptor

Modified:
    jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
    jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/MethodAbort.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpClient.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpRequestBase.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/protocol/RequestAddCookies.java
    jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/impl/client/AbstractHttpClient.java

Modified: jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java?view=diff&rev=537141&r1=537140&r2=537141
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
Fri May 11 01:59:55 2007
@@ -39,7 +39,9 @@
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.RoutedRequest;
 import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.HttpRoute;
 import org.apache.http.conn.PlainSocketFactory;
 import org.apache.http.conn.Scheme;
 import org.apache.http.conn.SchemeRegistry;
@@ -96,10 +98,13 @@
 
         HttpRequest req = createRequest();
 
+        final HttpRoute route = new HttpRoute(target, null, false);
+        final RoutedRequest roureq = new RoutedRequest.Impl(req, route);
+        
         System.out.println("executing request to " + target);
         HttpEntity entity = null;
         try {
-            HttpResponse rsp = client.execute(target, req);
+            HttpResponse rsp = client.execute(roureq, null);
             entity = rsp.getEntity();
 
             System.out.println("----------------------------------------");

Modified: jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/MethodAbort.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/MethodAbort.java?view=diff&rev=537141&r1=537140&r2=537141
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/MethodAbort.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/examples/org/apache/http/examples/client/MethodAbort.java
Fri May 11 01:59:55 2007
@@ -32,7 +32,6 @@
 package org.apache.http.examples.client;
 
 import org.apache.http.HttpEntity;
-import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.HttpClient;
@@ -62,12 +61,10 @@
         
         HttpClient httpclient = new DefaultHttpClient(params);
 
-        HttpHost target = new HttpHost("www.apache.org", 80, "http");
+        HttpGet httpget = new HttpGet("http://www.apache.org/"); 
 
-        HttpGet httpget = new HttpGet("/"); 
-
-        System.out.println("executing request to " + target);
-        HttpResponse response = httpclient.execute(target, httpget);
+        System.out.println("executing request " + httpget.getURI());
+        HttpResponse response = httpclient.execute(httpget);
         HttpEntity entity = response.getEntity();
 
         System.out.println("----------------------------------------");

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpClient.java?view=diff&rev=537141&r1=537140&r2=537141
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpClient.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/HttpClient.java
Fri May 11 01:59:55 2007
@@ -39,6 +39,7 @@
 import org.apache.http.HttpException;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
 
 
@@ -94,14 +95,11 @@
         ;
 
     /**
-     * Executes a request for the given target using the
-     * {@link #getContext default context}.
-     * Same as {@link #execute(HttpHost,HttpRequest,HttpContext)
-     *          client.execute(target, request, client.getContext())},
+     * Executes a request using the {@link #getContext default context}.
+     * Same as {@link #execute(HttpUriRequest,HttpContext)
+     *          client.execute(request, client.getContext())},
      * see there for details.
      *
-     * @param target    the target host for the request.
-     *                  Some implementations may accept <code>null</code>.
      * @param request   the request to execute
      *
      * @return  the response to the request
@@ -110,17 +108,15 @@
      * @throws IOException      in case of an IO problem
      * <br/><i @@@>timeout exceptions?</i>
      */
-    HttpResponse execute(HttpHost target, HttpRequest request)
+    HttpResponse execute(HttpUriRequest request)
         throws HttpException, IOException
         ;
 
 
     /**
-     * Executes a request for the given target using the given context.
+     * Executes a request using the given context.
      * The route to the target will be determined by the HTTP client.
      *
-     * @param target    the target host for the request.
-     *                  Some implementations may accept <code>null</code>.
      * @param request   the request to execute
      * @param context   the context to use for the execution, or
      *                  <code>null</code> to use the
@@ -136,8 +132,7 @@
      * @throws IOException      in case of an IO problem
      * <br/><i @@@>timeout exceptions?</i>
      */
-    HttpResponse execute(HttpHost target, HttpRequest request,
-                         HttpContext context)
+    HttpResponse execute(HttpUriRequest request, HttpContext context)
         throws HttpException, IOException
         ;
 

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpRequestBase.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpRequestBase.java?view=diff&rev=537141&r1=537140&r2=537141
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpRequestBase.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/methods/HttpRequestBase.java
Fri May 11 01:59:55 2007
@@ -34,7 +34,6 @@
 import java.io.IOException;
 import java.net.URI;
 
-import org.apache.http.HttpRequest;
 import org.apache.http.HttpVersion;
 import org.apache.http.RequestLine;
 import org.apache.http.conn.ConnectionReleaseTrigger;
@@ -52,7 +51,7 @@
  * @since 4.0
  */
 abstract class HttpRequestBase extends AbstractHttpMessage 
-    implements HttpRequest, AbortableHttpRequest {
+    implements HttpUriRequest, AbortableHttpRequest {
     
     private URI uri;
     private ConnectionReleaseTrigger releaseTrigger;

Modified: jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/protocol/RequestAddCookies.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/protocol/RequestAddCookies.java?view=diff&rev=537141&r1=537140&r2=537141
==============================================================================
--- jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/protocol/RequestAddCookies.java
(original)
+++ jakarta/httpcomponents/httpclient/trunk/src/java/org/apache/http/client/protocol/RequestAddCookies.java
Fri May 11 01:59:55 2007
@@ -131,9 +131,15 @@
             }
         }
         
+        String hostName = targetHost.getHostName();
+        int port = targetHost.getPort();
+        if (port < 0) {
+            port = conn.getRemotePort();
+        }
+        
         CookieOrigin cookieOrigin = new CookieOrigin(
-                targetHost.getHostName(), 
-                targetHost.getPort(), 
+                hostName, 
+                port, 
                 requestURI.getPath(),
                 conn.isSecure());
         

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=537141&r1=537140&r2=537141
==============================================================================
--- 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
Fri May 11 01:59:55 2007
@@ -32,6 +32,7 @@
 package org.apache.http.impl.client;
 
 import java.io.IOException;
+import java.net.URI;
 import java.util.List;
 
 import org.apache.http.ConnectionReuseStrategy;
@@ -47,6 +48,7 @@
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.client.HttpState;
 import org.apache.http.client.RoutedRequest;
+import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.cookie.CookieSpecRegistry;
 import org.apache.http.params.HttpParams;
@@ -304,11 +306,9 @@
 
 
     /**
-     * Maps to {@link #execute(HttpHost,HttpRequest,HttpContext)
-     *                 execute(target, request, context)}.
+     * Maps to {@link #execute(HttpUriRequest,HttpContext)
+     *                 execute(request, context)}.
      *
-     * @param target    the target host for the request.
-     *                  Some implementations may accept <code>null</code>.
      * @param request   the request to execute
      *
      * @return  the response to the request
@@ -316,10 +316,10 @@
      * @throws HttpException    in case of a problem
      * @throws IOException      in case of an IO problem
      */
-    public final HttpResponse execute(HttpHost target, HttpRequest request)
+    public final HttpResponse execute(HttpUriRequest request)
         throws HttpException, IOException {
 
-        return execute(target, request, null);
+        return execute(request, null);
     }
 
 
@@ -332,17 +332,26 @@
      *                  Some implementations may accept <code>null</code>.
      * @param request   the request to execute
      */
-    public final HttpResponse execute(HttpHost target, HttpRequest request,
-                                      HttpContext context)
+    public final HttpResponse execute(HttpUriRequest request, HttpContext context)
         throws HttpException, IOException {
 
         if (request == null) {
             throw new IllegalArgumentException
                 ("Request must not be null.");
         }
+
         // A null target may be acceptable if there is a default target.
         // Otherwise, the null target is detected in determineRoute().
-
+        HttpHost target = null;
+        
+        URI requestURI = request.getURI();
+        if (requestURI.isAbsolute()) {
+            target = new HttpHost(
+                    requestURI.getHost(), 
+                    requestURI.getPort(), 
+                    requestURI.getScheme());
+        }
+        
         synchronized (this) {
             if (context == null) {
                 context = new HttpExecutionContext(getContext());



Mime
View raw message