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 2012/10/02 21:44:37 UTC

svn commit: r1393136 [2/3] - in /httpcomponents/httpcore/trunk: ./ httpcore-ab/src/main/java/org/apache/http/benchmark/ httpcore-ab/src/test/java/org/apache/http/benchmark/ httpcore-nio/src/main/java/org/apache/http/impl/nio/ httpcore-nio/src/main/java...

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=1393136&r1=1393135&r2=1393136&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 Tue Oct  2 19:44:35 2012
@@ -52,9 +52,9 @@ import org.apache.http.entity.StringEnti
 import org.apache.http.impl.DefaultBHttpServerConnection;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.Config;
 import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpCoreConfigBuilder;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.HttpContext;
@@ -154,13 +154,10 @@ public class ElementalHttpServer {
 
         public RequestListenerThread(int port, final String docroot) throws IOException {
             this.serversocket = new ServerSocket(port);
-            this.params = new BasicHttpParams();
-            this.params
-                .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
-                .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
-                .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
-                .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
-                .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
+            this.params = new HttpCoreConfigBuilder()
+                .setSocketTimeout(5000)
+                .setTcpNoDelay(true)
+                .setOriginServer("HttpComponents/1.1").build();
 
             // Set up the HTTP protocol processor
             HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
@@ -190,7 +187,8 @@ public class ElementalHttpServer {
                 try {
                     // Set up HTTP connection
                     Socket socket = this.serversocket.accept();
-                    DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(this.params);
+                    int bufsize = Config.getInt(params, CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024);
+                    DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(bufsize);
                     System.out.println("Incoming connection from " + socket.getInetAddress());
                     conn.bind(socket);
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java Tue Oct  2 19:44:35 2012
@@ -46,9 +46,9 @@ import org.apache.http.impl.DefaultBHttp
 import org.apache.http.impl.DefaultBHttpServerConnection;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.Config;
 import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpCoreConfigBuilder;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.BasicHttpContext;
 import org.apache.http.protocol.ExecutionContext;
@@ -177,13 +177,10 @@ public class ElementalReverseProxy {
         public RequestListenerThread(int port, final HttpHost target) throws IOException {
             this.target = target;
             this.serversocket = new ServerSocket(port);
-            this.params = new BasicHttpParams();
-            this.params
-                .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
-                .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
-                .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
-                .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
-                .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
+            this.params = new HttpCoreConfigBuilder()
+                .setSocketTimeout(5000)
+                .setTcpNoDelay(true)
+                .setOriginServer("HttpComponents/1.1").build();
 
             // Set up HTTP protocol processor for incoming connections
             HttpProcessor inhttpproc = new ImmutableHttpProcessor(
@@ -228,15 +225,16 @@ public class ElementalReverseProxy {
             System.out.println("Listening on port " + this.serversocket.getLocalPort());
             while (!Thread.interrupted()) {
                 try {
+                    int bufsize = Config.getInt(params, CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024);
                     // Set up incoming HTTP connection
                     Socket insocket = this.serversocket.accept();
-                    DefaultBHttpServerConnection inconn = new DefaultBHttpServerConnection(this.params);
+                    DefaultBHttpServerConnection inconn = new DefaultBHttpServerConnection(bufsize);
                     System.out.println("Incoming connection from " + insocket.getInetAddress());
                     inconn.bind(insocket);
 
                     // Set up outgoing HTTP connection
                     Socket outsocket = new Socket(this.target.getHostName(), this.target.getPort());
-                    DefaultBHttpClientConnection outconn = new DefaultBHttpClientConnection(this.params);
+                    DefaultBHttpClientConnection outconn = new DefaultBHttpClientConnection(bufsize);
                     outconn.bind(outsocket);
                     System.out.println("Outgoing connection to " + outsocket.getInetAddress());
 

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageConstraintException.java (from r1392511, httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageConstraintException.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageConstraintException.java&p1=httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java&r1=1392511&r2=1393136&rev=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageConstraintException.java Tue Oct  2 19:44:35 2012
@@ -24,33 +24,27 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.benchmark;
 
-import java.io.InputStream;
-import java.io.OutputStream;
+package org.apache.http;
 
-import org.apache.http.impl.DefaultBHttpClientConnection;
-import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.params.HttpParams;
-
-class BenchmarkConnection extends DefaultBHttpClientConnection {
-
-    private final Stats stats;
-    
-    BenchmarkConnection(final Stats stats, final HttpParams params) {
-        super(params);
-        this.stats = stats;
-    }
+import java.io.IOException;
 
-    @Override
-    protected OutputStream createOutputStream(final long len, final SessionOutputBuffer outbuffer) {
-        return new CountingOutputStream(super.createOutputStream(len, outbuffer), this.stats);
-    }
+/**
+ * Signals a message constraint violation.
+ *
+ * @since 4.3
+ */
+public class MessageConstraintException extends IOException {
+
+    private static final long serialVersionUID = 6077207720446368695L;
 
-    @Override
-    protected InputStream createInputStream(final long len, final SessionInputBuffer inbuffer) {
-        return new CountingInputStream(super.createInputStream(len, inbuffer), this.stats);
+    /**
+     * Creates a TruncatedChunkException with the specified detail message.
+     *
+     * @param message The exception detail message
+     */
+    public MessageConstraintException(final String message) {
+        super(message);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java Tue Oct  2 19:44:35 2012
@@ -35,12 +35,9 @@ import java.net.Socket;
 import java.net.SocketAddress;
 import java.net.SocketException;
 import java.net.SocketTimeoutException;
-import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
 
-import org.apache.http.Consts;
 import org.apache.http.Header;
 import org.apache.http.HttpConnection;
 import org.apache.http.HttpConnectionMetrics;
@@ -62,34 +59,16 @@ import org.apache.http.impl.io.IdentityI
 import org.apache.http.impl.io.IdentityOutputStream;
 import org.apache.http.impl.io.SessionInputBufferImpl;
 import org.apache.http.impl.io.SessionOutputBufferImpl;
-import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.Config;
-import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.util.Args;
 import org.apache.http.util.Asserts;
-import org.apache.http.util.CharsetUtils;
 import org.apache.http.util.NetUtils;
 
 /**
  * This class serves as a base for all {@link HttpConnection} implementations and provides
  * functionality common to both client and server HTTP connections.
- * <p/>
- * The following parameters can be used to customize the behavior of this
- * class:
- * <ul>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_MALFORMED_INPUT_ACTION}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_UNMAPPABLE_INPUT_ACTION}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MIN_CHUNK_LIMIT}</li>
- * </ul>
  *
  * @since 4.0
  */
@@ -98,8 +77,6 @@ public class BHttpConnectionBase impleme
 
     private final SessionInputBufferImpl inbuffer;
     private final SessionOutputBufferImpl outbuffer;
-    private final HttpTransportMetricsImpl inTransportMetrics;
-    private final HttpTransportMetricsImpl outTransportMetrics;
     private final HttpConnectionMetricsImpl connMetrics;
     private final ContentLengthStrategy incomingContentStrategy;
     private final ContentLengthStrategy outgoingContentStrategy;
@@ -107,43 +84,41 @@ public class BHttpConnectionBase impleme
     private volatile boolean open;
     private volatile Socket socket;
 
-    public BHttpConnectionBase(final HttpParams params) {
+    /**
+     * Creates new instance of BHttpConnectionBase.
+     *
+     * @param buffersize buffer size. Must be a positive number.
+     * @param chardecoder decoder to be used for decoding HTTP protocol elements.
+     *   If <code>null</code> simple type cast will be used for byte to char conversion.
+     * @param charencoder encoder to be used for encoding HTTP protocol elements.
+     *   If <code>null</code> simple type cast will be used for char to byte conversion.
+     * @param constraints Message constraints. If <code>null</code>
+     *   {@link MessageConstraints#DEFAULT} will be used.
+     * @param incomingContentStrategy incoming content length strategy. If <code>null</code>
+     *   {@link LaxContentLengthStrategy#INSTANCE} will be used.
+     * @param outgoingContentStrategy outgoing content length strategy. If <code>null</code>
+     *   {@link StrictContentLengthStrategy#INSTANCE} will be used.
+     */
+    protected BHttpConnectionBase(
+            int buffersize,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints,
+            final ContentLengthStrategy incomingContentStrategy,
+            final ContentLengthStrategy outgoingContentStrategy) {
         super();
-        Args.notNull(params, "HTTP parameters");
-        int buffersize = Config.getInt(params, CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1);
-        if (buffersize <= 0) {
-            buffersize = 4096;
-        }
-        int maxLineLen = Config.getInt(params, CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        int minChunkLimit = Config.getInt(params, CoreConnectionPNames.MIN_CHUNK_LIMIT, -1);
-        CharsetDecoder decoder = null;
-        CharsetEncoder encoder = null;
-        Charset charset = CharsetUtils.lookup(Config.getString(params,
-                CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
-        if (charset != null) {
-            charset = Consts.ASCII;
-            decoder = charset.newDecoder();
-            encoder = charset.newEncoder();
-            CodingErrorAction malformedCharAction = Config.getValue(params,
-                    CoreProtocolPNames.HTTP_MALFORMED_INPUT_ACTION, CodingErrorAction.class);
-            CodingErrorAction unmappableCharAction = Config.getValue(params,
-                    CoreProtocolPNames.HTTP_UNMAPPABLE_INPUT_ACTION, CodingErrorAction.class);
-            decoder.onMalformedInput(malformedCharAction);
-            decoder.onUnmappableCharacter(unmappableCharAction);
-            encoder.onMalformedInput(malformedCharAction);
-            encoder.onUnmappableCharacter(unmappableCharAction);
-        }
-        this.inTransportMetrics = createTransportMetrics();
-        this.outTransportMetrics = createTransportMetrics();
-        this.inbuffer = new SessionInputBufferImpl(
-                this.inTransportMetrics, buffersize, maxLineLen, minChunkLimit, decoder);
-        this.outbuffer = new SessionOutputBufferImpl(
-                this.outTransportMetrics, buffersize, minChunkLimit, encoder);
-        this.connMetrics = createConnectionMetrics(
-                this.inTransportMetrics,
-                this.outTransportMetrics);
-        this.incomingContentStrategy = createIncomingContentStrategy();
-        this.outgoingContentStrategy = createOutgoingContentStrategy();
+        Args.positive(buffersize, "Buffer size");
+        HttpTransportMetricsImpl inTransportMetrics = new HttpTransportMetricsImpl();
+        HttpTransportMetricsImpl outTransportMetrics = new HttpTransportMetricsImpl();
+        this.inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1,
+                constraints != null ? constraints : MessageConstraints.DEFAULT, chardecoder);
+        this.outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, -1,
+                charencoder);
+        this.connMetrics = new HttpConnectionMetricsImpl(inTransportMetrics, outTransportMetrics);
+        this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
+            LaxContentLengthStrategy.INSTANCE;
+        this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
+            StrictContentLengthStrategy.INSTANCE;
     }
 
     protected void assertNotOpen() {
@@ -200,24 +175,6 @@ public class BHttpConnectionBase impleme
         return this.socket;
     }
 
-    protected HttpTransportMetricsImpl createTransportMetrics() {
-        return new HttpTransportMetricsImpl();
-    }
-
-    protected HttpConnectionMetricsImpl createConnectionMetrics(
-            final HttpTransportMetrics inTransportMetric,
-            final HttpTransportMetrics outTransportMetric) {
-        return new HttpConnectionMetricsImpl(inTransportMetric, outTransportMetric);
-    }
-
-    protected ContentLengthStrategy createIncomingContentStrategy() {
-        return new LaxContentLengthStrategy();
-    }
-
-    protected ContentLengthStrategy createOutgoingContentStrategy() {
-        return new StrictContentLengthStrategy();
-    }
-
     protected OutputStream createOutputStream(
             final long len,
             final SessionOutputBuffer outbuffer) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java Tue Oct  2 19:44:35 2012
@@ -31,6 +31,8 @@ import java.io.IOException;
 import java.io.OutputStream;
 import java.net.Socket;
 import java.net.SocketTimeoutException;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
 
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpEntity;
@@ -38,37 +40,20 @@ import org.apache.http.HttpEntityEnclosi
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
-import org.apache.http.HttpResponseFactory;
 import org.apache.http.annotation.NotThreadSafe;
-import org.apache.http.impl.io.DefaultHttpRequestWriter;
-import org.apache.http.impl.io.DefaultHttpResponseParser;
+import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.impl.entity.LaxContentLengthStrategy;
+import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.io.DefaultHttpRequestWriterFactory;
+import org.apache.http.impl.io.DefaultHttpResponseParserFactory;
 import org.apache.http.io.HttpMessageParser;
+import org.apache.http.io.HttpMessageParserFactory;
 import org.apache.http.io.HttpMessageWriter;
-import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.message.BasicLineFormatter;
-import org.apache.http.message.BasicLineParser;
-import org.apache.http.message.LineFormatter;
-import org.apache.http.message.LineParser;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.Config;
-import org.apache.http.params.HttpParams;
+import org.apache.http.io.HttpMessageWriterFactory;
 import org.apache.http.util.Args;
 
 /**
  * Default implementation of {@link HttpClientConnection}.
- * <p/>
- * The following parameters can be used to customize the behavior of this
- * class:
- * <ul>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_MALFORMED_INPUT_ACTION}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_UNMAPPABLE_INPUT_ACTION}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MIN_CHUNK_LIMIT}</li>
- * </ul>
  *
  * @since 4.3
  */
@@ -79,60 +64,52 @@ public class DefaultBHttpClientConnectio
     private final HttpMessageParser<HttpResponse> responseParser;
     private final HttpMessageWriter<HttpRequest> requestWriter;
 
-    public DefaultBHttpClientConnection(
-            final LineParser lineParser,
-            final LineFormatter lineFormatter,
-            final HttpResponseFactory responseFactory,
-            final HttpParams params) {
-        super(params);
-        this.responseParser = createResponseParser(
-                getSessionInputBuffer(), lineParser, responseFactory, params);
-        this.requestWriter = createRequestWriter(
-                getSessionOutputBuffer(), lineFormatter, params);
-    }
-
-    public DefaultBHttpClientConnection(final HttpParams params) {
-        this(null, null, null, params);
-    }
-
     /**
-     * Creates an instance of {@link HttpMessageParser} to be used for parsing
-     * HTTP responses received over this connection.
+     * Creates new instance of DefaultBHttpClientConnection.
      *
-     * @param buffer the session input buffer.
-     * @param lineParser the line parser. If <code>null</code> {@link BasicLineParser#INSTANCE}
-     *   will be used
-     * @param responseFactory the response factory. If <code>null</code>
-     *   {@link DefaultHttpResponseFactory#INSTANCE} will be used.
-     * @param params HTTP parameters.
-     * @return HTTP response parser.
+     * @param buffersize buffer size. Must be a positive number.
+     * @param chardecoder decoder to be used for decoding HTTP protocol elements.
+     *   If <code>null</code> simple type cast will be used for byte to char conversion.
+     * @param charencoder encoder to be used for encoding HTTP protocol elements.
+     *   If <code>null</code> simple type cast will be used for char to byte conversion.
+     * @param constraints Message constraints. If <code>null</code>
+     *   {@link MessageConstraints#DEFAULT} will be used.
+     * @param incomingContentStrategy incoming content length strategy. If <code>null</code>
+     *   {@link LaxContentLengthStrategy#INSTANCE} will be used.
+     * @param outgoingContentStrategy outgoing content length strategy. If <code>null</code>
+     *   {@link StrictContentLengthStrategy#INSTANCE} will be used.
+     * @param requestWriterFactory request writer factory. If <code>null</code>
+     *   {@link DefaultHttpRequestWriterFactory#INSTANCE} will be used.
+     * @param responseParserFactory response parser factory. If <code>null</code>
+     *   {@link DefaultHttpResponseParserFactory#INSTANCE} will be used.
      */
-    protected HttpMessageParser<HttpResponse> createResponseParser(
-            final SessionInputBuffer buffer,
-            final LineParser lineParser,
-            final HttpResponseFactory responseFactory,
-            final HttpParams params) {
-        int maxHeaderCount = Config.getInt(params, CoreConnectionPNames.MAX_HEADER_COUNT, -1);
-        int maxLineLen = Config.getInt(params, CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        return new DefaultHttpResponseParser(
-                buffer, maxHeaderCount, maxLineLen, lineParser, responseFactory);
+    public DefaultBHttpClientConnection(
+            int buffersize,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints,
+            final ContentLengthStrategy incomingContentStrategy,
+            final ContentLengthStrategy outgoingContentStrategy,
+            final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+            final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
+        super(buffersize, chardecoder, charencoder,
+                constraints, incomingContentStrategy, outgoingContentStrategy);
+        this.requestWriter = (requestWriterFactory != null ? requestWriterFactory :
+            DefaultHttpRequestWriterFactory.INSTANCE).create(getSessionOutputBuffer());
+        this.responseParser = (responseParserFactory != null ? responseParserFactory :
+            DefaultHttpResponseParserFactory.INSTANCE).create(getSessionInputBuffer(), constraints);
     }
 
-    /**
-     * Creates an instance of {@link HttpMessageWriter} to be used for
-     * writing out HTTP requests sent over this connection.
-     *
-     * @param buffer the session output buffer
-     * @param lineFormatter the line formatter. If <code>null</code>
-     *   {@link BasicLineFormatter#INSTANCE} will be used.
-     * @param params HTTP parameters
-     * @return HTTP request writer
-     */
-    protected HttpMessageWriter<HttpRequest> createRequestWriter(
-            final SessionOutputBuffer buffer,
-            final LineFormatter lineFormatter,
-            final HttpParams params) {
-        return new DefaultHttpRequestWriter(buffer, lineFormatter);
+    public DefaultBHttpClientConnection(
+            int buffersize,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints) {
+        this(buffersize, chardecoder, charencoder, constraints, null, null, null, null);
+    }
+
+    public DefaultBHttpClientConnection(int buffersize) {
+        this(buffersize, null, null, null, null, null, null, null);
     }
 
     protected void onResponseReceived(final HttpResponse response) {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java Tue Oct  2 19:44:35 2012
@@ -30,47 +30,29 @@ package org.apache.http.impl;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.Socket;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
-import org.apache.http.HttpRequestFactory;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpServerConnection;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.entity.ContentLengthStrategy;
 import org.apache.http.impl.entity.DisallowIdentityContentLengthStrategy;
-import org.apache.http.impl.entity.LaxContentLengthStrategy;
-import org.apache.http.impl.io.DefaultHttpRequestParser;
-import org.apache.http.impl.io.DefaultHttpResponseWriter;
+import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.io.DefaultHttpRequestParserFactory;
+import org.apache.http.impl.io.DefaultHttpResponseWriterFactory;
 import org.apache.http.io.HttpMessageParser;
+import org.apache.http.io.HttpMessageParserFactory;
 import org.apache.http.io.HttpMessageWriter;
-import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.message.BasicLineFormatter;
-import org.apache.http.message.BasicLineParser;
-import org.apache.http.message.LineFormatter;
-import org.apache.http.message.LineParser;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.Config;
-import org.apache.http.params.HttpParams;
+import org.apache.http.io.HttpMessageWriterFactory;
 import org.apache.http.util.Args;
 
 /**
  * Default implementation of {@link HttpServerConnection}.
- * <p/>
- * The following parameters can be used to customize the behavior of this
- * class:
- * <ul>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_MALFORMED_INPUT_ACTION}</li>
- *  <li>{@link org.apache.http.params.CoreProtocolPNames#HTTP_UNMAPPABLE_INPUT_ACTION}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MIN_CHUNK_LIMIT}</li>
- * </ul>
  *
  * @since 4.3
  */
@@ -81,65 +63,53 @@ public class DefaultBHttpServerConnectio
     private final HttpMessageParser<HttpRequest> requestParser;
     private final HttpMessageWriter<HttpResponse> responseWriter;
 
-    public DefaultBHttpServerConnection(
-            final LineParser lineParser,
-            final LineFormatter lineFormatter,
-            final HttpRequestFactory requestFactory,
-            final HttpParams params) {
-        super(params);
-        this.requestParser = createRequestParser(
-                getSessionInputBuffer(), lineParser, requestFactory, params);
-        this.responseWriter = createResponseWriter(
-                getSessionOutputBuffer(), lineFormatter, params);
-    }
-
-    public DefaultBHttpServerConnection(final HttpParams params) {
-        this(null, null, null, params);
-    }
-
-    @Override
-    protected ContentLengthStrategy createIncomingContentStrategy() {
-        return new DisallowIdentityContentLengthStrategy(new LaxContentLengthStrategy(0));
-    }
-
     /**
-     * Creates an instance of {@link HttpMessageParser} to be used for parsing
-     * HTTP requests received over this connection.
+     * Creates new instance of DefaultBHttpServerConnection.
      *
-     * @param buffer the session input buffer.
-     * @param lineParser the line parser. If <code>null</code> {@link BasicLineParser#INSTANCE}
-     *   will be used
-     * @param responseFactory the response factory. If <code>null</code>
-     *   {@link DefaultHttpRequestFactory#INSTANCE} will be used.
-     * @param params HTTP parameters.
-     * @return HTTP message parser.
+     * @param buffersize buffer size. Must be a positive number.
+     * @param chardecoder decoder to be used for decoding HTTP protocol elements.
+     *   If <code>null</code> simple type cast will be used for byte to char conversion.
+     * @param charencoder encoder to be used for encoding HTTP protocol elements.
+     *   If <code>null</code> simple type cast will be used for char to byte conversion.
+     * @param constraints Message constraints. If <code>null</code>
+     *   {@link MessageConstraints#DEFAULT} will be used.
+     * @param incomingContentStrategy incoming content length strategy. If <code>null</code>
+     *   {@link DisallowIdentityContentLengthStrategy#INSTANCE} will be used.
+     * @param outgoingContentStrategy outgoing content length strategy. If <code>null</code>
+     *   {@link StrictContentLengthStrategy#INSTANCE} will be used.
+     * @param requestParserFactory request parser factory. If <code>null</code>
+     *   {@link DefaultHttpRequestParserFactory#INSTANCE} will be used.
+     * @param responseWriterFactory response writer factory. If <code>null</code>
+     *   {@link DefaultHttpResponseWriterFactory#INSTANCE} will be used.
      */
-    protected HttpMessageParser<HttpRequest> createRequestParser(
-            final SessionInputBuffer buffer,
-            final LineParser lineParser,
-            final HttpRequestFactory requestFactory,
-            final HttpParams params) {
-        int maxHeaderCount = Config.getInt(params, CoreConnectionPNames.MAX_HEADER_COUNT, -1);
-        int maxLineLen = Config.getInt(params, CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        return new DefaultHttpRequestParser(
-                buffer, maxHeaderCount, maxLineLen, lineParser, requestFactory);
+    public DefaultBHttpServerConnection(
+            int buffersize,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints,
+            final ContentLengthStrategy incomingContentStrategy,
+            final ContentLengthStrategy outgoingContentStrategy,
+            final HttpMessageParserFactory<HttpRequest> requestParserFactory,
+            final HttpMessageWriterFactory<HttpResponse> responseWriterFactory) {
+        super(buffersize, chardecoder, charencoder, constraints,
+                incomingContentStrategy != null ? incomingContentStrategy :
+                    DisallowIdentityContentLengthStrategy.INSTANCE, outgoingContentStrategy);
+        this.requestParser = (requestParserFactory != null ? requestParserFactory :
+            DefaultHttpRequestParserFactory.INSTANCE).create(getSessionInputBuffer(), constraints);
+        this.responseWriter = (responseWriterFactory != null ? responseWriterFactory :
+            DefaultHttpResponseWriterFactory.INSTANCE).create(getSessionOutputBuffer());
     }
 
-    /**
-     * Creates an instance of {@link HttpMessageWriter} to be used for
-     * writing out HTTP responses sent over this connection.
-     *
-     * @param buffer the session output buffer
-     * @param lineFormatter the line formatter. If <code>null</code>
-     *   {@link BasicLineFormatter#INSTANCE} will be used.
-     * @param params HTTP parameters
-     * @return HTTP message writer
-     */
-    protected HttpMessageWriter<HttpResponse> createResponseWriter(
-            final SessionOutputBuffer buffer,
-            final LineFormatter lineFormatter,
-            final HttpParams params) {
-        return new DefaultHttpResponseWriter(buffer, lineFormatter);
+    public DefaultBHttpServerConnection(
+            int buffersize,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints) {
+        this(buffersize, chardecoder, charencoder, constraints, null, null, null, null);
+    }
+
+    public DefaultBHttpServerConnection(int buffersize) {
+        this(buffersize, null, null, null, null, null, null, null);
     }
 
     protected void onRequestReceived(final HttpRequest request) {

Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java?rev=1393136&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java Tue Oct  2 19:44:35 2012
@@ -0,0 +1,105 @@
+/*
+ * ====================================================================
+ * 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.util.Args;
+
+/**
+ * HTTP Message constraints: line length and header count.
+ *
+ * @since 4.3
+ */
+public class MessageConstraints {
+
+    public static final MessageConstraints UNLIMITED = new MessageConstraints(-1, -1);
+    public static final MessageConstraints DEFAULT = UNLIMITED;
+
+    private final int maxLineLength;
+    private final int maxHeaderCount;
+
+    MessageConstraints(int maxLineLength, int maxHeaderCount) {
+        super();
+        this.maxLineLength = maxLineLength;
+        this.maxHeaderCount = maxHeaderCount;
+    }
+
+    public static MessageConstraints lineLen(int max) {
+        return new MessageConstraints(Args.notNegative(max, "Max line length"), -1);
+    }
+
+    public static MessageConstraints.Builder custom() {
+        return new MessageConstraints.Builder();
+    }
+
+    public int getMaxLineLength() {
+        return maxLineLength;
+    }
+
+    public int getMaxHeaderCount() {
+        return maxHeaderCount;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("[maxLineLength=").append(maxLineLength)
+                .append(", maxHeaderCount=").append(maxHeaderCount)
+                .append("]");
+        return builder.toString();
+    }
+
+    public static class Builder {
+
+        private int maxLineLength;
+        private int maxHeaderCount;
+
+        public int getMaxLineLength() {
+            return maxLineLength;
+        }
+
+        public Builder setMaxLineLength(int maxLineLength) {
+            this.maxLineLength = maxLineLength;
+            return this;
+        }
+
+        public int getMaxHeaderCount() {
+            return maxHeaderCount;
+        }
+
+        public Builder setMaxHeaderCount(int maxHeaderCount) {
+            this.maxHeaderCount = maxHeaderCount;
+            return this;
+        }
+
+        public MessageConstraints build() {
+            return new MessageConstraints(maxLineLength, maxHeaderCount);
+        }
+
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java Tue Oct  2 19:44:35 2012
@@ -34,16 +34,19 @@ import org.apache.http.annotation.Immuta
 import org.apache.http.entity.ContentLengthStrategy;
 
 /**
- * Decorator for  {@link ContentLengthStrategy} implementations that disallows the use of 
- * identity transfer encoding. 
+ * Decorator for  {@link ContentLengthStrategy} implementations that disallows the use of
+ * identity transfer encoding.
  *
  * @since 4.2
  */
 @Immutable
 public class DisallowIdentityContentLengthStrategy implements ContentLengthStrategy {
 
+    public static final ContentLengthStrategy INSTANCE = new DisallowIdentityContentLengthStrategy(
+            new LaxContentLengthStrategy(0));
+
     private final ContentLengthStrategy contentLengthStrategy;
-    
+
     public DisallowIdentityContentLengthStrategy(final ContentLengthStrategy contentLengthStrategy) {
         super();
         this.contentLengthStrategy = contentLengthStrategy;

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java Tue Oct  2 19:44:35 2012
@@ -50,14 +50,16 @@ import org.apache.http.util.Args;
 @Immutable
 public class LaxContentLengthStrategy implements ContentLengthStrategy {
 
+    public static final ContentLengthStrategy INSTANCE = new LaxContentLengthStrategy();
+
     private final int implicitLen;
-    
+
     /**
      * Creates <tt>LaxContentLengthStrategy</tt> instance with the given length used per default
      * when content length is not explicitly specified in the message.
-     * 
+     *
      * @param implicitLen implicit content length.
-     * 
+     *
      * @since 4.2
      */
     public LaxContentLengthStrategy(int implicitLen) {
@@ -66,7 +68,7 @@ public class LaxContentLengthStrategy im
     }
 
     /**
-     * Creates <tt>LaxContentLengthStrategy</tt> instance. {@link ContentLengthStrategy#IDENTITY} 
+     * Creates <tt>LaxContentLengthStrategy</tt> instance. {@link ContentLengthStrategy#IDENTITY}
      * is used per default when content length is not explicitly specified in the message.
      */
     public LaxContentLengthStrategy() {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java Tue Oct  2 19:44:35 2012
@@ -50,14 +50,16 @@ import org.apache.http.util.Args;
 @Immutable
 public class StrictContentLengthStrategy implements ContentLengthStrategy {
 
+    public static final ContentLengthStrategy INSTANCE = new StrictContentLengthStrategy();
+
     private final int implicitLen;
-    
+
     /**
      * Creates <tt>StrictContentLengthStrategy</tt> instance with the given length used per default
      * when content length is not explicitly specified in the message.
-     * 
+     *
      * @param implicitLen implicit content length.
-     * 
+     *
      * @since 4.2
      */
     public StrictContentLengthStrategy(int implicitLen) {
@@ -66,7 +68,7 @@ public class StrictContentLengthStrategy
     }
 
     /**
-     * Creates <tt>StrictContentLengthStrategy</tt> instance. {@link ContentLengthStrategy#IDENTITY} 
+     * Creates <tt>StrictContentLengthStrategy</tt> instance. {@link ContentLengthStrategy#IDENTITY}
      * is used per default when content length is not explicitly specified in the message.
      */
     public StrictContentLengthStrategy() {

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java Tue Oct  2 19:44:35 2012
@@ -34,9 +34,11 @@ import java.util.List;
 import org.apache.http.Header;
 import org.apache.http.HttpException;
 import org.apache.http.HttpMessage;
+import org.apache.http.MessageConstraintException;
 import org.apache.http.ParseException;
 import org.apache.http.ProtocolException;
 import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.impl.MessageConstraints;
 import org.apache.http.io.HttpMessageParser;
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.message.BasicLineParser;
@@ -59,8 +61,7 @@ public abstract class AbstractMessagePar
     private static final int HEADERS      = 1;
 
     private final SessionInputBuffer sessionBuffer;
-    private final int maxHeaderCount;
-    private final int maxLineLen;
+    private final MessageConstraints messageConstraints;
     private final List<CharArrayBuffer> headerLines;
     protected final LineParser lineParser;
 
@@ -85,10 +86,10 @@ public abstract class AbstractMessagePar
         Args.notNull(buffer, "Session input buffer");
         Args.notNull(params, "HTTP parameters");
         this.sessionBuffer = buffer;
-        this.maxHeaderCount = params.getIntParameter(
-                CoreConnectionPNames.MAX_HEADER_COUNT, -1);
-        this.maxLineLen = params.getIntParameter(
-                CoreConnectionPNames.MAX_LINE_LENGTH, -1);
+        this.messageConstraints = MessageConstraints.custom()
+            .setMaxHeaderCount(params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1))
+            .setMaxLineLength(params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1))
+            .build();
         this.lineParser = (parser != null) ? parser : BasicLineParser.INSTANCE;
         this.headerLines = new ArrayList<CharArrayBuffer>();
         this.state = HEAD_LINE;
@@ -98,26 +99,21 @@ public abstract class AbstractMessagePar
      * Creates new instance of AbstractMessageParser.
      *
      * @param buffer the session input buffer.
-     * @param maxHeaderCount maximum header count limit. If set to a positive value, total number of 
-     *   headers in a message exceeding this limit will cause an I/O error. A negative value will 
-     *   disable the check.
-     * @param maxLineLen maximum line length limit. If set to a positive value, any line exceeding
-     *   this limit will cause an I/O error. A negative value will disable the check.
      * @param parser the line parser. If <code>null</code> {@link BasicLineParser#INSTANCE} 
-     *   will be used
+     *   will be used.
+     * @param parser the message constraints. If <code>null</code> {@link MessageConstraints#DEFAULT} 
+     *   will be used.
      * 
      * @since 4.3
      */
     public AbstractMessageParser(
             final SessionInputBuffer buffer,
-            int maxHeaderCount,
-            int maxLineLen,
-            final LineParser parser) {
+            final LineParser parser,
+            final MessageConstraints constraints) {
         super();
         this.sessionBuffer = Args.notNull(buffer, "Session input buffer");
-        this.lineParser = (parser != null) ? parser : BasicLineParser.INSTANCE;
-        this.maxHeaderCount = maxHeaderCount;
-        this.maxLineLen = maxLineLen;
+        this.lineParser = parser != null ? parser : BasicLineParser.INSTANCE;
+        this.messageConstraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
         this.headerLines = new ArrayList<CharArrayBuffer>();
         this.state = HEAD_LINE;
     }
@@ -217,7 +213,7 @@ public abstract class AbstractMessagePar
                 }
                 if (maxLineLen > 0
                         && previous.length() + 1 + current.length() - i > maxLineLen) {
-                    throw new IOException("Maximum line length limit exceeded");
+                    throw new MessageConstraintException("Maximum line length limit exceeded");
                 }
                 previous.append(' ');
                 previous.append(current, i, current.length() - i);
@@ -227,7 +223,7 @@ public abstract class AbstractMessagePar
                 current = null;
             }
             if (maxHeaderCount > 0 && headerLines.size() >= maxHeaderCount) {
-                throw new IOException("Maximum header count exceeded");
+                throw new MessageConstraintException("Maximum header count exceeded");
             }
         }
         Header[] headers = new Header[headerLines.size()];
@@ -273,8 +269,8 @@ public abstract class AbstractMessagePar
         case HEADERS:
             Header[] headers = AbstractMessageParser.parseHeaders(
                     this.sessionBuffer,
-                    this.maxHeaderCount,
-                    this.maxLineLen,
+                    this.messageConstraints.getMaxHeaderCount(),
+                    this.messageConstraints.getMaxLineLength(),
                     this.lineParser,
                     this.headerLines);
             this.message.setHeaders(headers);

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java Tue Oct  2 19:44:35 2012
@@ -38,6 +38,7 @@ import org.apache.http.RequestLine;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.impl.DefaultHttpRequestFactory;
 import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.MessageConstraints;
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.message.BasicLineParser;
 import org.apache.http.message.LineParser;
@@ -85,30 +86,42 @@ public class DefaultHttpRequestParser ex
      * Creates new instance of DefaultHttpRequestParser.
      *
      * @param buffer the session input buffer.
-     * @param maxHeaderCount maximum header count limit. If set to a positive value, total number of 
-     *   headers in a message exceeding this limit will cause an I/O error. A negative value will 
-     *   disable the check.
-     * @param maxLineLen maximum line length limit. If set to a positive value, any line exceeding
-     *   this limit will cause an I/O error. A negative value will disable the check.
      * @param parser the line parser. If <code>null</code> {@link BasicLineParser#INSTANCE} will
      *   be used. 
      * @param responseFactory the response factory. If <code>null</code> 
      *   {@link DefaultHttpResponseFactory#INSTANCE} will be used. 
+     * @param parser the message constraints. If <code>null</code> {@link MessageConstraints#DEFAULT} 
+     *   will be used.
      * 
      * @since 4.3
      */
     public DefaultHttpRequestParser(
             final SessionInputBuffer buffer,
-            int maxHeaderCount,
-            int maxLineLen,
             final LineParser parser,
-            final HttpRequestFactory requestFactory) {
-        super(buffer, maxHeaderCount, maxLineLen, parser);
+            final HttpRequestFactory requestFactory,
+            final MessageConstraints messageConstraints) {
+        super(buffer, parser, messageConstraints);
         this.requestFactory = requestFactory != null ? requestFactory : 
             DefaultHttpRequestFactory.INSTANCE;
         this.lineBuf = new CharArrayBuffer(128);
     }
 
+    /**
+     * @since 4.3
+     */
+    public DefaultHttpRequestParser(
+            final SessionInputBuffer buffer,
+            final MessageConstraints messageConstraints) {
+        this(buffer, null, null, messageConstraints);
+    }
+
+    /**
+     * @since 4.3
+     */
+    public DefaultHttpRequestParser(final SessionInputBuffer buffer) {
+        this(buffer, null, null, MessageConstraints.DEFAULT);
+    }
+
     @Override
     protected HttpRequest parseHead(
             final SessionInputBuffer sessionBuffer)

Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParserFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParserFactory.java?rev=1393136&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParserFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParserFactory.java Tue Oct  2 19:44:35 2012
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * 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.io;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestFactory;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.impl.DefaultHttpRequestFactory;
+import org.apache.http.impl.MessageConstraints;
+import org.apache.http.io.HttpMessageParser;
+import org.apache.http.io.HttpMessageParserFactory;
+import org.apache.http.io.SessionInputBuffer;
+import org.apache.http.message.BasicLineParser;
+import org.apache.http.message.LineParser;
+
+/**
+ * Default factory for request message parsers.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class DefaultHttpRequestParserFactory implements HttpMessageParserFactory<HttpRequest> {
+
+    public static final HttpMessageParserFactory<HttpRequest> INSTANCE = new DefaultHttpRequestParserFactory();
+
+    private final LineParser lineParser;
+    private final HttpRequestFactory requestFactory;
+
+    public DefaultHttpRequestParserFactory(final LineParser lineParser,
+            final HttpRequestFactory requestFactory) {
+        super();
+        this.lineParser = lineParser != null ? lineParser : BasicLineParser.INSTANCE;
+        this.requestFactory = requestFactory != null ? requestFactory
+                : DefaultHttpRequestFactory.INSTANCE;
+    }
+
+    public DefaultHttpRequestParserFactory() {
+        this(null, null);
+    }
+
+    public HttpMessageParser<HttpRequest> create(final SessionInputBuffer buffer,
+            final MessageConstraints constraints) {
+        return new DefaultHttpRequestParser(buffer, lineParser, requestFactory, constraints);
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParserFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParserFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParserFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java Tue Oct  2 19:44:35 2012
@@ -56,6 +56,10 @@ public class DefaultHttpRequestWriter ex
         super(buffer, formatter);
     }
 
+    public DefaultHttpRequestWriter(final SessionOutputBuffer buffer) {
+        this(buffer, null);
+    }
+
     @Override
     protected void writeHeadLine(final HttpRequest message) throws IOException {
         lineFormatter.formatRequestLine(this.lineBuf, message.getRequestLine());

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriterFactory.java (from r1392511, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriterFactory.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriterFactory.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java&r1=1392511&r2=1393136&rev=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriterFactory.java Tue Oct  2 19:44:35 2012
@@ -27,39 +27,37 @@
 
 package org.apache.http.impl.io;
 
-import java.io.IOException;
-
 import org.apache.http.HttpRequest;
-import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.io.HttpMessageWriter;
+import org.apache.http.io.HttpMessageWriterFactory;
 import org.apache.http.io.SessionOutputBuffer;
 import org.apache.http.message.BasicLineFormatter;
 import org.apache.http.message.LineFormatter;
 
 /**
- * HTTP request writer that serializes its output to an instance of {@link SessionOutputBuffer}.
+ * Default factory for request message writers.
  *
  * @since 4.3
  */
-@NotThreadSafe
-public class DefaultHttpRequestWriter extends AbstractMessageWriter<HttpRequest> {
+@Immutable
+public class DefaultHttpRequestWriterFactory implements HttpMessageWriterFactory<HttpRequest> {
+
+    public static final HttpMessageWriterFactory<HttpRequest> INSTANCE = new DefaultHttpRequestWriterFactory();
+
+    private final LineFormatter lineFormatter;
+
+    public DefaultHttpRequestWriterFactory(final LineFormatter lineFormatter) {
+        super();
+        this.lineFormatter = lineFormatter != null ? lineFormatter : BasicLineFormatter.INSTANCE;
+    }
 
-    /**
-     * Creates an instance of DefaultHttpRequestWriter.
-     *
-     * @param buffer the session output buffer.
-     * @param formatter the line formatter If <code>null</code> {@link BasicLineFormatter#INSTANCE}
-     *   will be used.
-     */
-    public DefaultHttpRequestWriter(
-            final SessionOutputBuffer buffer,
-            final LineFormatter formatter) {
-        super(buffer, formatter);
+    public DefaultHttpRequestWriterFactory() {
+        this(null);
     }
 
-    @Override
-    protected void writeHeadLine(final HttpRequest message) throws IOException {
-        lineFormatter.formatRequestLine(this.lineBuf, message.getRequestLine());
-        this.sessionBuffer.writeLine(this.lineBuf);
+    public HttpMessageWriter<HttpRequest> create(final SessionOutputBuffer buffer) {
+        return new DefaultHttpRequestWriter(buffer, lineFormatter);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java Tue Oct  2 19:44:35 2012
@@ -37,6 +37,7 @@ import org.apache.http.ParseException;
 import org.apache.http.StatusLine;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.MessageConstraints;
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.message.BasicLineParser;
 import org.apache.http.message.LineParser;
@@ -84,30 +85,42 @@ public class DefaultHttpResponseParser e
      * Creates new instance of DefaultHttpResponseParser.
      *
      * @param buffer the session input buffer.
-     * @param maxHeaderCount maximum header count limit. If set to a positive value, total number of 
-     *   headers in a message exceeding this limit will cause an I/O error. A negative value will 
-     *   disable the check.
-     * @param maxLineLen maximum line length limit. If set to a positive value, any line exceeding
-     *   this limit will cause an I/O error. A negative value will disable the check.
      * @param parser the line parser. If <code>null</code> {@link BasicLineParser#INSTANCE} 
      *   will be used
      * @param responseFactory the response factory. If <code>null</code> 
      *   {@link DefaultHttpResponseFactory#INSTANCE} will be used. 
+     * @param parser the message constraints. If <code>null</code> {@link MessageConstraints#DEFAULT} 
+     *   will be used.
      * 
      * @since 4.3
      */
     public DefaultHttpResponseParser(
             final SessionInputBuffer buffer,
-            int maxHeaderCount,
-            int maxLineLen,
             final LineParser parser,
-            final HttpResponseFactory responseFactory) {
-        super(buffer, maxHeaderCount, maxLineLen, parser);
+            final HttpResponseFactory responseFactory,
+            final MessageConstraints messageConstraints) {
+        super(buffer, parser, messageConstraints);
         this.responseFactory = responseFactory != null ? responseFactory : 
             DefaultHttpResponseFactory.INSTANCE;
         this.lineBuf = new CharArrayBuffer(128);
     }
 
+    /**
+     * @since 4.3
+     */
+    public DefaultHttpResponseParser(
+            final SessionInputBuffer buffer,
+            final MessageConstraints messageConstraints) {
+        this(buffer, null, null, messageConstraints);
+    }
+
+    /**
+     * @since 4.3
+     */
+    public DefaultHttpResponseParser(final SessionInputBuffer buffer) {
+        this(buffer, null, null, MessageConstraints.DEFAULT);
+    }
+
     @Override
     protected HttpResponse parseHead(
             final SessionInputBuffer sessionBuffer)

Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParserFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParserFactory.java?rev=1393136&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParserFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParserFactory.java Tue Oct  2 19:44:35 2012
@@ -0,0 +1,71 @@
+/*
+ * ====================================================================
+ * 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.io;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.MessageConstraints;
+import org.apache.http.io.HttpMessageParser;
+import org.apache.http.io.HttpMessageParserFactory;
+import org.apache.http.io.SessionInputBuffer;
+import org.apache.http.message.BasicLineParser;
+import org.apache.http.message.LineParser;
+
+/**
+ * Default factory for response message parsers.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class DefaultHttpResponseParserFactory implements HttpMessageParserFactory<HttpResponse> {
+
+    public static final HttpMessageParserFactory<HttpResponse> INSTANCE = new DefaultHttpResponseParserFactory();
+
+    private final LineParser lineParser;
+    private final HttpResponseFactory responseFactory;
+
+    public DefaultHttpResponseParserFactory(final LineParser lineParser,
+            final HttpResponseFactory responseFactory) {
+        super();
+        this.lineParser = lineParser != null ? lineParser : BasicLineParser.INSTANCE;
+        this.responseFactory = responseFactory != null ? responseFactory
+                : DefaultHttpResponseFactory.INSTANCE;
+    }
+
+    public DefaultHttpResponseParserFactory() {
+        this(null, null);
+    }
+
+    public HttpMessageParser<HttpResponse> create(final SessionInputBuffer buffer,
+            final MessageConstraints constraints) {
+        return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParserFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParserFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParserFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java Tue Oct  2 19:44:35 2012
@@ -56,6 +56,10 @@ public class DefaultHttpResponseWriter e
         super(buffer, formatter);
     }
 
+    public DefaultHttpResponseWriter(final SessionOutputBuffer buffer) {
+        super(buffer, null);
+    }
+
     @Override
     protected void writeHeadLine(final HttpResponse message) throws IOException {
         lineFormatter.formatStatusLine(this.lineBuf, message.getStatusLine());

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriterFactory.java (from r1392511, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriterFactory.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriterFactory.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java&r1=1392511&r2=1393136&rev=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriterFactory.java Tue Oct  2 19:44:35 2012
@@ -27,39 +27,37 @@
 
 package org.apache.http.impl.io;
 
-import java.io.IOException;
-
 import org.apache.http.HttpResponse;
-import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.io.HttpMessageWriter;
+import org.apache.http.io.HttpMessageWriterFactory;
 import org.apache.http.io.SessionOutputBuffer;
 import org.apache.http.message.BasicLineFormatter;
 import org.apache.http.message.LineFormatter;
 
 /**
- * HTTP response writer that serializes its output to an instance of {@link SessionOutputBuffer}.
+ * Default factory for response message writers.
  *
  * @since 4.3
  */
-@NotThreadSafe
-public class DefaultHttpResponseWriter extends AbstractMessageWriter<HttpResponse> {
+@Immutable
+public class DefaultHttpResponseWriterFactory implements HttpMessageWriterFactory<HttpResponse> {
+
+    public static final HttpMessageWriterFactory<HttpResponse> INSTANCE = new DefaultHttpResponseWriterFactory();
+
+    private final LineFormatter lineFormatter;
+
+    public DefaultHttpResponseWriterFactory(final LineFormatter lineFormatter) {
+        super();
+        this.lineFormatter = lineFormatter != null ? lineFormatter : BasicLineFormatter.INSTANCE;
+    }
 
-    /**
-     * Creates an instance of DefaultHttpResponseWriter.
-     *
-     * @param buffer the session output buffer.
-     * @param formatter the line formatter If <code>null</code> {@link BasicLineFormatter#INSTANCE}
-     *   will be used.
-     */
-    public DefaultHttpResponseWriter(
-            final SessionOutputBuffer buffer,
-            final LineFormatter formatter) {
-        super(buffer, formatter);
+    public DefaultHttpResponseWriterFactory() {
+        this(null);
     }
 
-    @Override
-    protected void writeHeadLine(final HttpResponse message) throws IOException {
-        lineFormatter.formatStatusLine(this.lineBuf, message.getStatusLine());
-        this.sessionBuffer.writeLine(this.lineBuf);
+    public HttpMessageWriter<HttpResponse> create(final SessionOutputBuffer buffer) {
+        return new DefaultHttpResponseWriter(buffer, lineFormatter);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java Tue Oct  2 19:44:35 2012
@@ -34,7 +34,9 @@ import java.nio.CharBuffer;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 
+import org.apache.http.MessageConstraintException;
 import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.impl.MessageConstraints;
 import org.apache.http.io.BufferInfo;
 import org.apache.http.io.HttpTransportMetrics;
 import org.apache.http.io.SessionInputBuffer;
@@ -61,8 +63,8 @@ public class SessionInputBufferImpl impl
     private final HttpTransportMetricsImpl metrics;
     private final byte[] buffer;
     private final ByteArrayBuffer linebuffer;
-    private final int maxLineLen;
     private final int minChunkLimit;
+    private final MessageConstraints constraints;
     private final CharsetDecoder decoder;
 
     private InputStream instream;
@@ -75,30 +77,30 @@ public class SessionInputBufferImpl impl
      *
      * @param metrics HTTP transport metrics.
      * @param buffersize buffer size. Must be a positive number.
-     * @param maxLineLen maximum line length limit. If set to a positive value, any line exceeding
-     *   this limit will cause an I/O error. A negative value will disable the check.
      * @param minChunkLimit size limit below which data chunks should be buffered in memory
      *   in order to minimize native method invocations on the underlying network socket.
      *   The optimal value of this parameter can be platform specific and defines a trade-off
      *   between performance of memory copy operations and that of native method invocation.
      *   If negative default chunk limited will be used.
+     * @param constraints Message constraints. If <code>null</code> 
+     *   {@link MessageConstraints#DEFAULT} will be used.
      * @param chardecoder chardecoder to be used for decoding HTTP protocol elements.
      *   If <code>null</code> simple type cast will be used for byte to char conversion.
      */
     public SessionInputBufferImpl(
             final HttpTransportMetricsImpl metrics,
             int buffersize,
-            int maxLineLen,
             int minChunkLimit,
+            final MessageConstraints constraints,
             final CharsetDecoder chardecoder) {
-        Args.positive(buffersize, "Buffer size");
         Args.notNull(metrics, "HTTP transport metrcis");
+        Args.positive(buffersize, "Buffer size");
         this.metrics = metrics;
         this.buffer = new byte[buffersize];
         this.bufferpos = 0;
         this.bufferlen = 0;
-        this.maxLineLen = maxLineLen >= 0 ? maxLineLen : -1;
         this.minChunkLimit = minChunkLimit >= 0 ? minChunkLimit : 512;
+        this.constraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
         this.linebuffer = new ByteArrayBuffer(buffersize);
         this.decoder = chardecoder;
     }
@@ -255,8 +257,9 @@ public class SessionInputBufferImpl impl
                     retry = false;
                 }
             }
-            if (this.maxLineLen > 0 && this.linebuffer.length() >= this.maxLineLen) {
-                throw new IOException("Maximum line length limit exceeded");
+            int maxLineLen = this.constraints.getMaxLineLength();
+            if (maxLineLen > 0 && this.linebuffer.length() >= maxLineLen) {
+                throw new MessageConstraintException("Maximum line length limit exceeded");
             }
         }
         if (noRead == -1 && this.linebuffer.isEmpty()) {

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=1393136&r1=1393135&r2=1393136&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 Tue Oct  2 19:44:35 2012
@@ -77,7 +77,8 @@ public class BasicConnFactory implements
     }
 
     protected HttpClientConnection create(final Socket socket, final HttpParams params) throws IOException {
-        DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(params);
+        int bufsize = Config.getInt(params, CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024);
+        DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(bufsize);
         conn.bind(socket);
         return conn;
     }

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java (from r1392511, httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java&p1=httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java&r1=1392511&r2=1393136&rev=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java Tue Oct  2 19:44:35 2012
@@ -24,33 +24,19 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.benchmark;
 
-import java.io.InputStream;
-import java.io.OutputStream;
+package org.apache.http.io;
 
-import org.apache.http.impl.DefaultBHttpClientConnection;
-import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.params.HttpParams;
+import org.apache.http.HttpMessage;
+import org.apache.http.impl.MessageConstraints;
 
-class BenchmarkConnection extends DefaultBHttpClientConnection {
-
-    private final Stats stats;
-    
-    BenchmarkConnection(final Stats stats, final HttpParams params) {
-        super(params);
-        this.stats = stats;
-    }
-
-    @Override
-    protected OutputStream createOutputStream(final long len, final SessionOutputBuffer outbuffer) {
-        return new CountingOutputStream(super.createOutputStream(len, outbuffer), this.stats);
-    }
+/**
+ * Factory for {@link HttpMessageParser} instances.
+ * 
+ * @since 4.3
+ */
+public interface HttpMessageParserFactory<T extends HttpMessage> {
 
-    @Override
-    protected InputStream createInputStream(final long len, final SessionInputBuffer inbuffer) {
-        return new CountingInputStream(super.createInputStream(len, inbuffer), this.stats);
-    }
+    HttpMessageParser<T> create(SessionInputBuffer buffer, MessageConstraints constraints);
 
 }

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageWriterFactory.java (from r1392511, httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageWriterFactory.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageWriterFactory.java&p1=httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java&r1=1392511&r2=1393136&rev=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageWriterFactory.java Tue Oct  2 19:44:35 2012
@@ -24,33 +24,18 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.benchmark;
 
-import java.io.InputStream;
-import java.io.OutputStream;
+package org.apache.http.io;
 
-import org.apache.http.impl.DefaultBHttpClientConnection;
-import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.io.SessionOutputBuffer;
-import org.apache.http.params.HttpParams;
+import org.apache.http.HttpMessage;
 
-class BenchmarkConnection extends DefaultBHttpClientConnection {
-
-    private final Stats stats;
-    
-    BenchmarkConnection(final Stats stats, final HttpParams params) {
-        super(params);
-        this.stats = stats;
-    }
-
-    @Override
-    protected OutputStream createOutputStream(final long len, final SessionOutputBuffer outbuffer) {
-        return new CountingOutputStream(super.createOutputStream(len, outbuffer), this.stats);
-    }
+/**
+ * Factory for {@link HttpMessageWriter} instances.
+ * 
+ * @since 4.3
+ */
+public interface HttpMessageWriterFactory<T extends HttpMessage> {
 
-    @Override
-    protected InputStream createInputStream(final long len, final SessionInputBuffer inbuffer) {
-        return new CountingInputStream(super.createInputStream(len, inbuffer), this.stats);
-    }
+    HttpMessageWriter<T> create(SessionOutputBuffer buffer);
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java Tue Oct  2 19:44:35 2012
@@ -47,33 +47,31 @@ public class SessionInputBufferMock exte
     public SessionInputBufferMock(
             final InputStream instream, 
             int buffersize, 
-            int maxLineLen,
-            int minChunkLimit,
+            final MessageConstraints constrains,
             final CharsetDecoder decoder) {
-        super(new HttpTransportMetricsImpl(), buffersize, maxLineLen, minChunkLimit, decoder);
+        super(new HttpTransportMetricsImpl(), buffersize, -1, constrains, decoder);
         bind(instream);
     }
 
     public SessionInputBufferMock(
             final InputStream instream,
             int buffersize) {
-        this(instream, buffersize, -1, -1, null);
+        this(instream, buffersize, null, null);
     }
 
     public SessionInputBufferMock(
             final byte[] bytes,
             int buffersize,
-            int maxLineLen,
-            int minChunkLimit,
+            final MessageConstraints constrains,
             final CharsetDecoder decoder) {
-        this(new ByteArrayInputStream(bytes), buffersize, maxLineLen, minChunkLimit, decoder);
+        this(new ByteArrayInputStream(bytes), buffersize, constrains, decoder);
     }
 
     public SessionInputBufferMock(
             final byte[] bytes,
             int buffersize,
-            int maxLineLen) {
-        this(new ByteArrayInputStream(bytes), buffersize, maxLineLen, -1, null);
+            final MessageConstraints constrains) {
+        this(new ByteArrayInputStream(bytes), buffersize, constrains, null);
     }
 
     public SessionInputBufferMock(
@@ -89,13 +87,13 @@ public class SessionInputBufferMock exte
 
     public SessionInputBufferMock(
             final byte[] bytes, final Charset charset) {
-        this(bytes, BUFFER_SIZE, -1, -1, charset != null ? charset.newDecoder() : null);
+        this(bytes, BUFFER_SIZE, null, charset != null ? charset.newDecoder() : null);
     }
 
     public SessionInputBufferMock(
             final byte[] bytes, 
             final CharsetDecoder decoder) {
-        this(bytes, BUFFER_SIZE, -1, -1, decoder);
+        this(bytes, BUFFER_SIZE, null, decoder);
     }
 
     public SessionInputBufferMock(

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java Tue Oct  2 19:44:35 2012
@@ -39,10 +39,8 @@ import org.apache.http.Header;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpVersion;
 import org.apache.http.RequestLine;
-import org.apache.http.impl.DefaultHttpRequestFactory;
 import org.apache.http.impl.SessionInputBufferMock;
 import org.apache.http.io.SessionInputBuffer;
-import org.apache.http.message.BasicLineParser;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -51,18 +49,9 @@ import org.junit.Test;
  */
 public class TestRequestParser {
 
-    @Test
+    @Test(expected=IllegalArgumentException.class)
     public void testInvalidConstructorInput() throws Exception {
-        try {
-            new DefaultHttpRequestParser(
-                    null,
-                    -1, -1,
-                    BasicLineParser.INSTANCE,
-                    DefaultHttpRequestFactory.INSTANCE);
-            Assert.fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
+        new DefaultHttpRequestParser(null);
     }
 
     @Test
@@ -75,12 +64,7 @@ public class TestRequestParser {
             "\r\n";
         SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
 
-        DefaultHttpRequestParser parser = new DefaultHttpRequestParser(
-                inbuffer,
-                -1, -1,
-                BasicLineParser.INSTANCE,
-                DefaultHttpRequestFactory.INSTANCE);
-
+        DefaultHttpRequestParser parser = new DefaultHttpRequestParser(inbuffer);
         HttpRequest httprequest = parser.parse();
 
         RequestLine reqline = httprequest.getRequestLine();
@@ -96,12 +80,7 @@ public class TestRequestParser {
     public void testConnectionClosedException() throws Exception {
         SessionInputBuffer inbuffer = new SessionInputBufferMock(new byte[] {});
 
-        DefaultHttpRequestParser parser = new DefaultHttpRequestParser(
-                inbuffer,
-                -1, -1,
-                BasicLineParser.INSTANCE,
-                DefaultHttpRequestFactory.INSTANCE);
-
+        DefaultHttpRequestParser parser = new DefaultHttpRequestParser(inbuffer);
         try {
             parser.parse();
             Assert.fail("ConnectionClosedException should have been thrown");
@@ -120,11 +99,7 @@ public class TestRequestParser {
         SessionInputBuffer inbuffer = new SessionInputBufferMock(
                 new TimeoutByteArrayInputStream(s.getBytes("US-ASCII")), 16);
 
-        DefaultHttpRequestParser parser = new DefaultHttpRequestParser(
-                inbuffer,
-                -1, -1,
-                BasicLineParser.INSTANCE,
-                DefaultHttpRequestFactory.INSTANCE);
+        DefaultHttpRequestParser parser = new DefaultHttpRequestParser(inbuffer);
 
         int timeoutCount = 0;