Hi Oleg,
I was looking into BHttpConnectionBase#createOutputStream method. To change
the default chunk size (2048), I believe the only way is to implement a
custom http client connection and override createOuptputStream(). Here is
what I have so far.
public static class CustomManagedHttpClientConnection extends
DefaultManagedHttpClientConnection {
private final int chunkSize;
public CustomManagedHttpClientConnection(final String id, final int
buffersize, final int chunkSize) {
super(id, buffersize);
this.chunkSize = chunkSize;
}
@Override
protected OutputStream createOutputStream(long len,
SessionOutputBuffer outbuffer) {
if (len == ContentLengthStrategy.CHUNKED) {
return new ChunkedOutputStream(chunkSize, outbuffer);
} else if (len == ContentLengthStrategy.IDENTITY) {
return new IdentityOutputStream(outbuffer);
} else {
return new ContentLengthOutputStream(outbuffer, len);
}
}
}
public static class CustomManagedHttpClientConnectionFactory extends
ManagedHttpClientConnectionFactory {
private final int chunkSize;
public CustomManagedHttpClientConnectionFactory(int chunkSize) {
this.chunkSize = chunkSize;
}
@Override
public ManagedHttpClientConnection create(HttpRoute route,
ConnectionConfig config) {
final String id = "http-outgoing-" +
Long.toString(COUNTER.getAndIncrement());
return new CustomManagedHttpClientConnection(id,
config.getBufferSize(), chunkSize);
}
}
Usage:
int chunkSize = 1024;
HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection>
connFactory = new CustomManagedHttpClientConnectionFactory(chunkSize);
PoolingHttpClientConnectionManager connManager = new
PoolingHttpClientConnectionManager(connFactory);
CloseableHttpClient client = HttpClients.createMinimal(connManager);
Do you recommend a better approach? Is there a way to configure this
per-request instead of client?
- ARul
On Wed, Nov 13, 2013 at 8:29 AM, Arul Dhesiaseelan <[email protected]> wrote:
> Thanks Oleg for clearing this up.
>
>
> On Wed, Nov 13, 2013 at 7:06 AM, Oleg Kalnichevski <[email protected]>wrote:
>
>> On Wed, 2013-11-13 at 06:54 -1000, Arul Dhesiaseelan wrote:
>> > Using chunked encoding to write the entity. So, this property is not
>> > intended to control the chunk size of the entity?
>> >
>>
>> No, it is not. I admit that javadocs may be unclear about it but I did
>> try to describe its purpose to my best abilities.
>>
>> If you want to change the default chunk size from 2048 to something else
>> you should be looking at the BHttpConnectionBase#createOutputStream
>> method.
>>
>> Oleg
>>
>> > - Arul
>> >
>> >
>> > On Wed, Nov 13, 2013 at 6:43 AM, Oleg Kalnichevski <[email protected]>
>> wrote:
>> >
>> > > On Wed, 2013-11-13 at 06:32 -1000, Arul Dhesiaseelan wrote:
>> > > > Hi Oleg,
>> > > >
>> > > > Using it to control the chunk size on the Client, which can be
>> > > configurable.
>> > > >
>> > >
>> > > Chunks of what? MIN_CHUNK_LIMIT has nothing to do with chunk coding.
>> > > Misleading name was one of the reasons why this parameter was
>> > > discontinued.
>> > >
>> > > Oleg
>> > >
>> > > > - Arul
>> > > >
>> > > >
>> > > > On Wed, Nov 13, 2013 at 5:40 AM, Oleg Kalnichevski <
>> [email protected]>
>> > > wrote:
>> > > >
>> > > > > On Tue, 2013-11-12 at 18:49 -1000, Arul Dhesiaseelan wrote:
>> > > > > > Hi,
>> > > > > >
>> > > > > > CoreConnectionPNames is deprecated. I could not find
>> MIN_CHUNK_LIMIT
>> > > > > > configuration in 4.3.1. The closest I can see is
>> > > > > > ConnectionConfig.bufferSize. Not sure if they are the same.
>> > > > > >
>> > > > > > Any idea?
>> > > > > >
>> > > > >
>> > > > > Arul
>> > > > >
>> > > > > There is no direct equivalent of MIN_CHUNK_LIMIT in 4.3. What are
>> you
>> > > > > using this parameter for?
>> > > > >
>> > > > > Oleg
>> > > > >
>> > > > >
>> > > > >
>> > > > >
>> ---------------------------------------------------------------------
>> > > > > To unsubscribe, e-mail:
>> [email protected]
>> > > > > For additional commands, e-mail:
>> [email protected]
>> > > > >
>> > > > >
>> > >
>> > >
>> > >
>> > > ---------------------------------------------------------------------
>> > > To unsubscribe, e-mail: [email protected]
>> > > For additional commands, e-mail: [email protected]
>> > >
>> > >
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>