hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r449426 - in /jakarta/httpcomponents/httpcore/trunk: module-main/src/examples/org/apache/http/examples/ module-main/src/main/java/org/apache/http/ module-main/src/main/java/org/apache/http/impl/ src/contrib/org/apache/http/contrib/benchmark...
Date Sun, 24 Sep 2006 16:30:00 GMT
Author: olegk
Date: Sun Sep 24 09:29:59 2006
New Revision: 449426

URL: http://svn.apache.org/viewvc?view=rev&rev=449426
Log:
[HTTPCORE-8] refactor HttpClientConnection and HttpProxyConnection

Changelog:
----------
* HttpCore: HttpClientConnection#open() method is no more
* HttpAsync: Added HttpAsyncClientConnection interface, which extends HttpClientConnection
and preserves the semantics of HttpClientConnection that existed before the changes to the
interface

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/HttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java
    jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java
    jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.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=449426&r1=449425&r2=449426
==============================================================================
--- 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
Sun Sep 24 09:29:59 2006
@@ -29,8 +29,9 @@
 
 package org.apache.http.examples;
 
+import java.net.Socket;
+
 import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
@@ -88,7 +89,7 @@
         HttpContext context = new HttpExecutionContext(null);
         
         HttpHost host = new HttpHost("localhost", 8080);
-        HttpClientConnection conn = new DefaultHttpClientConnection(host);
+        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
         try {
             
             String[] targets = {
@@ -100,7 +101,9 @@
             
             for (int i = 0; i < targets.length; i++) {
                 if (!conn.isOpen()) {
-                    conn.open(params);
+                    Socket socket = socketfactory.createSocket(
+                            host.getHostName(), host.getPort(), null, 0, params);
+                    conn.bind(socket, host, params);
                 }
                 HttpGet request = new HttpGet(targets[i]);
                 System.out.println(">> Request URI: " + request.getRequestLine().getUri());

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=449426&r1=449425&r2=449426
==============================================================================
--- 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
Sun Sep 24 09:29:59 2006
@@ -30,9 +30,9 @@
 package org.apache.http.examples;
 
 import java.io.ByteArrayInputStream;
+import java.net.Socket;
 
 import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
@@ -94,7 +94,7 @@
         HttpContext context = new HttpExecutionContext(null);
         
         HttpHost host = new HttpHost("localhost", 8080);
-        HttpClientConnection conn = new DefaultHttpClientConnection(host);
+        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
         try {
             
             HttpEntity[] requestBodies = {
@@ -112,7 +112,9 @@
             
             for (int i = 0; i < requestBodies.length; i++) {
                 if (!conn.isOpen()) {
-                    conn.open(params);
+                    Socket socket = socketfactory.createSocket(
+                            host.getHostName(), host.getPort(), null, 0, params);
+                    conn.bind(socket, host, params);
                 }
                 HttpPost request = new HttpPost("/servlets-examples/servlet/RequestInfoExample");
                 request.setEntity(requestBodies[i]);

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java?view=diff&rev=449426&r1=449425&r2=449426
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HttpClientConnection.java
Sun Sep 24 09:29:59 2006
@@ -55,15 +55,6 @@
     HttpHost getTargetHost();
     
     /**
-     * Opens the connection. Implementations may use additional settings from
-     * the HttpParams hierarchy.
-     * 
-     * @param params the parameters in effect for this connection.
-     * @throws IOException
-     */
-    void open(HttpParams params) throws IOException;
-    
-    /**
      * Checks if response data is available from the connection. May wait for
      * the specified time until some data becomes available. Note that some
      * implementations may completely ignore the timeout parameter.

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java?view=diff&rev=449426&r1=449425&r2=449426
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
Sun Sep 24 09:29:59 2006
@@ -30,7 +30,6 @@
 package org.apache.http.impl;
 
 import java.io.IOException;
-import java.net.InetAddress;
 import java.net.Socket;
 
 import org.apache.http.HttpHost;
@@ -40,7 +39,6 @@
 import org.apache.http.impl.io.SocketHttpDataTransmitter;
 import org.apache.http.io.HttpDataReceiver;
 import org.apache.http.io.HttpDataTransmitter;
-import org.apache.http.io.SocketFactory;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 
@@ -56,23 +54,12 @@
 public class DefaultHttpClientConnection extends AbstractHttpClientConnection {
 
     private HttpHost targethost = null;
-    private InetAddress localAddress = null;
 
     protected volatile boolean open;
     protected Socket socket = null;
     
-    public DefaultHttpClientConnection(final HttpHost targethost, final InetAddress localAddress)
{
-        super();
-        this.targethost = targethost;
-        this.localAddress = localAddress;
-    }
-    
-    public DefaultHttpClientConnection(final HttpHost targethost) {
-        this(targethost, null);
-    }
-    
     public DefaultHttpClientConnection() {
-        this(null, null);
+        super();
     }
     
     protected void assertNotOpen() {
@@ -87,26 +74,16 @@
         }
     }
 
-    public void open(final HttpParams params) throws IOException {
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
-        assertNotOpen();
-        if (this.targethost == null) {
-        	throw new IllegalStateException("Target host not specified");
-        }
-        SocketFactory socketfactory = this.targethost.getScheme().getSocketFactory();
-        Socket socket = socketfactory.createSocket(
-                this.targethost.getHostName(), this.targethost.getPort(), 
-                this.localAddress, 0, 
-                params);
-        bind(socket, params);
-    }
-    
-    protected void bind(final Socket socket, final HttpParams params) throws IOException
{
+    public void bind(
+            final Socket socket, 
+            final HttpHost targethost, 
+            final HttpParams params) throws IOException {
         if (socket == null) {
             throw new IllegalArgumentException("Socket may not be null");
         }
+        if (targethost == null) {
+            throw new IllegalArgumentException("Target host may not be null");
+        }
         if (params == null) {
             throw new IllegalArgumentException("HTTP parameters may not be null");
         }
@@ -121,6 +98,7 @@
         }
 
         this.socket = socket;
+        this.targethost = targethost;
         
         int buffersize = HttpConnectionParams.getSocketBufferSize(params);
         HttpDataTransmitter transmitter = new SocketHttpDataTransmitter(socket, buffersize);
@@ -139,23 +117,6 @@
 
     public HttpHost getTargetHost() {
         return this.targethost;
-    }
-    
-    public InetAddress getLocalAddress() {
-        return this.localAddress;
-    }
-    
-    public void setTargetHost(final HttpHost targethost) {
-        if (targethost == null) {
-            throw new IllegalArgumentException("Target host may not be null");
-        }
-        assertNotOpen();
-        this.targethost = targethost;
-    }
-
-    public void setLocalAddress(final InetAddress localAddress) {
-        assertNotOpen();
-        this.localAddress = localAddress;
     }
     
     public boolean isOpen() {

Modified: jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java?view=diff&rev=449426&r1=449425&r2=449426
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java
Sun Sep 24 09:29:59 2006
@@ -30,16 +30,19 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.Socket;
 import java.util.Iterator;
 
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.Header;
-import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpClientConnection;
+import org.apache.http.io.SocketFactory;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
@@ -92,17 +95,22 @@
     
     public Stats execute(
             final HttpRequest request, 
-            final HttpClientConnection conn, 
+            final HttpHost targetHost, 
             int count,
             boolean keepalive) throws HttpException {
         HttpResponse response = null;
+        DefaultHttpClientConnection conn = new DefaultHttpClientConnection(); 
         Stats stats = new Stats();
         stats.start();
         for (int i = 0; i < count; i++) {
             try {
                 resetHeader(request);
                 if (!conn.isOpen()) {
-                    conn.open(this.params);
+                    SocketFactory socketfactory = targetHost.getScheme().getSocketFactory();
+                    Socket socket = socketfactory.createSocket(
+                            targetHost.getHostName(), targetHost.getPort(), 
+                            null, 0, params);
+                    conn.bind(socket, targetHost, params);
                 }
                 response = this.httpexecutor.execute(request, conn, this.context);
                 if (this.verbosity >= 3) {

Modified: jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java?view=diff&rev=449426&r1=449425&r2=449426
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/benchmark/HttpBenchmark.java
Sun Sep 24 09:29:59 2006
@@ -43,7 +43,6 @@
 import org.apache.http.HttpVersion;
 import org.apache.http.Scheme;
 import org.apache.http.entity.FileEntity;
-import org.apache.http.impl.DefaultHttpClientConnection;
 import org.apache.http.impl.DefaultHttpParams;
 import org.apache.http.impl.io.PlainSocketFactory;
 import org.apache.http.impl.io.SSLSocketFactory;
@@ -186,7 +185,6 @@
                 url.getHost(), 
                 url.getPort(), 
                 Scheme.getScheme(url.getProtocol()));
-        DefaultHttpClientConnection conn = new DefaultHttpClientConnection(host);
         
         // Prepare request
         HttpRequest request = null;
@@ -235,12 +233,7 @@
         BenchmarkWorker worker = new BenchmarkWorker(params, verbosity);
         
         // Execute
-        Stats stats = null;
-        try {
-            stats = worker.execute(request, conn, num, keepAlive);
-        } finally {
-            conn.close();
-        }
+        Stats stats = worker.execute(request, host, num, keepAlive);
         
         // Show the results
         float totalTimeSec = (float)stats.getDuration() / 1000;

Modified: jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java?view=diff&rev=449426&r1=449425&r2=449426
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
Sun Sep 24 09:29:59 2006
@@ -28,14 +28,17 @@
  */
 package org.apache.http.contrib.spring;
 
+import java.net.Socket;
+
 import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestFactory;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.Scheme;
+import org.apache.http.impl.DefaultHttpClientConnection;
+import org.apache.http.io.SocketFactory;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HttpContext;
@@ -71,12 +74,15 @@
         HttpContext context = new HttpExecutionContext(null);
         
         HttpRequestFactory requestfactory = (HttpRequestFactory) beanfactory.getBean("http-request-factory");
-        HttpClientConnection conn = (HttpClientConnection) beanfactory.getBean("http-connection");
+        DefaultHttpClientConnection conn = (DefaultHttpClientConnection) beanfactory.getBean("http-connection");
         ConnectionReuseStrategy connStrategy = (ConnectionReuseStrategy) beanfactory.getBean("conn-reuse-strategy");
-        conn.setTargetHost(host);
         try {
             if (!conn.isOpen()) {
-                conn.open(params);
+                SocketFactory socketfactory = host.getScheme().getSocketFactory();
+                Socket socket = socketfactory.createSocket(
+                        host.getHostName(), host.getPort(), 
+                        null, 0, params);
+                conn.bind(socket, host, params);
             }
             HttpRequest request1 = requestfactory.newHttpRequest("GET", "/");
             HttpResponse response1 = httpexec.execute(request1, conn, context);
@@ -90,7 +96,11 @@
                 System.out.println("Connection closed...");
             }
             if (!conn.isOpen()) {
-                conn.open(params);
+                SocketFactory socketfactory = host.getScheme().getSocketFactory();
+                Socket socket = socketfactory.createSocket(
+                        host.getHostName(), host.getPort(), 
+                        null, 0, params);
+                conn.bind(socket, host, params);
             }
             HttpRequest request2 = requestfactory.newHttpRequest("GET", "/stuff");
             HttpResponse response2 = httpexec.execute(request2, conn, context);



Mime
View raw message