Index: httpcore/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpClientConnection.java =================================================================== --- httpcore/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpClientConnection.java (revision 1428700) +++ httpcore/httpcore/src/test/java/org/apache/http/testserver/LoggingBHttpClientConnection.java (working copy) @@ -66,7 +66,7 @@ final HttpMessageParserFactory responseParserFactory) { super(buffersize, chardecoder, charencoder, constraints, incomingContentStrategy, outgoingContentStrategy, - requestWriterFactory, responseParserFactory); + requestWriterFactory, responseParserFactory, null); this.id = "http-outgoing-" + COUNT.incrementAndGet(); this.log = LogFactory.getLog(getClass()); this.headerlog = LogFactory.getLog("org.apache.http.headers"); Index: httpcore/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java =================================================================== --- httpcore/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java (revision 1428700) +++ httpcore/httpcore/src/test/java/org/apache/http/impl/SessionInputBufferMock.java (working copy) @@ -51,7 +51,11 @@ final MessageConstraints constrains, final CharsetDecoder decoder) { super(new HttpTransportMetricsImpl(), buffersize, -1, constrains, decoder); - bind(instream); + try { + bind(instream); + } catch (IOException e) { + throw new RuntimeException(e); + } } public SessionInputBufferMock( Index: httpcore/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java =================================================================== --- httpcore/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java (revision 1428700) +++ httpcore/httpcore/src/test/java/org/apache/http/impl/SessionOutputBufferMock.java (working copy) @@ -28,6 +28,7 @@ package org.apache.http.impl; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; @@ -50,7 +51,11 @@ int minChunkLimit, final CharsetEncoder encoder) { super(new HttpTransportMetricsImpl(), buffersize, minChunkLimit, encoder); - bind(buffer); + try { + bind(buffer); + } catch (IOException e) { + throw new RuntimeException(e); + } this.buffer = buffer; } Index: httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java =================================================================== --- httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java (revision 1428700) +++ httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionInputBufferImpl.java (working copy) @@ -60,14 +60,14 @@ @NotThreadSafe public class SessionInputBufferImpl implements SessionInputBuffer, BufferInfo { - private final HttpTransportMetricsImpl metrics; + protected final HttpTransportMetricsImpl metrics; private final byte[] buffer; - private final ByteArrayBuffer linebuffer; + protected final ByteArrayBuffer linebuffer; private final int minChunkLimit; private final MessageConstraints constraints; private final CharsetDecoder decoder; - private InputStream instream; + protected InputStream instream; private int bufferpos; private int bufferlen; private CharBuffer cbuf; @@ -105,7 +105,7 @@ this.decoder = chardecoder; } - public void bind(final InputStream instream) { + public void bind(final InputStream instream) throws IOException { this.instream = instream; } @@ -286,7 +286,7 @@ * @return HTTP line as a string * @exception IOException if an I/O error occurs. */ - private int lineFromLineBuffer(final CharArrayBuffer charbuffer) + protected int lineFromLineBuffer(final CharArrayBuffer charbuffer) throws IOException { // discard LF if found int len = this.linebuffer.length(); Index: httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java =================================================================== --- httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java (revision 1428700) +++ httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionOutputBufferImpl.java (working copy) @@ -94,7 +94,7 @@ this.encoder = charencoder; } - public void bind(final OutputStream outstream) { + public void bind(final OutputStream outstream) throws IOException { this.outstream = outstream; } Index: httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionBufferImplFactory.java =================================================================== --- httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionBufferImplFactory.java (revision 0) +++ httpcore/httpcore/src/main/java/org/apache/http/impl/io/SessionBufferImplFactory.java (revision 0) @@ -0,0 +1,46 @@ +/* + * ==================================================================== + * 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 + * . + * + */ + +package org.apache.http.impl.io; + +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; + +import org.apache.http.config.MessageConstraints; + +/** + * @since 4.3 + */ +public interface SessionBufferImplFactory { + + SessionInputBufferImpl createInputBuffer(HttpTransportMetricsImpl metrics, + int buffersize, int minChunkLimit, MessageConstraints constraints, + CharsetDecoder chardecoder); + + SessionOutputBufferImpl createOutputBuffer(HttpTransportMetricsImpl metrics, + int buffersize, int i, CharsetEncoder charencoder); +} Index: httpcore/httpcore/src/main/java/org/apache/http/impl/io/DefaultSessionBufferImplFactory.java =================================================================== --- httpcore/httpcore/src/main/java/org/apache/http/impl/io/DefaultSessionBufferImplFactory.java (revision 0) +++ httpcore/httpcore/src/main/java/org/apache/http/impl/io/DefaultSessionBufferImplFactory.java (revision 0) @@ -0,0 +1,51 @@ +/* + * ==================================================================== + * 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 + * . + * + */ +package org.apache.http.impl.io; + +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; + +import org.apache.http.config.MessageConstraints; + +public class DefaultSessionBufferImplFactory implements SessionBufferImplFactory { + + public static final SessionBufferImplFactory INSTANCE = new DefaultSessionBufferImplFactory(); + + @Override + public SessionInputBufferImpl createInputBuffer( + HttpTransportMetricsImpl metrics, int buffersize, int minChunkLimit, + MessageConstraints constraints, CharsetDecoder chardecoder) { + return new SessionInputBufferImpl(metrics, buffersize, minChunkLimit, constraints, chardecoder); + } + + @Override + public SessionOutputBufferImpl createOutputBuffer( + HttpTransportMetricsImpl metrics, int buffersize, int minChunkLimit, + CharsetEncoder charencoder) { + return new SessionOutputBufferImpl(metrics, buffersize, minChunkLimit, charencoder); + } +} Index: httpcore/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java =================================================================== --- httpcore/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java (revision 1428700) +++ httpcore/httpcore/src/main/java/org/apache/http/impl/BHttpConnectionBase.java (working copy) @@ -55,9 +55,11 @@ import org.apache.http.impl.io.ChunkedOutputStream; import org.apache.http.impl.io.ContentLengthInputStream; import org.apache.http.impl.io.ContentLengthOutputStream; +import org.apache.http.impl.io.DefaultSessionBufferImplFactory; import org.apache.http.impl.io.HttpTransportMetricsImpl; import org.apache.http.impl.io.IdentityInputStream; import org.apache.http.impl.io.IdentityOutputStream; +import org.apache.http.impl.io.SessionBufferImplFactory; import org.apache.http.impl.io.SessionInputBufferImpl; import org.apache.http.impl.io.SessionOutputBufferImpl; import org.apache.http.io.SessionInputBuffer; @@ -99,6 +101,7 @@ * {@link LaxContentLengthStrategy#INSTANCE} will be used. * @param outgoingContentStrategy outgoing content length strategy. If null * {@link StrictContentLengthStrategy#INSTANCE} will be used. + * @param sessionBufferFactory */ protected BHttpConnectionBase( int buffersize, @@ -106,14 +109,16 @@ final CharsetEncoder charencoder, final MessageConstraints constraints, final ContentLengthStrategy incomingContentStrategy, - final ContentLengthStrategy outgoingContentStrategy) { + final ContentLengthStrategy outgoingContentStrategy, + final SessionBufferImplFactory sessionBufferFactory) { super(); Args.positive(buffersize, "Buffer size"); HttpTransportMetricsImpl inTransportMetrics = new HttpTransportMetricsImpl(); HttpTransportMetricsImpl outTransportMetrics = new HttpTransportMetricsImpl(); - this.inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1, + SessionBufferImplFactory sbf = sessionBufferFactory != null ? sessionBufferFactory : DefaultSessionBufferImplFactory.INSTANCE; + this.inbuffer = sbf.createInputBuffer(inTransportMetrics, buffersize, -1, constraints != null ? constraints : MessageConstraints.DEFAULT, chardecoder); - this.outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, -1, + this.outbuffer = sbf.createOutputBuffer(outTransportMetrics, buffersize, -1, charencoder); this.connMetrics = new HttpConnectionMetricsImpl(inTransportMetrics, outTransportMetrics); this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy : Index: httpcore/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java =================================================================== --- httpcore/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java (revision 1428700) +++ httpcore/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java (working copy) @@ -94,7 +94,7 @@ final HttpMessageWriterFactory responseWriterFactory) { super(buffersize, chardecoder, charencoder, constraints, incomingContentStrategy != null ? incomingContentStrategy : - DisallowIdentityContentLengthStrategy.INSTANCE, outgoingContentStrategy); + DisallowIdentityContentLengthStrategy.INSTANCE, outgoingContentStrategy, null); this.requestParser = (requestParserFactory != null ? requestParserFactory : DefaultHttpRequestParserFactory.INSTANCE).create(getSessionInputBuffer(), constraints); this.responseWriter = (responseWriterFactory != null ? responseWriterFactory : Index: httpcore/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java =================================================================== --- httpcore/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java (revision 1428700) +++ httpcore/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java (working copy) @@ -47,6 +47,7 @@ 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.impl.io.SessionBufferImplFactory; import org.apache.http.io.HttpMessageParser; import org.apache.http.io.HttpMessageParserFactory; import org.apache.http.io.HttpMessageWriter; @@ -83,6 +84,7 @@ * {@link DefaultHttpRequestWriterFactory#INSTANCE} will be used. * @param responseParserFactory response parser factory. If null * {@link DefaultHttpResponseParserFactory#INSTANCE} will be used. + * @param sessionBufferFactory */ public DefaultBHttpClientConnection( int buffersize, @@ -92,9 +94,11 @@ final ContentLengthStrategy incomingContentStrategy, final ContentLengthStrategy outgoingContentStrategy, final HttpMessageWriterFactory requestWriterFactory, - final HttpMessageParserFactory responseParserFactory) { - super(buffersize, chardecoder, charencoder, - constraints, incomingContentStrategy, outgoingContentStrategy); + final HttpMessageParserFactory responseParserFactory, + final SessionBufferImplFactory sessionBufferFactory) { + super(buffersize, chardecoder, charencoder, constraints, + incomingContentStrategy, outgoingContentStrategy, + sessionBufferFactory); this.requestWriter = (requestWriterFactory != null ? requestWriterFactory : DefaultHttpRequestWriterFactory.INSTANCE).create(getSessionOutputBuffer()); this.responseParser = (responseParserFactory != null ? responseParserFactory : @@ -106,11 +110,11 @@ final CharsetDecoder chardecoder, final CharsetEncoder charencoder, final MessageConstraints constraints) { - this(buffersize, chardecoder, charencoder, constraints, null, null, null, null); + this(buffersize, chardecoder, charencoder, constraints, null, null, null, null, null); } public DefaultBHttpClientConnection(int buffersize) { - this(buffersize, null, null, null, null, null, null, null); + this(buffersize, null, null, null, null, null, null, null, null); } protected void onResponseReceived(final HttpResponse response) { Index: httpclient/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java =================================================================== --- httpclient/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java (revision 1428700) +++ httpclient/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java (working copy) @@ -51,7 +51,11 @@ final MessageConstraints constrains, final CharsetDecoder decoder) { super(new HttpTransportMetricsImpl(), buffersize, -1, constrains, decoder); - bind(instream); + try { + bind(instream); + } catch (IOException e) { + throw new RuntimeException(e); + } } public SessionInputBufferMock( Index: httpclient/httpclient/src/main/java/org/apache/http/impl/conn/SocketClientConnectionImpl.java =================================================================== --- httpclient/httpclient/src/main/java/org/apache/http/impl/conn/SocketClientConnectionImpl.java (revision 1428700) +++ httpclient/httpclient/src/main/java/org/apache/http/impl/conn/SocketClientConnectionImpl.java (working copy) @@ -50,11 +50,12 @@ import org.apache.http.conn.SocketClientConnection; import org.apache.http.entity.ContentLengthStrategy; import org.apache.http.impl.DefaultBHttpClientConnection; +import org.apache.http.impl.io.SessionBufferImplFactory; import org.apache.http.io.HttpMessageParserFactory; import org.apache.http.io.HttpMessageWriterFactory; import org.apache.http.protocol.HttpContext; -class SocketClientConnectionImpl extends DefaultBHttpClientConnection +public class SocketClientConnectionImpl extends DefaultBHttpClientConnection implements SocketClientConnection, HttpContext { private static final AtomicLong COUNT = new AtomicLong(); @@ -67,27 +68,27 @@ private volatile boolean shutdown; - public SocketClientConnectionImpl( - int buffersize, - final CharsetDecoder chardecoder, - final CharsetEncoder charencoder, + public SocketClientConnectionImpl(int buffersize, + final CharsetDecoder chardecoder, final CharsetEncoder charencoder, final MessageConstraints constraints, final ContentLengthStrategy incomingContentStrategy, final ContentLengthStrategy outgoingContentStrategy, final HttpMessageWriterFactory requestWriterFactory, - final HttpMessageParserFactory responseParserFactory) { - super(buffersize, chardecoder, charencoder, - constraints, incomingContentStrategy, outgoingContentStrategy, - requestWriterFactory, responseParserFactory); + final HttpMessageParserFactory responseParserFactory, + final SessionBufferImplFactory sessionBufferFactory) { + super(buffersize, chardecoder, charencoder, constraints, + incomingContentStrategy, outgoingContentStrategy, + requestWriterFactory, responseParserFactory, + sessionBufferFactory); this.id = "http-outgoing-" + COUNT.incrementAndGet(); this.log = LogFactory.getLog(getClass()); this.headerlog = LogFactory.getLog("org.apache.http.headers"); this.wire = new Wire(LogFactory.getLog("org.apache.http.wire"), this.id); - this.attributes = new ConcurrentHashMap(); + this.attributes = new ConcurrentHashMap(); } public SocketClientConnectionImpl(int buffersize) { - this(buffersize, null, null, null, null, null, null, null); + this(buffersize, null, null, null, null, null, null, null, null); } @Override Index: httpclient/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java =================================================================== --- httpclient/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java (revision 1428700) +++ httpclient/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionFactory.java (working copy) @@ -34,8 +34,10 @@ import org.apache.http.annotation.Immutable; import org.apache.http.config.ConnectionConfig; +import org.apache.http.config.MessageConstraints; import org.apache.http.conn.HttpConnectionFactory; import org.apache.http.conn.SocketClientConnection; +import org.apache.http.impl.io.DefaultSessionBufferImplFactory; /** * @since 4.3 @@ -62,11 +64,17 @@ charencoder.onMalformedInput(malformedInputAction); charencoder.onUnmappableCharacter(unmappableInputAction); } + return create(chardecoder, charencoder, cconfig.getMessageConstraints()); + } + + protected SocketClientConnection create(CharsetDecoder chardecoder, + CharsetEncoder charencoder, MessageConstraints messageConstraints) { return new SocketClientConnectionImpl(8 * 1024, chardecoder, charencoder, - cconfig.getMessageConstraints(), + messageConstraints, null, null, null, - DefaultHttpResponseParserFactory.INSTANCE); + DefaultHttpResponseParserFactory.INSTANCE, + DefaultSessionBufferImplFactory.INSTANCE); } } Index: httpclient/pom.xml =================================================================== --- httpclient/pom.xml (revision 1428700) +++ httpclient/pom.xml (working copy) @@ -65,7 +65,7 @@ - 4.3-alpha1 + 4.3-alpha2-SNAPSHOT 1.1.1 1.6 2.2.0