hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brett Ryan <brett.r...@gmail.com>
Subject Re: 400 bad request POSTing to Tomcat 7.0.42
Date Thu, 26 Feb 2015 08:04:39 GMT

> Since I produce the xml in memory, that's the way Marshal.marshal method works, I could
use the ByteArrayEntity using the byte[] from the ByteArrayOutputStream supplied to marshal.


Could you not do something like 

PipedOutputStream out = new PipedOutputStream();
InputStream instr = new PipedInputStream(out);
marshaller.marshal(object, out);
HttpPost post = new HttpPost();
post.setEntity(new InputStreamEntity(instr));

I have t validated this as I'm just on my phone but thats where id start. Always try to write
to a stream wherever possible instead of building up in memory only to dump it out.

> But docs tell me that ByteArrayEntity is not thread-safe, while I need to use HttpClient
by conncurrent threads.

You would be only creating the entity per request, so thread safety is not an issue.


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


Mime
View raw message