hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r438468 - in /jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http: impl/ io/
Date Wed, 30 Aug 2006 11:26:35 GMT
Author: olegk
Date: Wed Aug 30 04:26:34 2006
New Revision: 438468

URL: http://svn.apache.org/viewvc?rev=438468&view=rev
Log:
[HTTPCORE-11] Added generic server and client connection primitives that can work with arbitrary
HTTP data receivers and transmitters

Added:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
      - copied, changed from r437389, jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
      - copied, changed from r437389, jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java
Removed:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataReceiverFactory.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/io/HttpDataTransmitterFactory.java
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpConnection.java

Copied: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
(from r437389, 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/AbstractHttpClientConnection.java?p2=jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java&p1=jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java&r1=437389&r2=438468&rev=438468&view=diff
==============================================================================
--- 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/AbstractHttpClientConnection.java
Wed Aug 30 04:26:34 2006
@@ -30,8 +30,6 @@
 package org.apache.http.impl;
 
 import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
 import java.util.Iterator;
 
 import org.apache.http.Header;
@@ -39,7 +37,6 @@
 import org.apache.http.HttpEntity;
 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.HttpResponseFactory;
@@ -48,22 +45,21 @@
 import org.apache.http.StatusLine;
 import org.apache.http.entity.EntityDeserializer;
 import org.apache.http.entity.EntitySerializer;
-import org.apache.http.impl.entity.DefaultEntitySerializer;
-import org.apache.http.impl.entity.DefaultEntityDeserializer;
 import org.apache.http.io.CharArrayBuffer;
-import org.apache.http.io.SocketFactory;
+import org.apache.http.io.HttpDataReceiver;
+import org.apache.http.io.HttpDataTransmitter;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicRequestLine;
 import org.apache.http.message.BasicStatusLine;
 import org.apache.http.message.BufferedHeader;
-import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.util.HeaderUtils;
 
 /**
- * Default implementation of a client-side HTTP connection.
+ * Abstract client-side HTTP connection capable of transmitting and receiving data
+ * using arbitrary {@link HttpDataReceiver} and {@link HttpDataTransmitter}
  *
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
@@ -71,11 +67,8 @@
  * 
  * @since 4.0
  */
-public class DefaultHttpClientConnection 
-        extends AbstractHttpConnection implements HttpClientConnection {
+public abstract class AbstractHttpClientConnection implements HttpClientConnection {
 
-    private HttpHost targethost = null;
-    private InetAddress localAddress = null;
     private int maxHeaderCount = -1;
 
     private final CharArrayBuffer buffer; 
@@ -86,82 +79,53 @@
     private HttpResponseFactory responsefactory = null;
     private EntitySerializer entityserializer = null;
     private EntityDeserializer entitydeserializer = null;
-    
-    public DefaultHttpClientConnection(final HttpHost targethost, final InetAddress localAddress)
{
+    private HttpDataReceiver datareceiver = null;
+    private HttpDataTransmitter datatransmitter = null;
+
+    public AbstractHttpClientConnection() {
         super();
-        this.targethost = targethost;
-        this.localAddress = localAddress;
         this.buffer = new CharArrayBuffer(128);
-        this.responsefactory = new DefaultHttpResponseFactory();
-        this.entityserializer = new DefaultEntitySerializer();
-        this.entitydeserializer = new DefaultEntityDeserializer();
     }
     
-    public DefaultHttpClientConnection(final HttpHost targethost) {
-        this(targethost, null);
-    }
-    
-    public DefaultHttpClientConnection() {
-        this(null, null);
+    protected abstract void assertOpen() throws IllegalStateException;
+
+    protected void setMaxHeaderCount(int maxHeaderCount) {
+        this.maxHeaderCount = maxHeaderCount;
     }
     
-    public void setResponseFactory(final HttpResponseFactory responsefactory) {
+    protected void setResponseFactory(final HttpResponseFactory responsefactory) {
         if (responsefactory == null) {
             throw new IllegalArgumentException("Factory may not be null");
         }
         this.responsefactory = responsefactory;
     }
 
-    public void setEntityDeserializer(final EntityDeserializer entitydeserializer) {
+    protected void setEntityDeserializer(final EntityDeserializer entitydeserializer) {
         if (entitydeserializer == null) {
             throw new IllegalArgumentException("Entity deserializer may not be null");
         }
         this.entitydeserializer = entitydeserializer;
     }
 
-    public void setEntitySerializer(final EntitySerializer entityserializer) {
+    protected void setEntitySerializer(final EntitySerializer entityserializer) {
         if (entityserializer == null) {
             throw new IllegalArgumentException("Entity serializer may not be null");
         }
         this.entityserializer = entityserializer;
     }
 
-    public void open(final HttpParams params) throws IOException {
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
+    protected void setHttpDataReceiver(final HttpDataReceiver datareceiver) {
+        if (datareceiver == null) {
+            throw new IllegalArgumentException("HTTP data receiver 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);
-        this.maxHeaderCount = params.getIntParameter(HttpConnectionParams.MAX_HEADER_COUNT,
-1);
-    }
-    
-    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;
+        this.datareceiver = datareceiver;
     }
 
-    public void setLocalAddress(final InetAddress localAddress) {
-        assertNotOpen();
-        this.localAddress = localAddress;
+    protected void setHttpDataTransmitter(final HttpDataTransmitter datatransmitter) {
+        if (datatransmitter == null) {
+            throw new IllegalArgumentException("HTTP data transmitter may not be null");
+        }
+        this.datatransmitter = datatransmitter;
     }
     
     public boolean isResponseAvailable(int timeout) throws IOException {
@@ -276,16 +240,15 @@
             int i = this.datareceiver.readLine(this.buffer);
             if (i == -1 && count == 0) {
                 // The server just dropped connection on us
-                throw new NoHttpResponseException("The server " + 
-                        this.targethost.getHostName() + " failed to respond");
+                throw new NoHttpResponseException("The target server failed to respond");
             }
             if (startsWithHTTP(this.buffer)) {
                 // Got one
                 break;
             } else if (i == -1 || count >= maxGarbageLines) {
                 // Giving up
-                throw new ProtocolException("The server " + this.targethost.getHostName()
+ 
-                        " failed to respond with a valid HTTP response");
+                throw new ProtocolException("The server failed to respond with a " +
+                        "valid HTTP response");
             }
             count++;
         } while(true);
@@ -301,5 +264,5 @@
         Header[] headers = HeaderUtils.parseHeaders(this.datareceiver, this.maxHeaderCount);
         response.setHeaders(headers);
     }
-    
+
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpConnection.java?rev=438468&r1=438467&r2=438468&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpConnection.java
Wed Aug 30 04:26:34 2006
@@ -36,9 +36,7 @@
 import org.apache.http.impl.io.SocketHttpDataReceiver;
 import org.apache.http.impl.io.SocketHttpDataTransmitter;
 import org.apache.http.io.HttpDataReceiver;
-import org.apache.http.io.HttpDataReceiverFactory;
 import org.apache.http.io.HttpDataTransmitter;
-import org.apache.http.io.HttpDataTransmitterFactory;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 
@@ -63,30 +61,10 @@
     protected HttpDataTransmitter datatransmitter = null;
     protected HttpDataReceiver datareceiver = null;
     
-    /*
-     * Dependent interfaces
-     */
-    private HttpDataTransmitterFactory trxfactory = null; 
-    private HttpDataReceiverFactory rcvfactory = null; 
-    
     protected AbstractHttpConnection() {
         super();
     }
     
-    public void setReceiverFactory(final HttpDataReceiverFactory rcvfactory) {
-        if (rcvfactory == null) {
-            throw new IllegalArgumentException("Factory may not be null");
-        }
-        this.rcvfactory = rcvfactory;
-    }
-    
-    public void setTransmitterFactory(final HttpDataTransmitterFactory trxfactory) {
-        if (trxfactory == null) {
-            throw new IllegalArgumentException("Factory may not be null");
-        }
-        this.trxfactory = trxfactory;
-    }
-
     protected void assertNotOpen() {
         if (this.open) {
             throw new IllegalStateException("Connection is already open");
@@ -118,16 +96,8 @@
         assertNotOpen();
         this.open = true;
         this.socket = socket;
-        if (this.trxfactory != null) {
-            this.datatransmitter = this.trxfactory.create(this.socket); 
-        } else {
-            this.datatransmitter = new SocketHttpDataTransmitter(this.socket, buffersize);
-        }
-        if (this.rcvfactory != null) {
-            this.datareceiver = this.rcvfactory.create(this.socket); 
-        } else {
-            this.datareceiver = new SocketHttpDataReceiver(this.socket, buffersize);
-        }
+        this.datatransmitter = new SocketHttpDataTransmitter(this.socket, buffersize);
+        this.datareceiver = new SocketHttpDataReceiver(this.socket, buffersize);
         this.datatransmitter.reset(params);
         this.datareceiver.reset(params);
     }

Copied: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
(from r437389, jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java?p2=jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java&p1=jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java&r1=437389&r2=438468&rev=438468&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
Wed Aug 30 04:26:34 2006
@@ -30,7 +30,6 @@
 package org.apache.http.impl;
 
 import java.io.IOException;
-import java.net.Socket;
 import java.util.Iterator;
 
 import org.apache.http.ConnectionClosedException;
@@ -45,19 +44,19 @@
 import org.apache.http.RequestLine;
 import org.apache.http.entity.EntityDeserializer;
 import org.apache.http.entity.EntitySerializer;
-import org.apache.http.impl.entity.DefaultEntityDeserializer;
-import org.apache.http.impl.entity.DefaultEntitySerializer;
 import org.apache.http.io.CharArrayBuffer;
+import org.apache.http.io.HttpDataReceiver;
+import org.apache.http.io.HttpDataTransmitter;
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicRequestLine;
 import org.apache.http.message.BasicStatusLine;
 import org.apache.http.message.BufferedHeader;
-import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.HeaderUtils;
 
 /**
- * Default implementation of a server-side HTTP connection.
+ * Abstract server-side HTTP connection capable of transmitting and receiving data
+ * using arbitrary {@link HttpDataReceiver} and {@link HttpDataTransmitter}
  *
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
@@ -65,8 +64,7 @@
  * 
  * @since 4.0
  */
-public class DefaultHttpServerConnection 
-        extends AbstractHttpConnection implements HttpServerConnection {
+public abstract class AbstractHttpServerConnection implements HttpServerConnection {
 
     private int maxHeaderCount = -1;
     
@@ -78,39 +76,53 @@
     private HttpRequestFactory requestfactory = null; 
     private EntitySerializer entityserializer = null;
     private EntityDeserializer entitydeserializer = null;
+    private HttpDataReceiver datareceiver = null;
+    private HttpDataTransmitter datatransmitter = null;
 
-    public DefaultHttpServerConnection() {
+    public AbstractHttpServerConnection() {
         super();
-        this.requestfactory = new DefaultHttpRequestFactory();
         this.buffer = new CharArrayBuffer(128);
-        this.entityserializer = new DefaultEntitySerializer();
-        this.entitydeserializer = new DefaultEntityDeserializer();
     }
     
-    public void setRequestFactory(final HttpRequestFactory requestfactory) {
+    protected abstract void assertOpen() throws IllegalStateException;
+
+    protected void setMaxHeaderCount(int maxHeaderCount) {
+        this.maxHeaderCount = maxHeaderCount;
+    }
+    
+    protected void setRequestFactory(final HttpRequestFactory requestfactory) {
         if (requestfactory == null) {
             throw new IllegalArgumentException("Factory may not be null");
         }
         this.requestfactory = requestfactory;
     }
 
-    public void setEntityDeserializer(final EntityDeserializer entitydeserializer) {
+    protected void setEntityDeserializer(final EntityDeserializer entitydeserializer) {
         if (entitydeserializer == null) {
             throw new IllegalArgumentException("Entity deserializer may not be null");
         }
         this.entitydeserializer = entitydeserializer;
     }
 
-    public void setEntitySerializer(final EntitySerializer entityserializer) {
+    protected void setEntitySerializer(final EntitySerializer entityserializer) {
         if (entityserializer == null) {
             throw new IllegalArgumentException("Entity serializer may not be null");
         }
         this.entityserializer = entityserializer;
     }
 
-    public void bind(final Socket socket, final HttpParams params) throws IOException {
-        super.bind(socket, params);
-        this.maxHeaderCount = params.getIntParameter(HttpConnectionParams.MAX_HEADER_COUNT,
-1);
+    protected void setHttpDataReceiver(final HttpDataReceiver datareceiver) {
+        if (datareceiver == null) {
+            throw new IllegalArgumentException("HTTP data receiver may not be null");
+        }
+        this.datareceiver = datareceiver;
+    }
+
+    protected void setHttpDataTransmitter(final HttpDataTransmitter datatransmitter) {
+        if (datatransmitter == null) {
+            throw new IllegalArgumentException("HTTP data transmitter may not be null");
+        }
+        this.datatransmitter = datatransmitter;
     }
 
     public HttpRequest receiveRequestHeader(final HttpParams params) 



Mime
View raw message