Ok cool. I was thinking of configuring it at runtime, but I think it may not be needed.
Thanks! ARul On Sun, Dec 1, 2013 at 11:39 PM, Oleg Kalnichevski <ol...@apache.org> wrote: > On Sun, 2013-12-01 at 13:14 -1000, ARul wrote: > > 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? > > I cannot suggest anything better. > > > Is there a way to configure this > > per-request instead of client? > > > > Why would you want to do that in the first place? > > Oleg > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org > For additional commands, e-mail: httpclient-users-h...@hc.apache.org > >