You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2013/07/05 13:47:50 UTC
svn commit: r1499976 - in /httpcomponents/httpcore/trunk:
httpcore-nio/src/main/java/org/apache/http/impl/nio/
httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/
httpcore/src/examples/org/apache/http/examples/
httpcore/src/main/java/org/apache/h...
Author: olegk
Date: Fri Jul 5 11:47:49 2013
New Revision: 1499976
URL: http://svn.apache.org/r1499976
Log:
Extended default connection factories; added sections on blocking and non-blocking connection factories to the 'advanced' chapter of the HttpCore tutorial
Added:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpConnectionFactory.java (with props)
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnectionFactory.java (with props)
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnectionFactory.java (with props)
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java
httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
httpcomponents/httpcore/trunk/src/docbkx/advanced.xml
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java Fri Jul 5 11:47:49 2013
@@ -26,15 +26,18 @@
*/
package org.apache.http.impl.nio;
+import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
import org.apache.http.annotation.Immutable;
import org.apache.http.config.ConnectionConfig;
+import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.ConnSupport;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory;
import org.apache.http.nio.NHttpConnectionFactory;
import org.apache.http.nio.NHttpMessageParserFactory;
+import org.apache.http.nio.NHttpMessageWriterFactory;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.nio.util.HeapByteBufferAllocator;
@@ -53,14 +56,20 @@ import org.apache.http.util.Args;
public class DefaultNHttpClientConnectionFactory
implements NHttpConnectionFactory<DefaultNHttpClientConnection> {
+ public static final DefaultNHttpClientConnectionFactory INSTANCE = new DefaultNHttpClientConnectionFactory();
+
+ private final ContentLengthStrategy incomingContentStrategy;
+ private final ContentLengthStrategy outgoingContentStrategy;
private final NHttpMessageParserFactory<HttpResponse> responseParserFactory;
+ private final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory;
private final ByteBufferAllocator allocator;
private final ConnectionConfig cconfig;
/**
* @deprecated (4.3) use {@link
* DefaultNHttpClientConnectionFactory#DefaultNHttpClientConnectionFactory(
- * NHttpMessageParserFactory, ByteBufferAllocator, ConnectionConfig)}
+ * NHttpMessageParserFactory, NHttpMessageWriterFactory, ByteBufferAllocator,
+ * ConnectionConfig)}
*/
@Deprecated
public DefaultNHttpClientConnectionFactory(
@@ -72,7 +81,10 @@ public class DefaultNHttpClientConnectio
Args.notNull(allocator, "Byte buffer allocator");
Args.notNull(params, "HTTP parameters");
this.allocator = allocator;
+ this.incomingContentStrategy = null;
+ this.outgoingContentStrategy = null;
this.responseParserFactory = new DefaultHttpResponseParserFactory(null, responseFactory);
+ this.requestWriterFactory = null;
this.cconfig = HttpParamConfig.getConnectionConfig(params);
}
@@ -90,21 +102,54 @@ public class DefaultNHttpClientConnectio
* @since 4.3
*/
public DefaultNHttpClientConnectionFactory(
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+ final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
final ByteBufferAllocator allocator,
final ConnectionConfig cconfig) {
super();
- this.allocator = allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE;
- this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
- DefaultHttpResponseParserFactory.INSTANCE;
+ this.incomingContentStrategy = incomingContentStrategy;
+ this.outgoingContentStrategy = outgoingContentStrategy;
+ this.responseParserFactory = responseParserFactory;
+ this.requestWriterFactory = requestWriterFactory;
+ this.allocator = allocator;
this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
}
/**
* @since 4.3
*/
+ public DefaultNHttpClientConnectionFactory(
+ final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+ final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+ final ByteBufferAllocator allocator,
+ final ConnectionConfig cconfig) {
+ this(null, null, responseParserFactory, requestWriterFactory, allocator, cconfig);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public DefaultNHttpClientConnectionFactory(
+ final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+ final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+ final ConnectionConfig cconfig) {
+ this(null, null, responseParserFactory, requestWriterFactory, null, cconfig);
+ }
+
+ /**
+ * @since 4.3
+ */
public DefaultNHttpClientConnectionFactory(final ConnectionConfig cconfig) {
- this(null, null, cconfig);
+ this(null, null, null, null, null, cconfig);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public DefaultNHttpClientConnectionFactory() {
+ this(null, null, null, null, null, null);
}
/**
@@ -128,7 +173,9 @@ public class DefaultNHttpClientConnectio
ConnSupport.createDecoder(this.cconfig),
ConnSupport.createEncoder(this.cconfig),
this.cconfig.getMessageConstraints(),
- null, null, null,
+ this.incomingContentStrategy,
+ this.outgoingContentStrategy,
+ this.requestWriterFactory,
this.responseParserFactory);
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java Fri Jul 5 11:47:49 2013
@@ -28,13 +28,16 @@ package org.apache.http.impl.nio;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestFactory;
+import org.apache.http.HttpResponse;
import org.apache.http.annotation.Immutable;
import org.apache.http.config.ConnectionConfig;
+import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.ConnSupport;
import org.apache.http.impl.DefaultHttpRequestFactory;
import org.apache.http.impl.nio.codecs.DefaultHttpRequestParserFactory;
import org.apache.http.nio.NHttpConnectionFactory;
import org.apache.http.nio.NHttpMessageParserFactory;
+import org.apache.http.nio.NHttpMessageWriterFactory;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.nio.util.HeapByteBufferAllocator;
@@ -53,14 +56,18 @@ import org.apache.http.util.Args;
public class DefaultNHttpServerConnectionFactory
implements NHttpConnectionFactory<DefaultNHttpServerConnection> {
+ private final ContentLengthStrategy incomingContentStrategy;
+ private final ContentLengthStrategy outgoingContentStrategy;
private final NHttpMessageParserFactory<HttpRequest> requestParserFactory;
+ private final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory;
private final ByteBufferAllocator allocator;
private final ConnectionConfig cconfig;
/**
* @deprecated (4.3) use {@link
* DefaultNHttpServerConnectionFactory#DefaultNHttpServerConnectionFactory(
- * ByteBufferAllocator, NHttpMessageParserFactory, ConnectionConfig)}
+ * ByteBufferAllocator, NHttpMessageParserFactory, NHttpMessageWriterFactory,
+ * ConnectionConfig)}
*/
@Deprecated
public DefaultNHttpServerConnectionFactory(
@@ -71,7 +78,10 @@ public class DefaultNHttpServerConnectio
Args.notNull(requestFactory, "HTTP request factory");
Args.notNull(allocator, "Byte buffer allocator");
Args.notNull(params, "HTTP parameters");
+ this.incomingContentStrategy = null;
+ this.outgoingContentStrategy = null;
this.requestParserFactory = new DefaultHttpRequestParserFactory(null, requestFactory);
+ this.responseWriterFactory = null;
this.allocator = allocator;
this.cconfig = HttpParamConfig.getConnectionConfig(params);
}
@@ -101,21 +111,44 @@ public class DefaultNHttpServerConnectio
* @since 4.3
*/
public DefaultNHttpServerConnectionFactory(
- final ByteBufferAllocator allocator,
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
+ final ByteBufferAllocator allocator,
final ConnectionConfig cconfig) {
super();
- this.allocator = allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE;
- this.requestParserFactory = requestParserFactory != null ? requestParserFactory :
- DefaultHttpRequestParserFactory.INSTANCE;
+ this.incomingContentStrategy = incomingContentStrategy;
+ this.outgoingContentStrategy = outgoingContentStrategy;
+ this.requestParserFactory = requestParserFactory;
+ this.responseWriterFactory = responseWriterFactory;
+ this.allocator = allocator;
this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
}
/**
* @since 4.3
*/
+ public DefaultNHttpServerConnectionFactory(
+ final ByteBufferAllocator allocator,
+ final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
+ final ConnectionConfig cconfig) {
+ this(null, null, requestParserFactory, responseWriterFactory, allocator, cconfig);
+ }
+
+ /**
+ * @since 4.3
+ */
public DefaultNHttpServerConnectionFactory(final ConnectionConfig config) {
- this(null, null, config);
+ this(null, null, null, null, null, config);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public DefaultNHttpServerConnectionFactory() {
+ this(null, null, null, null, null, null);
}
public DefaultNHttpServerConnection createConnection(final IOSession session) {
@@ -126,9 +159,10 @@ public class DefaultNHttpServerConnectio
ConnSupport.createDecoder(this.cconfig),
ConnSupport.createEncoder(this.cconfig),
this.cconfig.getMessageConstraints(),
- null, null,
+ this.incomingContentStrategy,
+ this.outgoingContentStrategy,
this.requestParserFactory,
- null);
+ this.responseWriterFactory);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java Fri Jul 5 11:47:49 2013
@@ -28,15 +28,18 @@ package org.apache.http.impl.nio;
import javax.net.ssl.SSLContext;
+import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
import org.apache.http.annotation.Immutable;
import org.apache.http.config.ConnectionConfig;
+import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.ConnSupport;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory;
import org.apache.http.nio.NHttpConnectionFactory;
import org.apache.http.nio.NHttpMessageParserFactory;
+import org.apache.http.nio.NHttpMessageWriterFactory;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.ssl.SSLIOSession;
import org.apache.http.nio.reactor.ssl.SSLMode;
@@ -58,7 +61,12 @@ import org.apache.http.util.Args;
public class SSLNHttpClientConnectionFactory
implements NHttpConnectionFactory<DefaultNHttpClientConnection> {
+ public static final SSLNHttpClientConnectionFactory INSTANCE = new SSLNHttpClientConnectionFactory();
+
+ private final ContentLengthStrategy incomingContentStrategy;
+ private final ContentLengthStrategy outgoingContentStrategy;
private final NHttpMessageParserFactory<HttpResponse> responseParserFactory;
+ private final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory;
private final ByteBufferAllocator allocator;
private final SSLContext sslcontext;
private final SSLSetupHandler sslHandler;
@@ -67,7 +75,8 @@ public class SSLNHttpClientConnectionFac
/**
* @deprecated (4.3) use {@link
* SSLNHttpClientConnectionFactory#SSLNHttpClientConnectionFactory(SSLContext,
- * SSLSetupHandler, NHttpMessageParserFactory, ByteBufferAllocator, ConnectionConfig)}
+ * SSLSetupHandler, NHttpMessageParserFactory, NHttpMessageWriterFactory,
+ * ByteBufferAllocator, ConnectionConfig)}
*/
@Deprecated
public SSLNHttpClientConnectionFactory(
@@ -83,7 +92,10 @@ public class SSLNHttpClientConnectionFac
this.sslcontext = sslcontext;
this.sslHandler = sslHandler;
this.allocator = allocator;
+ this.incomingContentStrategy = null;
+ this.outgoingContentStrategy = null;
this.responseParserFactory = new DefaultHttpResponseParserFactory(null, responseFactory);
+ this.requestWriterFactory = null;
this.cconfig = HttpParamConfig.getConnectionConfig(params);
}
@@ -116,15 +128,20 @@ public class SSLNHttpClientConnectionFac
public SSLNHttpClientConnectionFactory(
final SSLContext sslcontext,
final SSLSetupHandler sslHandler,
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+ final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
final ByteBufferAllocator allocator,
final ConnectionConfig cconfig) {
super();
this.sslcontext = sslcontext;
this.sslHandler = sslHandler;
- this.allocator = allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE;
- this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
- DefaultHttpResponseParserFactory.INSTANCE;
+ this.incomingContentStrategy = incomingContentStrategy;
+ this.outgoingContentStrategy = outgoingContentStrategy;
+ this.responseParserFactory = responseParserFactory;
+ this.requestWriterFactory = requestWriterFactory;
+ this.allocator = allocator;
this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
}
@@ -134,15 +151,49 @@ public class SSLNHttpClientConnectionFac
public SSLNHttpClientConnectionFactory(
final SSLContext sslcontext,
final SSLSetupHandler sslHandler,
+ final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+ final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+ final ByteBufferAllocator allocator,
+ final ConnectionConfig cconfig) {
+ this(sslcontext, sslHandler,
+ null, null, responseParserFactory, requestWriterFactory, allocator, cconfig);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public SSLNHttpClientConnectionFactory(
+ final SSLContext sslcontext,
+ final SSLSetupHandler sslHandler,
+ final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+ final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+ final ConnectionConfig cconfig) {
+ this(sslcontext, sslHandler,
+ null, null, responseParserFactory, requestWriterFactory, null, cconfig);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public SSLNHttpClientConnectionFactory(
+ final SSLContext sslcontext,
+ final SSLSetupHandler sslHandler,
final ConnectionConfig config) {
- this(sslcontext, sslHandler, null, null, config);
+ this(sslcontext, sslHandler, null, null, null, null, null, config);
}
/**
* @since 4.3
*/
public SSLNHttpClientConnectionFactory(final ConnectionConfig config) {
- this(null, null, null, null, config);
+ this(null, null, null, null, null, null, null, config);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public SSLNHttpClientConnectionFactory() {
+ this(null, null, null, null, null, null);
}
private SSLContext getDefaultSSLContext() {
@@ -192,7 +243,9 @@ public class SSLNHttpClientConnectionFac
ConnSupport.createDecoder(this.cconfig),
ConnSupport.createEncoder(this.cconfig),
this.cconfig.getMessageConstraints(),
- null, null, null,
+ this.incomingContentStrategy,
+ this.outgoingContentStrategy,
+ this.requestWriterFactory,
this.responseParserFactory);
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java Fri Jul 5 11:47:49 2013
@@ -30,13 +30,16 @@ import javax.net.ssl.SSLContext;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestFactory;
+import org.apache.http.HttpResponse;
import org.apache.http.annotation.Immutable;
import org.apache.http.config.ConnectionConfig;
+import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.ConnSupport;
import org.apache.http.impl.DefaultHttpRequestFactory;
import org.apache.http.impl.nio.codecs.DefaultHttpRequestParserFactory;
import org.apache.http.nio.NHttpConnectionFactory;
import org.apache.http.nio.NHttpMessageParserFactory;
+import org.apache.http.nio.NHttpMessageWriterFactory;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.ssl.SSLIOSession;
import org.apache.http.nio.reactor.ssl.SSLMode;
@@ -58,16 +61,20 @@ import org.apache.http.util.Args;
public class SSLNHttpServerConnectionFactory
implements NHttpConnectionFactory<DefaultNHttpServerConnection> {
- private final NHttpMessageParserFactory<HttpRequest> requestParserFactory;
- private final ByteBufferAllocator allocator;
private final SSLContext sslcontext;
private final SSLSetupHandler sslHandler;
+ private final ContentLengthStrategy incomingContentStrategy;
+ private final ContentLengthStrategy outgoingContentStrategy;
+ private final NHttpMessageParserFactory<HttpRequest> requestParserFactory;
+ private final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory;
+ private final ByteBufferAllocator allocator;
private final ConnectionConfig cconfig;
/**
* @deprecated (4.3) use {@link
* SSLNHttpServerConnectionFactory#SSLNHttpServerConnectionFactory(SSLContext,
- * SSLSetupHandler, NHttpMessageParserFactory, ByteBufferAllocator, ConnectionConfig)}
+ * SSLSetupHandler, NHttpMessageParserFactory, NHttpMessageWriterFactory,
+ * ByteBufferAllocator, ConnectionConfig)}
*/
@Deprecated
public SSLNHttpServerConnectionFactory(
@@ -82,8 +89,11 @@ public class SSLNHttpServerConnectionFac
Args.notNull(params, "HTTP parameters");
this.sslcontext = sslcontext;
this.sslHandler = sslHandler;
- this.allocator = allocator;
+ this.incomingContentStrategy = null;
+ this.outgoingContentStrategy = null;
this.requestParserFactory = new DefaultHttpRequestParserFactory(null, requestFactory);
+ this.responseWriterFactory = null;
+ this.allocator = allocator;
this.cconfig = HttpParamConfig.getConnectionConfig(params);
}
@@ -116,15 +126,20 @@ public class SSLNHttpServerConnectionFac
public SSLNHttpServerConnectionFactory(
final SSLContext sslcontext,
final SSLSetupHandler sslHandler,
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
final ByteBufferAllocator allocator,
final ConnectionConfig cconfig) {
super();
this.sslcontext = sslcontext;
this.sslHandler = sslHandler;
- this.allocator = allocator != null ? allocator : HeapByteBufferAllocator.INSTANCE;
- this.requestParserFactory = requestParserFactory != null ? requestParserFactory :
- DefaultHttpRequestParserFactory.INSTANCE;
+ this.incomingContentStrategy = incomingContentStrategy;
+ this.outgoingContentStrategy = outgoingContentStrategy;
+ this.requestParserFactory = requestParserFactory;
+ this.responseWriterFactory = responseWriterFactory;
+ this.allocator = allocator;
this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
}
@@ -134,15 +149,49 @@ public class SSLNHttpServerConnectionFac
public SSLNHttpServerConnectionFactory(
final SSLContext sslcontext,
final SSLSetupHandler sslHandler,
+ final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
+ final ByteBufferAllocator allocator,
+ final ConnectionConfig cconfig) {
+ this(sslcontext, sslHandler,
+ null, null, requestParserFactory, responseWriterFactory, allocator, cconfig);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public SSLNHttpServerConnectionFactory(
+ final SSLContext sslcontext,
+ final SSLSetupHandler sslHandler,
+ final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
+ final ConnectionConfig cconfig) {
+ this(sslcontext, sslHandler,
+ null, null, requestParserFactory, responseWriterFactory, null, cconfig);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public SSLNHttpServerConnectionFactory(
+ final SSLContext sslcontext,
+ final SSLSetupHandler sslHandler,
final ConnectionConfig config) {
- this(sslcontext, sslHandler, null, null, config);
+ this(sslcontext, sslHandler, null, null, null, null, null, config);
}
/**
* @since 4.3
*/
public SSLNHttpServerConnectionFactory(final ConnectionConfig config) {
- this(null, null, null, null, config);
+ this(null, null, null, null, null, null, null, config);
+ }
+
+ /**
+ * @since 4.3
+ */
+ public SSLNHttpServerConnectionFactory() {
+ this(null, null, null, null, null, null, null, null);
}
private SSLContext getDefaultSSLContext() {
@@ -191,9 +240,10 @@ public class SSLNHttpServerConnectionFac
ConnSupport.createDecoder(this.cconfig),
ConnSupport.createEncoder(this.cconfig),
this.cconfig.getMessageConstraints(),
- null, null,
+ this.incomingContentStrategy,
+ this.outgoingContentStrategy,
this.requestParserFactory,
- null);
+ this.responseWriterFactory);
}
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOConnFactory.java Fri Jul 5 11:47:49 2013
@@ -31,6 +31,7 @@ import java.io.IOException;
import javax.net.ssl.SSLContext;
import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
import org.apache.http.annotation.Immutable;
@@ -41,6 +42,7 @@ import org.apache.http.impl.nio.SSLNHttp
import org.apache.http.nio.NHttpClientConnection;
import org.apache.http.nio.NHttpConnectionFactory;
import org.apache.http.nio.NHttpMessageParserFactory;
+import org.apache.http.nio.NHttpMessageWriterFactory;
import org.apache.http.nio.pool.NIOConnFactory;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOSession;
@@ -79,7 +81,8 @@ public class BasicNIOConnFactory impleme
/**
* @deprecated (4.3) use {@link BasicNIOConnFactory#BasicNIOConnFactory(SSLContext,
- * SSLSetupHandler, NHttpMessageParserFactory, ByteBufferAllocator, ConnectionConfig)}
+ * SSLSetupHandler, NHttpMessageParserFactory, NHttpMessageWriterFactory,
+ * ByteBufferAllocator, ConnectionConfig)}
*/
@Deprecated
public BasicNIOConnFactory(
@@ -122,10 +125,13 @@ public class BasicNIOConnFactory impleme
final SSLContext sslcontext,
final SSLSetupHandler sslHandler,
final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+ final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
final ByteBufferAllocator allocator,
final ConnectionConfig config) {
- this(new DefaultNHttpClientConnectionFactory(responseParserFactory, allocator, config),
- new SSLNHttpClientConnectionFactory(sslcontext, sslHandler, responseParserFactory,
+ this(new DefaultNHttpClientConnectionFactory(
+ responseParserFactory, requestWriterFactory, allocator, config),
+ new SSLNHttpClientConnectionFactory(
+ sslcontext, sslHandler, responseParserFactory, requestWriterFactory,
allocator, config));
}
@@ -136,7 +142,7 @@ public class BasicNIOConnFactory impleme
final SSLContext sslcontext,
final SSLSetupHandler sslHandler,
final ConnectionConfig config) {
- this(sslcontext, sslHandler, null, null, config);
+ this(sslcontext, sslHandler, null, null, null, config);
}
/**
Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java Fri Jul 5 11:47:49 2013
@@ -39,6 +39,7 @@ import java.security.KeyStore;
import java.util.Locale;
import org.apache.http.ConnectionClosedException;
+import org.apache.http.HttpConnectionFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
@@ -50,7 +51,7 @@ import org.apache.http.MethodNotSupporte
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.DefaultBHttpServerConnection;
+import org.apache.http.impl.DefaultBHttpServerConnectionFactory;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
@@ -184,6 +185,7 @@ public class ElementalHttpServer {
static class RequestListenerThread extends Thread {
+ private final HttpConnectionFactory<HttpServerConnection> connFactory;
private final ServerSocket serversocket;
private final HttpService httpService;
@@ -191,6 +193,7 @@ public class ElementalHttpServer {
final int port,
final HttpService httpService,
final SSLServerSocketFactory sf) throws IOException {
+ this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE;
this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port);
this.httpService = httpService;
}
@@ -202,9 +205,8 @@ public class ElementalHttpServer {
try {
// Set up HTTP connection
Socket socket = this.serversocket.accept();
- DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(8 * 1024);
System.out.println("Incoming connection from " + socket.getInetAddress());
- conn.bind(socket);
+ HttpServerConnection conn = this.connFactory.createConnection(socket);
// Start worker thread
Thread t = new WorkerThread(this.httpService, conn);
Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalPoolingHttpGet.java Fri Jul 5 11:47:49 2013
@@ -88,6 +88,7 @@ public class ElementalPoolingHttpGet {
@Override
public void run() {
+ ConnectionReuseStrategy connStrategy = DefaultConnectionReuseStrategy.INSTANCE;
try {
Future<BasicPoolEntry> future = pool.lease(this.target, null);
@@ -108,7 +109,6 @@ public class ElementalPoolingHttpGet {
System.out.println("<< Response: " + response.getStatusLine());
System.out.println(EntityUtils.toString(response.getEntity()));
- ConnectionReuseStrategy connStrategy = DefaultConnectionReuseStrategy.INSTANCE;
reusable = connStrategy.keepAlive(response, coreContext);
} catch (IOException ex) {
throw ex;
Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpConnectionFactory.java?rev=1499976&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpConnectionFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpConnectionFactory.java Fri Jul 5 11:47:49 2013
@@ -0,0 +1,42 @@
+/*
+ * ====================================================================
+ * 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;
+
+import java.io.IOException;
+import java.net.Socket;
+
+/**
+ * Factory for {@link HttpConnection} instances.
+ *
+ * @since 4.3
+ */
+public interface HttpConnectionFactory<T extends HttpConnection> {
+
+ T createConnection(Socket socket) throws IOException;
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpConnectionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpConnectionFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpConnectionFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnectionFactory.java?rev=1499976&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnectionFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnectionFactory.java Fri Jul 5 11:47:49 2013
@@ -0,0 +1,104 @@
+/*
+ * ====================================================================
+ * 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;
+
+import org.apache.http.HttpConnectionFactory;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.io.HttpMessageParserFactory;
+import org.apache.http.io.HttpMessageWriterFactory;
+
+import java.io.IOException;
+import java.net.Socket;
+
+/**
+ * Default factory for {@link org.apache.http.HttpClientConnection}s.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class DefaultBHttpClientConnectionFactory
+ implements HttpConnectionFactory<DefaultBHttpClientConnection> {
+
+ public static final DefaultBHttpClientConnectionFactory INSTANCE = new DefaultBHttpClientConnectionFactory();
+
+ private final ConnectionConfig cconfig;
+ private final ContentLengthStrategy incomingContentStrategy;
+ private final ContentLengthStrategy outgoingContentStrategy;
+ private final HttpMessageWriterFactory<HttpRequest> requestWriterFactory;
+ private final HttpMessageParserFactory<HttpResponse> responseParserFactory;
+
+ public DefaultBHttpClientConnectionFactory(
+ final ConnectionConfig cconfig,
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
+ final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+ final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
+ super();
+ this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
+ this.incomingContentStrategy = incomingContentStrategy;
+ this.outgoingContentStrategy = outgoingContentStrategy;
+ this.requestWriterFactory = requestWriterFactory;
+ this.responseParserFactory = responseParserFactory;
+ }
+
+ public DefaultBHttpClientConnectionFactory(
+ final ConnectionConfig cconfig,
+ final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+ final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
+ this(cconfig, null, null, requestWriterFactory, responseParserFactory);
+ }
+
+ public DefaultBHttpClientConnectionFactory(final ConnectionConfig cconfig) {
+ this(cconfig, null, null, null, null);
+ }
+
+ public DefaultBHttpClientConnectionFactory() {
+ this(null, null, null, null, null);
+ }
+
+ @Override
+ public DefaultBHttpClientConnection createConnection(final Socket socket) throws IOException {
+ final DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(
+ this.cconfig.getBufferSize(),
+ this.cconfig.getFragmentSizeHint(),
+ ConnSupport.createDecoder(this.cconfig),
+ ConnSupport.createEncoder(this.cconfig),
+ this.cconfig.getMessageConstraints(),
+ this.incomingContentStrategy,
+ this.outgoingContentStrategy,
+ this.requestWriterFactory,
+ this.responseParserFactory);
+ conn.bind(socket);
+ return conn;
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnectionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnectionFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnectionFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnectionFactory.java?rev=1499976&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnectionFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnectionFactory.java Fri Jul 5 11:47:49 2013
@@ -0,0 +1,104 @@
+/*
+ * ====================================================================
+ * 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;
+
+import org.apache.http.HttpConnectionFactory;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.io.HttpMessageParserFactory;
+import org.apache.http.io.HttpMessageWriterFactory;
+
+import java.io.IOException;
+import java.net.Socket;
+
+/**
+ * Default factory for {@link org.apache.http.HttpServerConnection}s.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class DefaultBHttpServerConnectionFactory
+ implements HttpConnectionFactory<DefaultBHttpServerConnection> {
+
+ public static final DefaultBHttpServerConnectionFactory INSTANCE = new DefaultBHttpServerConnectionFactory();
+
+ private final ConnectionConfig cconfig;
+ private final ContentLengthStrategy incomingContentStrategy;
+ private final ContentLengthStrategy outgoingContentStrategy;
+ private final HttpMessageParserFactory<HttpRequest> requestParserFactory;
+ private final HttpMessageWriterFactory<HttpResponse> responseWriterFactory;
+
+ public DefaultBHttpServerConnectionFactory(
+ final ConnectionConfig cconfig,
+ final ContentLengthStrategy incomingContentStrategy,
+ final ContentLengthStrategy outgoingContentStrategy,
+ final HttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final HttpMessageWriterFactory<HttpResponse> responseWriterFactory) {
+ super();
+ this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
+ this.incomingContentStrategy = incomingContentStrategy;
+ this.outgoingContentStrategy = outgoingContentStrategy;
+ this.requestParserFactory = requestParserFactory;
+ this.responseWriterFactory = responseWriterFactory;
+ }
+
+ public DefaultBHttpServerConnectionFactory(
+ final ConnectionConfig cconfig,
+ final HttpMessageParserFactory<HttpRequest> requestParserFactory,
+ final HttpMessageWriterFactory<HttpResponse> responseWriterFactory) {
+ this(cconfig, null, null, requestParserFactory, responseWriterFactory);
+ }
+
+ public DefaultBHttpServerConnectionFactory(final ConnectionConfig cconfig) {
+ this(cconfig, null, null, null, null);
+ }
+
+ public DefaultBHttpServerConnectionFactory() {
+ this(null, null, null, null, null);
+ }
+
+ @Override
+ public DefaultBHttpServerConnection createConnection(final Socket socket) throws IOException {
+ final DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(
+ this.cconfig.getBufferSize(),
+ this.cconfig.getFragmentSizeHint(),
+ ConnSupport.createDecoder(this.cconfig),
+ ConnSupport.createEncoder(this.cconfig),
+ this.cconfig.getMessageConstraints(),
+ this.incomingContentStrategy,
+ this.outgoingContentStrategy,
+ this.requestParserFactory,
+ this.responseWriterFactory);
+ conn.bind(socket);
+ return conn;
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnectionFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnectionFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnectionFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java Fri Jul 5 11:47:49 2013
@@ -34,12 +34,13 @@ import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpConnectionFactory;
import org.apache.http.HttpHost;
import org.apache.http.annotation.Immutable;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.config.SocketConfig;
-import org.apache.http.impl.ConnSupport;
import org.apache.http.impl.DefaultBHttpClientConnection;
+import org.apache.http.impl.DefaultBHttpClientConnectionFactory;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParamConfig;
@@ -62,7 +63,7 @@ public class BasicConnFactory implements
private final SSLSocketFactory sslfactory;
private final int connectTimeout;
private final SocketConfig sconfig;
- private final ConnectionConfig cconfig;
+ private final HttpConnectionFactory<? extends HttpClientConnection> connFactory;
/**
* @deprecated (4.3) use
@@ -77,7 +78,8 @@ public class BasicConnFactory implements
this.sslfactory = sslfactory;
this.connectTimeout = HttpConnectionParams.getConnectionTimeout(params);
this.sconfig = HttpParamConfig.getSocketConfig(params);
- this.cconfig = HttpParamConfig.getConnectionConfig(params);
+ this.connFactory = new DefaultBHttpClientConnectionFactory(
+ HttpParamConfig.getConnectionConfig(params));
}
/**
@@ -103,7 +105,8 @@ public class BasicConnFactory implements
this.sslfactory = sslfactory;
this.connectTimeout = connectTimeout;
this.sconfig = sconfig != null ? sconfig : SocketConfig.DEFAULT;
- this.cconfig = cconfig != null ? cconfig : ConnectionConfig.DEFAULT;
+ this.connFactory = new DefaultBHttpClientConnectionFactory(
+ cconfig != null ? cconfig : ConnectionConfig.DEFAULT);
}
/**
@@ -169,15 +172,7 @@ public class BasicConnFactory implements
if (linger >= 0) {
socket.setSoLinger(linger > 0, linger);
}
- final DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(
- this.cconfig.getBufferSize(),
- this.cconfig.getFragmentSizeHint(),
- ConnSupport.createDecoder(this.cconfig),
- ConnSupport.createEncoder(this.cconfig),
- this.cconfig.getMessageConstraints(),
- null, null, null, null);
- conn.bind(socket);
- return conn;
+ return this.connFactory.createConnection(socket);
}
}
Modified: httpcomponents/httpcore/trunk/src/docbkx/advanced.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/src/docbkx/advanced.xml?rev=1499976&r1=1499975&r2=1499976&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/src/docbkx/advanced.xml (original)
+++ httpcomponents/httpcore/trunk/src/docbkx/advanced.xml Fri Jul 5 11:47:49 2013
@@ -277,6 +277,38 @@ HttpMessageWriter<HttpResponse> response
responseWriter.write(response);
]]></programlisting>
<para>
+ Custom message parsers and writers can be plugged into the message processing pipeline
+ through a custom connection factory:
+ </para>
+ <programlisting><![CDATA[
+HttpMessageWriterFactory<HttpResponse> responseWriterFactory =
+ new HttpMessageWriterFactory<HttpResponse>() {
+ @Override
+ public HttpMessageWriter<HttpResponse> create(
+ SessionOutputBuffer buffer) {
+ HttpMessageWriter<HttpResponse> customWriter = <...>
+ return customWriter;
+ }
+};
+HttpMessageParserFactory<HttpRequest> requestParserFactory =
+ new HttpMessageParserFactory<HttpRequest>() {
+ @Override
+ public HttpMessageParser<HttpRequest> create(
+ SessionInputBuffer buffer,
+ MessageConstraints constraints) {
+ HttpMessageParser<HttpRequest> customParser = <...>
+ return customParser;
+ }
+};
+HttpConnectionFactory<DefaultBHttpServerConnection> cf =
+ new DefaultBHttpServerConnectionFactory(
+ ConnectionConfig.DEFAULT,
+ requestParserFactory,
+ responseWriterFactory);
+Socket socket = <...>
+DefaultBHttpServerConnection conn = cf.createConnection(socket);
+]]></programlisting>
+ <para>
Example of HTTP request parsing / writing for non-blocking HTTP connections:
</para>
<programlisting><![CDATA[
@@ -305,6 +337,37 @@ NHttpMessageWriter responseWriter = new
responseWriter.write(response);
]]></programlisting>
</section>
+ <para>
+ Custom non-blocking message parsers and writers can be plugged into the message processing
+ pipeline through a custom connection factory:
+ </para>
+ <programlisting><![CDATA[
+NHttpMessageWriterFactory<HttpResponse> responseWriterFactory =
+ new NHttpMessageWriterFactory<HttpResponse>() {
+ @Override
+ public NHttpMessageWriter<HttpResponse> create(SessionOutputBuffer buffer) {
+ NHttpMessageWriter<HttpResponse> customWriter = <...>
+ return customWriter;
+ }
+};
+NHttpMessageParserFactory<HttpRequest> requestParserFactory =
+ new NHttpMessageParserFactory<HttpRequest>() {
+ @Override
+ public NHttpMessageParser<HttpRequest> create(
+ SessionInputBuffer buffer, MessageConstraints constraints) {
+ NHttpMessageParser<HttpRequest> customParser = <...>
+ return customParser;
+ }
+};
+NHttpConnectionFactory<DefaultNHttpServerConnection> cf =
+ new DefaultNHttpServerConnectionFactory(
+ null,
+ requestParserFactory,
+ responseWriterFactory,
+ ConnectionConfig.DEFAULT);
+IOSession iosession = <...>
+DefaultNHttpServerConnection conn = cf.createConnection(iosession);
+]]></programlisting>
<section>
<title>HTTP header parsing on demand</title>
<para>