hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1393136 [1/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...
Date Tue, 02 Oct 2012 19:44:37 GMT
Author: olegk
Date: Tue Oct  2 19:44:35 2012
New Revision: 1393136

URL: http://svn.apache.org/viewvc?rev=1393136&view=rev
Log:
Configuration API changes: default HTTP connection classes now use constructor parameters for configuration instead of HttpParams

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParserFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriterFactory.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParserFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriterFactory.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageParserFactory.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageWriterFactory.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageConstraintException.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/MessageConstraints.java   (with props)
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParserFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriterFactory.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParserFactory.java   (with props)
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriterFactory.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageParserFactory.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/io/HttpMessageWriterFactory.java
      - copied, changed from r1392511, httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java
Modified:
    httpcomponents/httpcore/trunk/.gitignore
    httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java
    httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
    httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java
    httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/SmokeTest.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
    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/DefaultNHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java
    httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java
    httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java
    httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java
    httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestParser.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpRequestWriter.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseParser.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/DefaultHttpResponseWriter.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/pool/BasicConnFactory.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestRequestParser.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestResponseParser.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/io/TestSessionInOutBuffers.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/HttpServer.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpServerConnection.java

Modified: httpcomponents/httpcore/trunk/.gitignore
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/.gitignore?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/.gitignore (original)
+++ httpcomponents/httpcore/trunk/.gitignore Tue Oct  2 19:44:35 2012
@@ -1,5 +1,6 @@
 .classpath
 .project
 .settings
+.pydevproject
 target
 maven-eclipse.xml

Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkConnection.java Tue Oct  2 19:44:35 2012
@@ -32,14 +32,13 @@ import java.io.OutputStream;
 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);
+    BenchmarkConnection(int bufsize, final Stats stats) {
+        super(bufsize);
         this.stats = stats;
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java Tue Oct  2 19:44:35 2012
@@ -110,9 +110,11 @@ class BenchmarkWorker implements Runnabl
     }
 
     public void run() {
+        HttpParams params = request.getParams();
 
         HttpResponse response = null;
-        BenchmarkConnection conn = new BenchmarkConnection(stats, request.getParams());
+        int bufsize = Config.getInt(params, CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024);
+        BenchmarkConnection conn = new BenchmarkConnection(bufsize, stats);
 
         String scheme = targetHost.getSchemeName();
         String hostname = targetHost.getHostName();
@@ -144,7 +146,6 @@ class BenchmarkWorker implements Runnabl
                         socket = new Socket();
                     }
                     
-                    HttpParams params = request.getParams();
                     int connTimeout = Config.getInt(params, CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
                     int soTimeout = Config.getInt(params, CoreConnectionPNames.SO_TIMEOUT, 0);
 

Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/HttpServer.java Tue Oct  2 19:44:35 2012
@@ -85,7 +85,7 @@ public class HttpServer {
 
     private HttpServerConnection acceptConnection() throws IOException {
         Socket socket = this.serversocket.accept();
-        DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(this.params);
+        DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(8 * 1024);
         conn.bind(socket);
         return conn;
     }

Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/SmokeTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/SmokeTest.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/SmokeTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-ab/src/test/java/org/apache/http/benchmark/SmokeTest.java Tue Oct  2 19:44:35 2012
@@ -27,7 +27,6 @@ public class SmokeTest {
         HttpParams params = new HttpCoreConfigBuilder()
             .setConnectTimeout(5000)
             .setSocketTimeout(5000)
-            .setSocketBufferSize(8 * 1024)
             .setOriginServer("TEST-SERVER/1.1").build();
         server = new HttpServer(params);
         server.registerHandler("/", new HttpRequestHandler() {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java Tue Oct  2 19:44:35 2012
@@ -29,6 +29,8 @@ package org.apache.http.impl.nio;
 
 import java.io.IOException;
 import java.nio.channels.SelectionKey;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
@@ -37,34 +39,35 @@ 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.entity.ContentLengthStrategy;
+import org.apache.http.impl.MessageConstraints;
+import org.apache.http.impl.entity.LaxContentLengthStrategy;
+import org.apache.http.impl.entity.StrictContentLengthStrategy;
 import org.apache.http.impl.nio.codecs.DefaultHttpRequestWriter;
+import org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory;
 import org.apache.http.impl.nio.codecs.DefaultHttpResponseParser;
+import org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory;
 import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.nio.NHttpClientEventHandler;
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpMessageParser;
+import org.apache.http.nio.NHttpMessageParserFactory;
 import org.apache.http.nio.NHttpMessageWriter;
+import org.apache.http.nio.NHttpMessageWriterFactory;
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.SessionInputBuffer;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
 import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.params.Config;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
 
 /**
  * Default implementation of the {@link NHttpClientConnection} interface.
- * <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.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
- * </ul>
  *
  * @since 4.0
  */
@@ -83,7 +86,12 @@ public class DefaultNHttpClientConnectio
      * @param responseFactory HTTP response factory.
      * @param allocator byte buffer allocator.
      * @param params HTTP parameters.
+     *
+     * @deprecated (4.3) use {@link DefaultNHttpClientConnection#DefaultNHttpClientConnection(
+     *  IOSession, int, ByteBufferAllocator, CharsetDecoder, CharsetEncoder, MessageConstraints,
+     *  ContentLengthStrategy, ContentLengthStrategy, NHttpMessageWriterFactory, NHttpMessageParserFactory)}
      */
+    @Deprecated
     public DefaultNHttpClientConnection(
             final IOSession session,
             final HttpResponseFactory responseFactory,
@@ -99,6 +107,65 @@ public class DefaultNHttpClientConnectio
     }
 
     /**
+     * Creates new instance DefaultNHttpClientConnection given the underlying I/O session.
+     *
+     * @param session the underlying I/O session.
+     * @param buffersize buffer size. Must be a positive number.
+     * @param allocator memory allocator.
+     *   If <code>null</code> {@link HeapByteBufferAllocator#INSTANCE} will be used.
+     * @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.
+     *
+     * @since 4.3
+     */
+    public DefaultNHttpClientConnection(
+            final IOSession session,
+            int buffersize,
+            final ByteBufferAllocator allocator,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints,
+            final ContentLengthStrategy incomingContentStrategy,
+            final ContentLengthStrategy outgoingContentStrategy,
+            final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+            final NHttpMessageParserFactory<HttpResponse> responseParserFactory) {
+        super(session, buffersize, allocator, chardecoder, charencoder, constraints,
+                incomingContentStrategy, outgoingContentStrategy);
+        this.requestWriter = (requestWriterFactory != null ? requestWriterFactory :
+            DefaultHttpRequestWriterFactory.INSTANCE).create(this.outbuf);
+        this.responseParser = (responseParserFactory != null ? responseParserFactory :
+            DefaultHttpResponseParserFactory.INSTANCE).create(this.inbuf, constraints);
+    }
+
+    /**
+     * @since 4.3
+     */
+    public DefaultNHttpClientConnection(
+            final IOSession session,
+            int buffersize,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints) {
+        this(session, buffersize, null, chardecoder, charencoder, constraints,
+                null, null, null, null);
+    }
+
+    /**
+     * @since 4.3
+     */
+    public DefaultNHttpClientConnection(final IOSession session, int buffersize) {
+        this(session, buffersize, null, null, null, null, null, null, null, null);
+    }
+
+    /**
      * Creates an instance of {@link NHttpMessageParser} to be used
      * by this connection for parsing incoming {@link HttpResponse} messages.
      * <p>
@@ -106,15 +173,20 @@ public class DefaultNHttpClientConnectio
      * a different implementation of the {@link NHttpMessageParser} interface.
      *
      * @return HTTP response parser.
+     *
+     * @deprecated (4.3) use constructor.
      */
+    @Deprecated
     protected NHttpMessageParser<HttpResponse> createResponseParser(
             final SessionInputBuffer buffer,
             final HttpResponseFactory responseFactory,
             final HttpParams params) {
         // override in derived class to specify a line parser
-        int maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        int maxHeaderCount = params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1);
-        return new DefaultHttpResponseParser(buffer, maxHeaderCount, maxLineLen, null, responseFactory);
+        MessageConstraints constraints = MessageConstraints.custom()
+                .setMaxLineLength(Config.getInt(params, CoreConnectionPNames.MAX_LINE_LENGTH, -1))
+                .setMaxHeaderCount(Config.getInt(params, CoreConnectionPNames.MAX_HEADER_COUNT, -1))
+                .build();
+        return new DefaultHttpResponseParser(buffer, null, responseFactory, constraints);
     }
 
     /**
@@ -125,7 +197,10 @@ public class DefaultNHttpClientConnectio
      * a different implementation of the {@link NHttpMessageWriter} interface.
      *
      * @return HTTP response parser.
+     *
+     * @deprecated (4.3) use constructor.
      */
+    @Deprecated
     protected NHttpMessageWriter<HttpRequest> createRequestWriter(
             final SessionOutputBuffer buffer,
             final HttpParams params) {
@@ -138,13 +213,13 @@ public class DefaultNHttpClientConnectio
      */
     protected void onResponseReceived(final HttpResponse response) {
     }
-    
+
     /**
      * @since 4.2
      */
     protected void onRequestSubmitted(final HttpRequest request) {
     }
-    
+
     public void resetInput() {
         this.response = null;
         this.contentDecoder = null;

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=1393136&r1=1393135&r2=1393136&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 Tue Oct  2 19:44:35 2012
@@ -88,7 +88,7 @@ public class DefaultNHttpClientConnectio
     }
 
     public DefaultNHttpClientConnection createConnection(final IOSession session) {
-        DefaultNHttpClientConnection conn = createConnection(session, this.responseFactory, 
+        DefaultNHttpClientConnection conn = createConnection(session, this.responseFactory,
                 this.allocator, this.params);
         int timeout = Config.getInt(this.params, CoreConnectionPNames.SO_TIMEOUT, 0);
         conn.setSocketTimeout(timeout);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java Tue Oct  2 19:44:35 2012
@@ -29,6 +29,8 @@ package org.apache.http.impl.nio;
 
 import java.io.IOException;
 import java.nio.channels.SelectionKey;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
@@ -38,12 +40,18 @@ import org.apache.http.HttpRequestFactor
 import org.apache.http.HttpResponse;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.impl.MessageConstraints;
 import org.apache.http.impl.entity.DisallowIdentityContentLengthStrategy;
 import org.apache.http.impl.entity.LaxContentLengthStrategy;
+import org.apache.http.impl.entity.StrictContentLengthStrategy;
 import org.apache.http.impl.nio.codecs.DefaultHttpRequestParser;
+import org.apache.http.impl.nio.codecs.DefaultHttpRequestParserFactory;
 import org.apache.http.impl.nio.codecs.DefaultHttpResponseWriter;
+import org.apache.http.impl.nio.codecs.DefaultHttpResponseWriterFactory;
 import org.apache.http.nio.NHttpMessageParser;
+import org.apache.http.nio.NHttpMessageParserFactory;
 import org.apache.http.nio.NHttpMessageWriter;
+import org.apache.http.nio.NHttpMessageWriterFactory;
 import org.apache.http.nio.NHttpServerConnection;
 import org.apache.http.nio.NHttpServerEventHandler;
 import org.apache.http.nio.NHttpServerIOTarget;
@@ -53,21 +61,14 @@ import org.apache.http.nio.reactor.IOSes
 import org.apache.http.nio.reactor.SessionInputBuffer;
 import org.apache.http.nio.reactor.SessionOutputBuffer;
 import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.params.Config;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
 
 /**
  * Default implementation of the {@link NHttpServerConnection} interface.
- * <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.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li>
- *  <li>{@link org.apache.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li>
- * </ul>
  *
  * @since 4.0
  */
@@ -86,7 +87,12 @@ public class DefaultNHttpServerConnectio
      * @param requestFactory HTTP request factory.
      * @param allocator byte buffer allocator.
      * @param params HTTP parameters.
+     *
+     * @deprecated (4.3) use {@link DefaultNHttpServerConnection#DefaultNHttpServerConnection(
+     *  IOSession, int, ByteBufferAllocator, CharsetDecoder, CharsetEncoder, MessageConstraints,
+     *  ContentLengthStrategy, ContentLengthStrategy, NHttpMessageParserFactory, NHttpMessageWriterFactory)}
      */
+    @Deprecated
     public DefaultNHttpServerConnection(
             final IOSession session,
             final HttpRequestFactory requestFactory,
@@ -98,7 +104,75 @@ public class DefaultNHttpServerConnectio
         this.responseWriter = createResponseWriter(this.outbuf, params);
     }
 
+    /**
+     * Creates new instance DefaultNHttpServerConnection given the underlying I/O session.
+     *
+     * @param session the underlying I/O session.
+     * @param buffersize buffer size. Must be a positive number.
+     * @param allocator memory allocator.
+     *   If <code>null</code> {@link HeapByteBufferAllocator#INSTANCE} will be used.
+     * @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.
+     *
+     * @since 4.3
+     */
+    public DefaultNHttpServerConnection(
+            final IOSession session,
+            int buffersize,
+            final ByteBufferAllocator allocator,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints,
+            final ContentLengthStrategy incomingContentStrategy,
+            final ContentLengthStrategy outgoingContentStrategy,
+            final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+            final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory) {
+        super(session, buffersize, allocator, chardecoder, charencoder, constraints,
+                incomingContentStrategy != null ? incomingContentStrategy :
+                    DisallowIdentityContentLengthStrategy.INSTANCE, outgoingContentStrategy);
+        this.requestParser = (requestParserFactory != null ? requestParserFactory :
+            DefaultHttpRequestParserFactory.INSTANCE).create(this.inbuf, constraints);
+        this.responseWriter = (responseWriterFactory != null ? responseWriterFactory :
+            DefaultHttpResponseWriterFactory.INSTANCE).create(this.outbuf);
+    }
+
+    /**
+     * @since 4.3
+     */
+    public DefaultNHttpServerConnection(
+            final IOSession session,
+            int buffersize,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints) {
+        this(session, buffersize, null, chardecoder, charencoder, constraints,
+                null, null, null, null);
+    }
+
+    /**
+     * @since 4.3
+     */
+    public DefaultNHttpServerConnection(final IOSession session, int buffersize) {
+        this(session, buffersize, null, null, null, null, null, null, null, null);
+    }
+
+    /**
+     * @deprecated (4.3) use constructor.
+     */
     @Override
+    @Deprecated
     protected ContentLengthStrategy createIncomingContentStrategy() {
         return new DisallowIdentityContentLengthStrategy(new LaxContentLengthStrategy(0));
     }
@@ -111,14 +185,19 @@ public class DefaultNHttpServerConnectio
      * a different implementation of the {@link NHttpMessageParser} interface.
      *
      * @return HTTP response parser.
+     *
+     * @deprecated (4.3) use constructor.
      */
+    @Deprecated
     protected NHttpMessageParser<HttpRequest> createRequestParser(
             final SessionInputBuffer buffer,
             final HttpRequestFactory requestFactory,
             final HttpParams params) {
-        int maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        int maxHeaderCount = params.getIntParameter(CoreConnectionPNames.MAX_HEADER_COUNT, -1);
-        return new DefaultHttpRequestParser(buffer, maxHeaderCount, maxLineLen, null, requestFactory);
+        MessageConstraints constraints = MessageConstraints.custom()
+                .setMaxLineLength(Config.getInt(params, CoreConnectionPNames.MAX_LINE_LENGTH, -1))
+                .setMaxHeaderCount(Config.getInt(params, CoreConnectionPNames.MAX_HEADER_COUNT, -1))
+                .build();
+        return new DefaultHttpRequestParser(buffer, null, requestFactory, constraints);
     }
 
     /**
@@ -130,7 +209,10 @@ public class DefaultNHttpServerConnectio
      * a different implementation of the {@link NHttpMessageWriter} interface.
      *
      * @return HTTP response parser.
+     *
+     * @deprecated (4.3) use constructor.
      */
+    @Deprecated
     protected NHttpMessageWriter<HttpResponse> createResponseWriter(
             final SessionOutputBuffer buffer,
             final HttpParams params) {
@@ -143,13 +225,13 @@ public class DefaultNHttpServerConnectio
      */
     protected void onRequestReceived(final HttpRequest request) {
     }
-    
+
     /**
      * @since 4.2
      */
     protected void onResponseSubmitted(final HttpResponse response) {
     }
-    
+
     public void resetInput() {
         this.request = null;
         this.contentDecoder = null;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java Tue Oct  2 19:44:35 2012
@@ -53,6 +53,7 @@ import org.apache.http.annotation.NotThr
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.entity.ContentLengthStrategy;
 import org.apache.http.impl.HttpConnectionMetricsImpl;
+import org.apache.http.impl.MessageConstraints;
 import org.apache.http.impl.entity.LaxContentLengthStrategy;
 import org.apache.http.impl.entity.StrictContentLengthStrategy;
 import org.apache.http.impl.io.HttpTransportMetricsImpl;
@@ -75,9 +76,10 @@ import org.apache.http.nio.reactor.Sessi
 import org.apache.http.nio.reactor.SessionOutputBuffer;
 import org.apache.http.nio.reactor.SocketAccessor;
 import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.params.Config;
 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.protocol.HttpContext;
@@ -88,13 +90,6 @@ import org.apache.http.util.NetUtils;
 /**
  * This class serves as a base for all {@link NHttpConnection} 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.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li>
- * </ul>
  *
  * @since 4.0
  */
@@ -130,7 +125,12 @@ public class NHttpConnectionBase
      * @param session the underlying I/O session.
      * @param allocator byte buffer allocator.
      * @param params HTTP parameters.
+     *
+     * @deprecated (4.3) use
+     *   {@link NHttpConnectionBase#NHttpConnectionBase(IOSession, int, ByteBufferAllocator,
+     *   CharsetDecoder, CharsetEncoder, MessageConstraints, ContentLengthStrategy, ContentLengthStrategy)}
      */
+    @Deprecated
     public NHttpConnectionBase(
             final IOSession session,
             final ByteBufferAllocator allocator,
@@ -150,7 +150,7 @@ public class NHttpConnectionBase
 
         CharsetDecoder decoder = null;
         CharsetEncoder encoder = null;
-        Charset charset = CharsetUtils.lookup(Config.getString(params, 
+        Charset charset = CharsetUtils.lookup(Config.getString(params,
                 CoreProtocolPNames.HTTP_ELEMENT_CHARSET));
         if (charset != null) {
             charset = Consts.ASCII;
@@ -181,6 +181,56 @@ public class NHttpConnectionBase
         this.status = ACTIVE;
     }
 
+    /**
+     * Creates new instance NHttpConnectionBase given the underlying I/O session.
+     *
+     * @param session the underlying I/O session.
+     * @param buffersize buffer size. Must be a positive number.
+     * @param allocator memory allocator.
+     *   If <code>null</code> {@link HeapByteBufferAllocator#INSTANCE} will be used.
+     * @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.
+     *
+     * @since 4.3
+     */
+    protected NHttpConnectionBase(
+            final IOSession session,
+            int buffersize,
+            final ByteBufferAllocator allocator,
+            final CharsetDecoder chardecoder,
+            final CharsetEncoder charencoder,
+            final MessageConstraints constraints,
+            final ContentLengthStrategy incomingContentStrategy,
+            final ContentLengthStrategy outgoingContentStrategy) {
+        Args.notNull(session, "I/O session");
+        Args.positive(buffersize, "Buffer size");
+        int linebuffersize = buffersize;
+        if (linebuffersize > 512) {
+            linebuffersize = 512;
+        }
+        this.inbuf = new SessionInputBufferImpl(buffersize, linebuffersize, chardecoder, allocator);
+        this.outbuf = new SessionOutputBufferImpl(buffersize, linebuffersize, charencoder, allocator);
+
+        this.inTransportMetrics = new HttpTransportMetricsImpl();
+        this.outTransportMetrics = new HttpTransportMetricsImpl();
+        this.connMetrics = new HttpConnectionMetricsImpl(this.inTransportMetrics, this.outTransportMetrics);
+        this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
+            LaxContentLengthStrategy.INSTANCE;
+        this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
+            StrictContentLengthStrategy.INSTANCE;
+
+        setSession(session);
+        this.status = ACTIVE;
+    }
+
     private void setSession(final IOSession session) {
         this.session = session;
         this.context = new SessionHttpContext(this.session);
@@ -202,28 +252,40 @@ public class NHttpConnectionBase
 
     /**
      * @since 4.2
+     *
+     * @deprecated (4.3) use constructor.
      */
+    @Deprecated
     protected ContentLengthStrategy createIncomingContentStrategy() {
         return new LaxContentLengthStrategy();
     }
 
     /**
      * @since 4.2
+     *
+     * @deprecated (4.3) use constructor.
      */
+    @Deprecated
     protected ContentLengthStrategy createOutgoingContentStrategy() {
         return new StrictContentLengthStrategy();
     }
 
     /**
      * @since 4.1
+     *
+     * @deprecated (4.3) no longer used.
      */
+    @Deprecated
     protected HttpTransportMetricsImpl createTransportMetrics() {
         return new HttpTransportMetricsImpl();
     }
 
     /**
      * @since 4.1
+     *
+     * @deprecated (4.3) use decorator to add additional metrics.
      */
+    @Deprecated
     protected HttpConnectionMetricsImpl createConnectionMetrics(
             final HttpTransportMetrics inTransportMetric,
             final HttpTransportMetrics outTransportMetric) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java Tue Oct  2 19:44:35 2012
@@ -34,13 +34,16 @@ import java.util.List;
 
 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.message.BasicLineParser;
 import org.apache.http.message.LineParser;
 import org.apache.http.nio.NHttpMessageParser;
 import org.apache.http.nio.reactor.SessionInputBuffer;
+import org.apache.http.params.Config;
 import org.apache.http.params.CoreConnectionPNames;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.Args;
@@ -68,9 +71,8 @@ public abstract class AbstractMessagePar
     private CharArrayBuffer lineBuf;
     private final List<CharArrayBuffer> headerBufs;
 
-    private int maxLineLen = -1;
-    private int maxHeaderCount = -1;
     protected final LineParser lineParser;
+    private final MessageConstraints constraints;
 
     /**
      * Creates an instance of this class.
@@ -78,12 +80,12 @@ public abstract class AbstractMessagePar
      * @param buffer the session input buffer.
      * @param parser the line parser.
      * @param params HTTP parameters.
-     * 
-     * @deprecated (4.3) use 
+     *
+     * @deprecated (4.3) use
      *   {@link AbstractMessageParser#AbstractMessageParser(SessionInputBuffer, int, int, LineParser)}
      */
     @Deprecated
-    public AbstractMessageParser(final SessionInputBuffer buffer, final LineParser parser, 
+    public AbstractMessageParser(final SessionInputBuffer buffer, final LineParser parser,
             final HttpParams params) {
         super();
         Args.notNull(buffer, "Session input buffer");
@@ -92,10 +94,10 @@ public abstract class AbstractMessagePar
         this.state = READ_HEAD_LINE;
         this.endOfStream = false;
         this.headerBufs = new ArrayList<CharArrayBuffer>();
-        this.maxLineLen = params.getIntParameter(
-                CoreConnectionPNames.MAX_LINE_LENGTH, -1);
-        this.maxHeaderCount = params.getIntParameter(
-                CoreConnectionPNames.MAX_HEADER_COUNT, -1);
+        this.constraints = MessageConstraints.custom()
+                .setMaxLineLength(Config.getInt(params, CoreConnectionPNames.MAX_LINE_LENGTH, -1))
+                .setMaxHeaderCount(Config.getInt(params, CoreConnectionPNames.MAX_HEADER_COUNT, -1))
+                .build();
         this.lineParser = (parser != null) ? parser : BasicLineParser.INSTANCE;
     }
 
@@ -103,26 +105,21 @@ public abstract class AbstractMessagePar
      * Creates an 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. 
-     * 
+     *   be used.
+     * @param constraints 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 SessionInputBuffer buffer,
+            final LineParser parser,
+            final MessageConstraints constraints) {
         super();
         this.sessionBuffer = Args.notNull(buffer, "Session input buffer");
-        this.maxHeaderCount = maxHeaderCount;
-        this.maxLineLen = maxLineLen;
-        this.lineParser = (parser != null) ? parser : BasicLineParser.INSTANCE;
+        this.lineParser = parser != null ? parser : BasicLineParser.INSTANCE;
+        this.constraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
         this.headerBufs = new ArrayList<CharArrayBuffer>();
         this.state = READ_HEAD_LINE;
         this.endOfStream = false;
@@ -173,9 +170,9 @@ public abstract class AbstractMessagePar
                 }
                 i++;
             }
-            if (this.maxLineLen > 0
-                    && previous.length() + 1 + current.length() - i > this.maxLineLen) {
-                throw new IOException("Maximum line length limit exceeded");
+            int maxLineLen = this.constraints.getMaxLineLength();
+            if (maxLineLen > 0 && previous.length() + 1 + current.length() - i > maxLineLen) {
+                throw new MessageConstraintException("Maximum line length limit exceeded");
             }
             previous.append(' ');
             previous.append(current, i, current.length() - i);
@@ -193,10 +190,11 @@ public abstract class AbstractMessagePar
                 this.lineBuf.clear();
             }
             boolean lineComplete = this.sessionBuffer.readLine(this.lineBuf, this.endOfStream);
-            if (this.maxLineLen > 0 &&
-                    (this.lineBuf.length() > this.maxLineLen ||
-                            (!lineComplete && this.sessionBuffer.length() > this.maxLineLen))) {
-                throw new IOException("Maximum line length limit exceeded");
+            int maxLineLen = this.constraints.getMaxLineLength();
+            if (maxLineLen > 0 &&
+                    (this.lineBuf.length() > maxLineLen ||
+                            (!lineComplete && this.sessionBuffer.length() > maxLineLen))) {
+                throw new MessageConstraintException("Maximum line length limit exceeded");
             }
             if (!lineComplete) {
                 break;
@@ -213,8 +211,9 @@ public abstract class AbstractMessagePar
                 break;
             case READ_HEADERS:
                 if (this.lineBuf.length() > 0) {
-                    if (this.maxHeaderCount > 0 && headerBufs.size() >= this.maxHeaderCount) {
-                        throw new IOException("Maximum header count exceeded");
+                    int maxHeaderCount = this.constraints.getMaxHeaderCount();
+                    if (maxHeaderCount > 0 && headerBufs.size() >= maxHeaderCount) {
+                        throw new MessageConstraintException("Maximum header count exceeded");
                     }
 
                     parseHeader();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageWriter.java Tue Oct  2 19:44:35 2012
@@ -61,8 +61,8 @@ public abstract class AbstractMessageWri
      * @param buffer the session output buffer.
      * @param formatter the line formatter.
      * @param params HTTP parameters.
-     * 
-     * @deprecated (4.3) use 
+     *
+     * @deprecated (4.3) use
      *   {@link AbstractMessageWriter#AbstractMessageWriter(SessionOutputBuffer, LineFormatter)}
      */
     @Deprecated
@@ -82,7 +82,7 @@ public abstract class AbstractMessageWri
      * @param buffer the session output buffer.
      * @param formatter the line formatter If <code>null</code> {@link BasicLineFormatter#INSTANCE}
      *   will be used.
-     * 
+     *
      * @since 4.3
      */
     public AbstractMessageWriter(

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.java Tue Oct  2 19:44:35 2012
@@ -34,6 +34,7 @@ import org.apache.http.ParseException;
 import org.apache.http.RequestLine;
 import org.apache.http.annotation.NotThreadSafe;
 import org.apache.http.impl.DefaultHttpRequestFactory;
+import org.apache.http.impl.MessageConstraints;
 import org.apache.http.message.BasicLineParser;
 import org.apache.http.message.LineParser;
 import org.apache.http.message.ParserCursor;
@@ -59,9 +60,10 @@ public class DefaultHttpRequestParser ex
      * @param buffer the session input buffer.
      * @param parser the line parser.
      * @param params HTTP parameters.
-     * 
-     * @deprecated (4.3) use 
-     *   {@link DefaultHttpRequestParser#DefaultHttpRequestParser(SessionInputBuffer, int, int, LineParser, HttpRequestFactory)}
+     *
+     * @deprecated (4.3) use
+     *   {@link DefaultHttpRequestParser#DefaultHttpRequestParser(
+     *   SessionInputBuffer, LineParser, HttpRequestFactory, MessageConstraints)}
      */
     @Deprecated
     public DefaultHttpRequestParser(
@@ -78,35 +80,38 @@ public class DefaultHttpRequestParser ex
      * Creates an 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 requestFactory the request factory. If <code>null</code> 
+     *   be used.
+     * @param requestFactory the request factory. If <code>null</code>
      *   {@link DefaultHttpRequestFactory#INSTANCE} will be used.
-     * 
+     * @param constraints 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 constraints) {
+        super(buffer, parser, constraints);
         this.requestFactory = requestFactory != null ? requestFactory : DefaultHttpRequestFactory.INSTANCE;
     }
 
     /**
     * @since 4.3
     */
+    public DefaultHttpRequestParser(final SessionInputBuffer buffer, final MessageConstraints constraints) {
+        this(buffer, null, null, constraints);
+    }
+
+    /**
+    * @since 4.3
+    */
     public DefaultHttpRequestParser(final SessionInputBuffer buffer) {
-        this(buffer, -1, -1, null, null);
+        this(buffer, null);
     }
-    
+
     @Override
     protected HttpRequest createMessage(final CharArrayBuffer buffer)
             throws HttpException, ParseException {

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParserFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParserFactory.java?rev=1393136&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestParserFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/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.nio.codecs;
+
+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.message.BasicLineParser;
+import org.apache.http.message.LineParser;
+import org.apache.http.nio.NHttpMessageParser;
+import org.apache.http.nio.NHttpMessageParserFactory;
+import org.apache.http.nio.reactor.SessionInputBuffer;
+
+/**
+ * Default factory for request message parsers.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class DefaultHttpRequestParserFactory implements NHttpMessageParserFactory<HttpRequest> {
+
+    public static final NHttpMessageParserFactory<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 NHttpMessageParser<HttpRequest> create(final SessionInputBuffer buffer,
+            final MessageConstraints constraints) {
+        return new DefaultHttpRequestParser(buffer, lineParser, requestFactory, constraints);
+    }
+
+}

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

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

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

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriter.java Tue Oct  2 19:44:35 2012
@@ -47,7 +47,7 @@ import org.apache.http.util.CharArrayBuf
 public class DefaultHttpRequestWriter extends AbstractMessageWriter<HttpRequest> {
 
     /**
-     * @deprecated (4.3) use 
+     * @deprecated (4.3) use
      *   {@link DefaultHttpRequestWriter#DefaultHttpRequestWriter(SessionOutputBuffer, LineFormatter)}
      */
     @Deprecated
@@ -57,14 +57,14 @@ public class DefaultHttpRequestWriter ex
         super(buffer, formatter, params);
     }
 
-    
+
     /**
      * 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.
-     * 
+     *
      * @since 4.3
      */
     public DefaultHttpRequestWriter(

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/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-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriterFactory.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/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-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriterFactory.java Tue Oct  2 19:44:35 2012
@@ -25,41 +25,39 @@
  *
  */
 
-package org.apache.http.impl.io;
-
-import java.io.IOException;
+package org.apache.http.impl.nio.codecs;
 
 import org.apache.http.HttpRequest;
-import org.apache.http.annotation.NotThreadSafe;
-import org.apache.http.io.SessionOutputBuffer;
+import org.apache.http.annotation.Immutable;
 import org.apache.http.message.BasicLineFormatter;
 import org.apache.http.message.LineFormatter;
+import org.apache.http.nio.NHttpMessageWriter;
+import org.apache.http.nio.NHttpMessageWriterFactory;
+import org.apache.http.nio.reactor.SessionOutputBuffer;
 
 /**
- * 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 NHttpMessageWriterFactory<HttpRequest> {
+
+    public static final NHttpMessageWriterFactory<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 NHttpMessageWriter<HttpRequest> create(final SessionOutputBuffer buffer) {
+        return new DefaultHttpRequestWriter(buffer, lineFormatter);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParser.java Tue Oct  2 19:44:35 2012
@@ -34,6 +34,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.message.BasicLineParser;
 import org.apache.http.message.LineParser;
 import org.apache.http.message.ParserCursor;
@@ -54,8 +55,9 @@ public class DefaultHttpResponseParser e
     private final HttpResponseFactory responseFactory;
 
     /**
-     * @deprecated (4.3) use 
-     *   {@link DefaultHttpResponseParser#DefaultHttpResponseParser(SessionInputBuffer, int, int, LineParser, HttpResponseFactory)}
+     * @deprecated (4.3) use
+     *   {@link DefaultHttpResponseParser#DefaultHttpResponseParser(
+     *   SessionInputBuffer, LineParser, HttpResponseFactory, MessageConstraints)}
      */
     @Deprecated
     public DefaultHttpResponseParser(
@@ -72,34 +74,37 @@ public class DefaultHttpResponseParser e
      * Creates an 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. 
-     * 
+     *   be used.
+     * @param responseFactory the response factory. If <code>null</code>
+     *   {@link DefaultHttpResponseFactory#INSTANCE} will be used.
+     * @param constraints 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);
-        this.responseFactory = responseFactory != null ? responseFactory : 
+            final HttpResponseFactory responseFactory,
+            final MessageConstraints constraints) {
+        super(buffer, parser, constraints);
+        this.responseFactory = responseFactory != null ? responseFactory :
             DefaultHttpResponseFactory.INSTANCE;
     }
 
     /**
      * @since 4.3
      */
+    public DefaultHttpResponseParser(final SessionInputBuffer buffer, final MessageConstraints constraints) {
+        this(buffer, null, null, constraints);
+    }
+
+    /**
+     * @since 4.3
+     */
     public DefaultHttpResponseParser(final SessionInputBuffer buffer) {
-        this(buffer, -1, -1, null, null);
+        this(buffer, null);
     }
 
     @Override

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParserFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParserFactory.java?rev=1393136&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseParserFactory.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/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.nio.codecs;
+
+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.message.BasicLineParser;
+import org.apache.http.message.LineParser;
+import org.apache.http.nio.NHttpMessageParser;
+import org.apache.http.nio.NHttpMessageParserFactory;
+import org.apache.http.nio.reactor.SessionInputBuffer;
+
+/**
+ * Default factory for response message parsers.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class DefaultHttpResponseParserFactory implements NHttpMessageParserFactory<HttpResponse> {
+
+    public static final NHttpMessageParserFactory<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 NHttpMessageParser<HttpResponse> create(final SessionInputBuffer buffer,
+            final MessageConstraints constraints) {
+        return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
+    }
+
+}

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

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

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

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriter.java Tue Oct  2 19:44:35 2012
@@ -47,7 +47,7 @@ import org.apache.http.util.CharArrayBuf
 public class DefaultHttpResponseWriter extends AbstractMessageWriter<HttpResponse> {
 
     /**
-     * @deprecated (4.3) use 
+     * @deprecated (4.3) use
      *   {@link DefaultHttpResponseWriter#DefaultHttpResponseWriter(SessionOutputBuffer, LineFormatter)}
      */
     @Deprecated
@@ -63,7 +63,7 @@ public class DefaultHttpResponseWriter e
      * @param buffer the session output buffer.
      * @param formatter the line formatter If <code>null</code> {@link BasicLineFormatter#INSTANCE}
      *   will be used.
-     * 
+     *
      * @since 4.3
      */
     public DefaultHttpResponseWriter(

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/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-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriterFactory.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/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-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriterFactory.java Tue Oct  2 19:44:35 2012
@@ -25,41 +25,39 @@
  *
  */
 
-package org.apache.http.impl.io;
-
-import java.io.IOException;
+package org.apache.http.impl.nio.codecs;
 
 import org.apache.http.HttpResponse;
-import org.apache.http.annotation.NotThreadSafe;
-import org.apache.http.io.SessionOutputBuffer;
+import org.apache.http.annotation.Immutable;
 import org.apache.http.message.BasicLineFormatter;
 import org.apache.http.message.LineFormatter;
+import org.apache.http.nio.NHttpMessageWriter;
+import org.apache.http.nio.NHttpMessageWriterFactory;
+import org.apache.http.nio.reactor.SessionOutputBuffer;
 
 /**
- * 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 NHttpMessageWriterFactory<HttpResponse> {
+
+    public static final NHttpMessageWriterFactory<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 NHttpMessageWriter<HttpResponse> create(final SessionOutputBuffer buffer) {
+        return new DefaultHttpResponseWriter(buffer, lineFormatter);
     }
 
 }

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageParserFactory.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-nio/src/main/java/org/apache/http/nio/NHttpMessageParserFactory.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageParserFactory.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-nio/src/main/java/org/apache/http/nio/NHttpMessageParserFactory.java Tue Oct  2 19:44:35 2012
@@ -24,33 +24,20 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.benchmark;
 
-import java.io.InputStream;
-import java.io.OutputStream;
+package org.apache.http.nio;
 
-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;
-    }
-
-    @Override
-    protected OutputStream createOutputStream(final long len, final SessionOutputBuffer outbuffer) {
-        return new CountingOutputStream(super.createOutputStream(len, outbuffer), this.stats);
-    }
+import org.apache.http.HttpMessage;
+import org.apache.http.impl.MessageConstraints;
+import org.apache.http.nio.reactor.SessionInputBuffer;
+
+/**
+ * Factory for {@link NHttpMessageParser} instances.
+ * 
+ * @since 4.3
+ */
+public interface NHttpMessageParserFactory<T extends HttpMessage> {
 
-    @Override
-    protected InputStream createInputStream(final long len, final SessionInputBuffer inbuffer) {
-        return new CountingInputStream(super.createInputStream(len, inbuffer), this.stats);
-    }
+    NHttpMessageParser<T> create(SessionInputBuffer buffer, MessageConstraints constraints);
 
 }

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageWriterFactory.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-nio/src/main/java/org/apache/http/nio/NHttpMessageWriterFactory.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageWriterFactory.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-nio/src/main/java/org/apache/http/nio/NHttpMessageWriterFactory.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.nio;
 
-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.nio.reactor.SessionOutputBuffer;
 
-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 NHttpMessageWriter} instances.
+ * 
+ * @since 4.3
+ */
+public interface NHttpMessageWriterFactory<T extends HttpMessage> {
 
-    @Override
-    protected InputStream createInputStream(final long len, final SessionInputBuffer inbuffer) {
-        return new CountingInputStream(super.createInputStream(len, inbuffer), this.stats);
-    }
+    NHttpMessageWriter<T> create(SessionOutputBuffer buffer);
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestHttpMessageParser.java Tue Oct  2 19:44:35 2012
@@ -38,6 +38,7 @@ import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
+import org.apache.http.impl.MessageConstraints;
 import org.apache.http.impl.nio.reactor.SessionInputBufferImpl;
 import org.apache.http.nio.NHttpMessageParser;
 import org.apache.http.nio.reactor.SessionInputBuffer;
@@ -281,12 +282,13 @@ public class TestHttpMessageParser {
     @Test
     public void testLineLimitForStatus() throws Exception {
         SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
-        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, -1, 0, null, null);
+        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf,
+                MessageConstraints.lineLen(0));
         requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n\r\n"));
         requestParser.parse();
         requestParser.reset();
 
-        requestParser = new DefaultHttpRequestParser(inbuf, -1, 15, null, null);
+        requestParser = new DefaultHttpRequestParser(inbuf, MessageConstraints.lineLen(15));
         try {
             requestParser.fillBuffer(newChannel("GET /loooooooooooooooong HTTP/1.0\r\nHeader: one\r\n\r\n"));
             requestParser.parse();
@@ -299,12 +301,13 @@ public class TestHttpMessageParser {
     public void testLineLimitForHeader() throws Exception {
         SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
 
-        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, -1, 0, null, null);
+        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf,
+                MessageConstraints.lineLen(0));
         requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n\r\n"));
         requestParser.parse();
         requestParser.reset();
 
-        requestParser = new DefaultHttpRequestParser(inbuf, -1, 15, null, null);
+        requestParser = new DefaultHttpRequestParser(inbuf, MessageConstraints.lineLen(15));
         requestParser.fillBuffer(newChannel("GET / HTTP/1.0\r\nHeader: 9012345\r\n\r\n"));
         requestParser.parse();
         requestParser.reset();
@@ -320,9 +323,12 @@ public class TestHttpMessageParser {
     public void testLineLimitForFoldedHeader() throws Exception {
         SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
 
-        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, 2, 15, null, null);
+        MessageConstraints constraints = MessageConstraints.custom()
+                .setMaxHeaderCount(2).setMaxLineLength(15).build();
+        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, constraints);
         try {
-            requestParser.fillBuffer(newChannel("GET / HTTP/1.0\r\nHeader: 9012345\r\n 23456789012345\r\n 23456789012345\r\n 23456789012345\r\n\r\n"));
+            requestParser.fillBuffer(newChannel("GET / HTTP/1.0\r\nHeader: 9012345\r\n" +
+                    " 23456789012345\r\n 23456789012345\r\n 23456789012345\r\n\r\n"));
             requestParser.parse();
             Assert.fail("IOException should have been thrown");
         } catch (IOException expected) {
@@ -333,13 +339,16 @@ public class TestHttpMessageParser {
     public void testMaxHeaderCount() throws Exception {
         SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 128, Consts.ASCII);
 
-        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, 2, -1, null, null);
+        MessageConstraints constraints = MessageConstraints.custom()
+                .setMaxHeaderCount(2).setMaxLineLength(-1).build();
+        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, constraints);
         requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\nHeader: two\r\n\r\n"));
         requestParser.parse();
         requestParser.reset();
 
         try {
-            requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\nHeader: two\r\nHeader: three\r\n\r\n"));
+            requestParser.fillBuffer(newChannel("GET /whatever HTTP/1.0\r\nHeader: one\r\n" +
+                    "Header: two\r\nHeader: three\r\n\r\n"));
             requestParser.parse();
             Assert.fail("IOException should have been thrown");
         } catch (IOException expected) {
@@ -350,7 +359,8 @@ public class TestHttpMessageParser {
     public void testDetectLineLimitEarly() throws Exception {
         SessionInputBuffer inbuf = new SessionInputBufferImpl(2, 128, Consts.ASCII);
 
-        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf, -1, 2, null, null);
+        NHttpMessageParser<HttpRequest> requestParser = new DefaultHttpRequestParser(inbuf,
+                MessageConstraints.lineLen(2));
         ReadableByteChannel channel = newChannel("GET / HTTP/1.0\r\nHeader: one\r\n\r\n");
         Assert.assertEquals(2, requestParser.fillBuffer(channel));
         Assert.assertNull(requestParser.parse());

Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java Tue Oct  2 19:44:35 2012
@@ -81,7 +81,7 @@ public class ElementalHttpGet {
         HttpContext context = new BasicHttpContext(null);
         HttpHost host = new HttpHost("localhost", 8080);
 
-        DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(params);
+        DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
         ConnectionReuseStrategy connStrategy = DefaultConnectionReuseStrategy.INSTANCE;
 
         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);

Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java?rev=1393136&r1=1393135&r2=1393136&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java Tue Oct  2 19:44:35 2012
@@ -88,7 +88,7 @@ public class ElementalHttpPost {
 
         HttpHost host = new HttpHost("localhost", 8080);
 
-        DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(params);
+        DefaultBHttpClientConnection conn = new DefaultBHttpClientConnection(8 * 1024);
         ConnectionReuseStrategy connStrategy = DefaultConnectionReuseStrategy.INSTANCE;
 
         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);



Mime
View raw message