You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by AT Pune <an...@googlemail.com> on 2010/10/21 08:45:50 UTC

How to get an output stream from already established connection in HttpComponents Client 4.0

Hi,

I upload a large file (>4GB in chunks) in a single http connection and by
opening the output stream just once. To do this I've used HttpClient 3.1 API
and have done this.

1. Extended the RequestEntity to create a chunked entity class that has the
getContentLength(), getContentType() etc methods.
2. Extended the EntityEnclosingMethod to create a PostMethod like class
"ChunkedPostMethod". And in its constructor called the setRequestEntity()
method passing the chunked entity class as parameter.
3. In the "ChunkedPostMethod", in the writeRequestBody(HttpState state,
HttpConnection conn) I get the handle of OutputStream using
conn.getRequestOutputStream(), and in the readResponseBody(HttpState state,
HttpConnection conn) I get the handle of InputStream using
conn.getResponseInputStream().

I use this "ChunkedPostMethod" to connect to the Http server. These input
stream and output stream handles I maintain until all the chunks are
transfered using these.

All this I've achieved with HttpClient3.1. But I'm not able to convert this
code to HttpComponents Client 4.1 as the equivalent of EntityEnclosingMethod
in httpclient4.0 is HttpEntityEnclosingRequestBase but that does not provide
any method (like writeRequestBody and readResponseBody) that provides the
after-connection outputstream and inputstream handles.

First of all is there any way of getting the outputstream from the http
connection in httpclient4.0? If yes then how?

Thanks in advance,
Anurag
-- 
View this message in context: http://old.nabble.com/How-to-get-an-output-stream-from-already-established-connection-in-HttpComponents-Client-4.0-tp30016648p30016648.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: How to get an output stream from already established connection in HttpComponents Client 4.0

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2010-10-20 at 23:45 -0700, AT Pune wrote:
> Hi,
> 
> I upload a large file (>4GB in chunks) in a single http connection and by
> opening the output stream just once. To do this I've used HttpClient 3.1 API
> and have done this.
> 
> 1. Extended the RequestEntity to create a chunked entity class that has the
> getContentLength(), getContentType() etc methods.
> 2. Extended the EntityEnclosingMethod to create a PostMethod like class
> "ChunkedPostMethod". And in its constructor called the setRequestEntity()
> method passing the chunked entity class as parameter.
> 3. In the "ChunkedPostMethod", in the writeRequestBody(HttpState state,
> HttpConnection conn) I get the handle of OutputStream using
> conn.getRequestOutputStream(), and in the readResponseBody(HttpState state,
> HttpConnection conn) I get the handle of InputStream using
> conn.getResponseInputStream().
> 
> I use this "ChunkedPostMethod" to connect to the Http server. These input
> stream and output stream handles I maintain until all the chunks are
> transfered using these.
> 
> All this I've achieved with HttpClient3.1. But I'm not able to convert this
> code to HttpComponents Client 4.1 as the equivalent of EntityEnclosingMethod
> in httpclient4.0 is HttpEntityEnclosingRequestBase but that does not provide
> any method (like writeRequestBody and readResponseBody) that provides the
> after-connection outputstream and inputstream handles.
> 
> First of all is there any way of getting the outputstream from the http
> connection in httpclient4.0? If yes then how?
> 
> Thanks in advance,
> Anurag

What is wrong with just writing out the content of the file into
OutputStream instance passed as a parameter to the HttpEntity#writeTo
method?

Oleg


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org