hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Magnus Landrø <stefan.lan...@gmail.com>
Subject Re: 400 bad request POSTing to Tomcat 7.0.42
Date Wed, 25 Feb 2015 19:44:00 GMT
2015-02-25 20:07 GMT+01:00 Alessandro Manzoni <manzoni.alessandro4@gmail.com
>:

> Il 25.02.2015 19.28, Stefan Magnus Landrø ha scritto:
>
>> Few questions:
>>
>> Why not use a more appropriate entity type? ByteArrayEntity? StreamEntity?
>>
> Should I? Why an entity would be more or less appropriate?
>
> By the way, in version 4.2.2  I have no StreamEntity class.


https://github.com/apache/httpcore/blob/4.2.2/httpcore/src/main/java/org/apache/http/entity/InputStreamEntity.java


> Docs says that ByteArrayEntity has no encoding, while StringEntity does.
> That's it.
>

You're reading the whole thing into memory. You'll get better performance
streaming. The encoding header can be set directly on the request. See
sources for details on which headers are set in case of string entity.

>
>
>> How do you consume the response?
>>
> Does it matter? The failure already happened.
>
Fair enough. You should see details in the tomcat logs concerning the 400
error code. Are you controlling the application you're hitting?

>
> By the way, I try to unmarshal response.getEntity().getContent(), as the
> application waits for a returned xml stream.
> If the unmarshal fails, I just write the content to the log file. In the
> log I found that Tomcat returned an html page, with the notification of the
> failure. This case 400 bad request, and I'm wondering why Tomcat dislikes
> my request. That's not bad at all to me.
>
>
>
>>
>>
>>
>>
>> Sendt fra min iPhone
>>
>>  Den 25. feb. 2015 kl. 17.26 skrev Alessandro Manzoni <
>>> manzoni.alessandro4@gmail.com>:
>>>
>>> I made a simple client that sends a xml stream to a webapp running on
>>> tomcat 7 by POST method.
>>> Both client and tomcat run on the same server (linux). HTTPClient
>>> version is 4.2.2.
>>>
>>> The xml stream is formally correct. Somtimes, when the stream is more
>>> than 30KB tomcat replies with an html page reporting 400 bad request. When
>>> the stream is smaller goes fine.
>>>
>>> This is my code:
>>>             HttpClient httpclient = new DefaultHttpClient();
>>>             HttpPost httppost = new HttpPost(uri);
>>>             StringEntity entity = new StringEntity(new
>>> String(output.toByteArray()), ContentType.TEXT_XML);
>>>             httppost.setEntity(entity);
>>>             return httpclient.execute(httppost);
>>>
>>> where:
>>> - uri is the uri of the webapp, always the same.
>>> - output is a ByteArrayOutputStream that contains the xml stream
>>>
>>> Should I put some more headers? Or change somewhat to avoid the error?
>>>
>>> Thanks, regards.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>>
>>>  ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
BEKK Open
http://open.bekk.no

TesTcl - a unit test framework for iRules
http://testcl.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message