Sorry for the typo, I mean to say "I am NOW using HttpAsyncClient"

On Thu, Nov 1, 2012 at 11:44 AM, Sachin Nikumbh <[email protected]> wrote:

> Hi Oleg,
>
> Thanks for the help. I am not using HttpAsyncClient and it's working as
> expected. Is the async client still in beta version? Are there any known
> issues that I should be aware of?
>
> Thanks
> Sachin
>
>
> On Thu, Nov 1, 2012 at 6:01 AM, Oleg Kalnichevski <[email protected]>wrote:
>
>> On Wed, Oct 31, 2012 at 09:19:19AM -0400, Sachin Nikumbh wrote:
>> > Hi,
>> >
>> > I am using HttpClient (version 4.2.2) to communicate with a server using
>> > POST requests. The server can be configured to set request size limit.
>> Once
>> > the request content exceeds this limit, it sends HTTP 413 response
>> status
>> > and closes the connection.
>> >
>> > In my simple application written using Apache HttpClient, I send a POST
>> > request with request content too large for the server using something
>> like
>> > following:
>> >
>> > ***************************************************
>> > DefaultHttpClient httpClient = new DefaultHttpClient();
>> > ...
>> > ...
>> > HttpPost postReq = new HttpPost(url);
>> > ....
>> > HttpResponse response = httpClient.execute(postReq);
>> > ***************************************************
>> >
>> > I am expecting the response.getStatusLine().getStatusCode() to
>> > return  HttpStatus.SC_REQUEST_TOO_LONG. But instead, I am getting a
>> > SocketException with message :
>> >
>> > ***************************************************
>> > Connection reset by peer: socket write error
>> > ***************************************************
>> >
>> > I have used WireShark to see what's being sent and received. Wireshark
>> > shows the response with 413 status from server the moment client exceeds
>> > the request size limit. But it looks like HttpClient is ignoring it and
>> > still continues to send the remaining request.
>> >
>> > Is there something that I am missing or is this not supported?
>> >
>> > Any help will be greatly appreciated,
>> >
>> > Thanks
>> > Sachin
>>
>> This problem is caused by the limitation of Java blocking I/O. There is
>> no efficient way of reading and writing to the same network socket using a
>> single execution thread. Therefore, HttpClient cannot read incoming data
>> until the entire request is fully written out. Given that the server sends
>> a 413 status out of sequence and immediately closes the connection while
>> HttpClient is still busy writing out request data, request execution fails
>> with a connection reset i/o error rather than HTTP 413 status.
>>
>> Your only option would be switching to a NIO based HTTP client such
>> Apache HttpAsyncClient [1] which are better equipped to deal wi8th out of
>> sequence I/O events.
>>
>> Oleg
>>
>> [1] http://hc.apache.org/httpcomponents-asyncclient-dev/index.html
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>

Reply via email to