hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r440827 - in /jakarta/httpcomponents/httpcore/trunk/module-main/src: examples/org/apache/http/examples/ main/java/org/apache/http/ main/java/org/apache/http/impl/ main/java/org/apache/http/protocol/
Date Wed, 06 Sep 2006 18:48:31 GMT
Author: olegk
Date: Wed Sep  6 11:48:30 2006
New Revision: 440827

URL: http://svn.apache.org/viewvc?view=rev&rev=440827
Log:
[HTTPCORE-11] Provide generic server and client connection primitives that can work with arbitrary
HTTP data receivers and transmitters
Changelog:
(1) HttpRequestExecutor no longer attempts to re-open the connection in case of an I/O failure
(2) No more request retry code in HttpRequestExecutor
(3) No more HttpProxyConnection interface 

Removed:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpProxyConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpProxyConnection.java
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java?view=diff&rev=440827&r1=440826&r2=440827
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java
Wed Sep  6 11:48:30 2006
@@ -43,6 +43,8 @@
 import org.apache.http.message.HttpGet;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpExecutionContext;
 import org.apache.http.protocol.HttpRequestExecutor;
 import org.apache.http.protocol.RequestConnControl;
 import org.apache.http.protocol.RequestContent;
@@ -83,6 +85,8 @@
         httpexecutor.addInterceptor(new RequestUserAgent());
         httpexecutor.addInterceptor(new RequestExpectContinue());
         
+        HttpContext context = new HttpExecutionContext(null);
+        
         HttpHost host = new HttpHost("localhost", 8080);
         HttpClientConnection conn = new DefaultHttpClientConnection(host);
         try {
@@ -95,9 +99,12 @@
             ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();
             
             for (int i = 0; i < targets.length; i++) {
+                if (!conn.isOpen()) {
+                    conn.open(params);
+                }
                 HttpGet request = new HttpGet(targets[i]);
                 System.out.println(">> Request URI: " + request.getRequestLine().getUri());
-                HttpResponse response = httpexecutor.execute(request, conn);
+                HttpResponse response = httpexecutor.execute(request, conn, context);
                 System.out.println("<< Response: " + response.getStatusLine());
                 System.out.println(EntityUtils.toString(response.getEntity()));
                 System.out.println("==============");

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java?view=diff&rev=440827&r1=440826&r2=440827
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java
Wed Sep  6 11:48:30 2006
@@ -49,6 +49,8 @@
 import org.apache.http.message.HttpPost;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpExecutionContext;
 import org.apache.http.protocol.HttpRequestExecutor;
 import org.apache.http.protocol.RequestConnControl;
 import org.apache.http.protocol.RequestContent;
@@ -89,6 +91,8 @@
         httpexecutor.addInterceptor(new RequestUserAgent());
         httpexecutor.addInterceptor(new RequestExpectContinue());
         
+        HttpContext context = new HttpExecutionContext(null);
+        
         HttpHost host = new HttpHost("localhost", 8080);
         HttpClientConnection conn = new DefaultHttpClientConnection(host);
         try {
@@ -107,10 +111,13 @@
             ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();
             
             for (int i = 0; i < requestBodies.length; i++) {
+                if (!conn.isOpen()) {
+                    conn.open(params);
+                }
                 HttpPost request = new HttpPost("/servlets-examples/servlet/RequestInfoExample");
                 request.setEntity(requestBodies[i]);
                 System.out.println(">> Request URI: " + request.getRequestLine().getUri());
-                HttpResponse response = httpexecutor.execute(request, conn);
+                HttpResponse response = httpexecutor.execute(request, conn, context);
                 System.out.println("<< Response: " + response.getStatusLine());
                 System.out.println(EntityUtils.toString(response.getEntity()));
                 System.out.println("==============");

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java?view=diff&rev=440827&r1=440826&r2=440827
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java
Wed Sep  6 11:48:30 2006
@@ -35,12 +35,10 @@
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
-import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 
 /**
@@ -58,41 +56,13 @@
 
     protected static final int WAIT_FOR_CONTINUE_MS = 10000;
 
-    /** The context holding the default context information. */    
-    protected final HttpContext defaultContext;
-    
     private HttpParams params = null;
-    private HttpRequestRetryHandler retryhandler = null;
-
-    /**
-     * Create a new request executor with default context information.
-     * The attributes in the argument context will be made available
-     * in the context used for executing a request.
-     *
-     * @param parentContext     the default context information,
-     *                          or <code>null</code>
-     */    
-    public HttpRequestExecutor(final HttpContext parentContext) {
-        super();
-        this.defaultContext = new HttpExecutionContext(parentContext);
-    }
 
     /**
      * Create a new request executor.
      */
     public HttpRequestExecutor() {
-        this(null);
-    }
-
-    /**
-     * Obtain the default context information.
-     * This is not necessarily the same object passed to the constructor,
-     * but the default context information will be available here.
-     *
-     * @return  the context holding the default context information
-     */
-    public final HttpContext getContext() {
-        return this.defaultContext;
+        super();
     }
 
     /**
@@ -114,25 +84,6 @@
     }
 
     /**
-     * Obtain the retry handler.
-     *
-     * @return  the handler deciding whether a request should be retried
-     */
-    public final HttpRequestRetryHandler getRetryHandler() {
-        return this.retryhandler;
-    }
-
-    /**
-     * Set the retry handler.
-     *
-     * @param retryhandler      the handler to decide whether a request
-     *                          should be retried
-     */
-    public final void setRetryHandler(final HttpRequestRetryHandler retryhandler) {
-        this.retryhandler = retryhandler;
-    }
-
-    /**
      * Decide whether a response comes with an entity.
      * The implementation in this class is based on RFC 2616.
      * Unknown methods and response codes are supposed to
@@ -172,7 +123,8 @@
      */    
     public HttpResponse execute(
             final HttpRequest request,
-            final HttpClientConnection conn) 
+            final HttpClientConnection conn,
+            final HttpContext context) 
                 throws IOException, HttpException {
         if (request == null) {
             throw new IllegalArgumentException("HTTP request may not be null");
@@ -180,53 +132,32 @@
         if (conn == null) {
             throw new IllegalArgumentException("Client connection may not be null");
         }
+        if (context == null) {
+            throw new IllegalArgumentException("HTTP context may not be null");
+        }
 
-        //@@@ behavior if proxying - set real target or proxy, or both?
-        this.defaultContext.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST,
-                conn.getTargetHost());
-        this.defaultContext.setAttribute(HttpExecutionContext.HTTP_CONNECTION, 
-                conn);
-        
-        doPrepareRequest(request, this.defaultContext);
-
-        this.defaultContext.setAttribute(HttpExecutionContext.HTTP_REQUEST, 
-                request);
+        context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, conn.getTargetHost());
+        context.setAttribute(HttpExecutionContext.HTTP_CONNECTION, conn);
+        context.setAttribute(HttpExecutionContext.HTTP_REQUEST, request);
         
-        HttpResponse response = null;
-        // loop until the method is successfully processed, the retryHandler 
-        // returns false or a non-recoverable exception is thrown
-        for (int execCount = 0; ; execCount++) {
-            try {
-                doEstablishConnection(conn, conn.getTargetHost(),
-                                      request.getParams());
-                response = doSendRequest(request, conn, this.defaultContext);
-                if (response == null) {
-                    response = doReceiveResponse(request, conn,
-                                                 this.defaultContext);
-                }
-                // exit retry loop
-                break;
-            } catch (IOException ex) {
-                conn.close();
-                if (this.retryhandler == null) {
-                    throw ex;
-                }
-                if (!this.retryhandler.retryRequest(ex, execCount, null)) {
-                    throw ex;
-                }
-            } catch (HttpException ex) {
-                conn.close();
-                throw ex;
-            } catch (RuntimeException ex) {
-                conn.close();
-                throw ex;
+        try {
+            doPrepareRequest(request, context);
+            HttpResponse response = doSendRequest(request, conn, context);
+            if (response == null) {
+                response = doReceiveResponse(request, conn, context);
             }
+            doFinishResponse(response, context);
+            return response;
+        } catch (IOException ex) {
+            conn.close();
+            throw ex;
+        } catch (HttpException ex) {
+            conn.close();
+            throw ex;
+        } catch (RuntimeException ex) {
+            conn.close();
+            throw ex;
         }
-
-        doFinishResponse(response, this.defaultContext);
-
-        return response;
-
     }
 
     /**
@@ -251,55 +182,6 @@
         // link default parameters
         request.getParams().setDefaults(this.params);
         preprocessRequest(request, context);
-    }
-
-    /**
-     * Establish a connection with the target host.
-     *
-     * @param conn      the HTTP connection
-     * @param target    the target host for the request, or
-     *                  <code>null</code> to send to the host already
-     *                  set as the connection target
-     *
-     * @throws HttpException      in case of a problem
-     * @throws IOException        in case of an IO problem
-     */
-    protected void doEstablishConnection(
-            final HttpClientConnection conn,
-            final HttpHost target,
-            final HttpParams params)
-                throws HttpException, IOException {
-        if (conn == null) {
-            throw new IllegalArgumentException("HTTP connection may not be null");
-        }
-        if (target == null) {
-            throw new IllegalArgumentException("Target host may not be null");
-        }
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
-        // make sure the connection is open and points to the target host
-        if ((target == null) || target.equals(conn.getTargetHost())) {
-            // host and port ok, check whether connection needs to be opened
-            if (HttpConnectionParams.isStaleCheckingEnabled(params)) {
-                if (conn.isOpen() && conn.isStale()) {
-                    conn.close();
-                }
-            }
-            if (!conn.isOpen()) {
-                conn.open(params);
-                //TODO: Implement secure tunnelling (@@@ HttpRequestExecutor) 
-            }
-
-        } else {
-            // wrong target, point connection to target
-            if (conn.isOpen()) {
-                conn.close();
-            }
-            conn.setTargetHost(target);
-            conn.open(params);
-
-        } // if connection points to target else        
     }
 
     /**



Mime
View raw message