You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Da...@apcc.com on 2004/03/03 22:41:40 UTC

Streaming requests

I know there have been several discussions in regards to streaming requests
rather than buffering.  There have been many suggestions on how to allow
for streaming of requests using Piped streams, etc, but I have come up
against a situation were it seems to be impossible to do with the current
architecture.  I am using JDOM to generate XML and send it to the server
using httpclient.  The problem I am running into is that the xml can become
large enough that streaming would definately help on memory allocations.
The real stumbling block lies in the fact that JDOM expects an output
stream to write to and httpclient uses an input stream.  This would
normally be a great place to use Piped streams but in this instance it
doesn't work.

This example demonstrates the problem

PipedInputStream pipedInputStream = new PipedInputStream();
PipedOutputStream pipedOutputStream = new
PipedOutputStream(pipedInputStream);
XMLOutputter output = new XMLOutputter();

postMethod.setRequestBody(pipedInputStream);
output.output(doc, pipedOutputStream);   // calling this outputs to the
output stream but this hangs because the PipedInputStream is not read until
executeMethod
int statusCode = httpClient.executeMethod(postMethod);


The problem here is that calling output of course hangs because the
PipedInputStream is not being read until executMethod is called.  If there
was access to an output stream in postMethod this could be solved.  Does
anyone have any other ideas of how this could be accomplished?

Thanks in advance for any help.



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Re: Streaming requests

Posted by Michael Becke <be...@u.washington.edu>.
Hi David,

In the case of the piped streams you need to do the reading and writing 
from separate threads.  This is to avoid the exact case that you are 
seeing, and I believe it is documented in Sun's javadocs.  Any other 
solution will require changing the PostMethod API as discussed, or 
buffering.

Mike

On Mar 3, 2004, at 4:41 PM, David.Cowan@apcc.com wrote:

> I know there have been several discussions in regards to streaming 
> requests
> rather than buffering.  There have been many suggestions on how to 
> allow
> for streaming of requests using Piped streams, etc, but I have come up
> against a situation were it seems to be impossible to do with the 
> current
> architecture.  I am using JDOM to generate XML and send it to the 
> server
> using httpclient.  The problem I am running into is that the xml can 
> become
> large enough that streaming would definately help on memory 
> allocations.
> The real stumbling block lies in the fact that JDOM expects an output
> stream to write to and httpclient uses an input stream.  This would
> normally be a great place to use Piped streams but in this instance it
> doesn't work.
>
> This example demonstrates the problem
>
> PipedInputStream pipedInputStream = new PipedInputStream();
> PipedOutputStream pipedOutputStream = new
> PipedOutputStream(pipedInputStream);
> XMLOutputter output = new XMLOutputter();
>
> postMethod.setRequestBody(pipedInputStream);
> output.output(doc, pipedOutputStream);   // calling this outputs to the
> output stream but this hangs because the PipedInputStream is not read 
> until
> executeMethod
> int statusCode = httpClient.executeMethod(postMethod);
>
>
> The problem here is that calling output of course hangs because the
> PipedInputStream is not being read until executMethod is called.  If 
> there
> was access to an output stream in postMethod this could be solved.  
> Does
> anyone have any other ideas of how this could be accomplished?
>
> Thanks in advance for any help.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org