users@jersey.java.net

Re: [Jersey] Thread waits indefinitely using Apache HTTP based Jersey Client[WAS]Re: Problem switching to ApacheHttpClient in Jersey 1.0.2

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 17 Feb 2009 16:01:54 +0100

Hi Imran,

I reproduced both of your issues:

1) The first as you rightly work around is to use preemptive
authorization.
      I think we need a property to state whether PUT/POST requests
requiring buffering for
      repeatable requests.

2) The thread locking issue is related not releasing the connection on
the Apache HTTP methods.
      My guess is your service is returning something for the POST but
the client is not interested
      in processing the response entity.

For 1 i have changed things so that requests are repeatable by
default. If you set the ClientConfig.PROPERTY_CHUNKED_ENCODING_SIZE to
something > 0 then buffering will not occur.

For 2 i have fixed this so that resources are correctly cleaned up. It
is important for the Apache HTTP client that if you are using
ClientResponse without reading an entity (when one is present) or are
processing entities that are instances of Closeable that you close the
response or stream respectively after you have finished processing the
response.

This is fixed in the trunk, and I have updated the JavaDoc of
ApacheHttpClient to reflect the changes i have made.

So now by default things should work as you initially expected.

Paul.

On Feb 17, 2009, at 11:14 AM, Imran M Yousuf wrote:

> Hi,
>
> While trying to fix how to integrate authentication in client API
> using Apache HTTP based Jersey Client I applied 0002_2 on 0001 and
> somehow went into a indefinite wait state and the thread dump from
> that instance is also attached for reference. I came around that state
> by applying 0002_1 instead of 0002_2. Another observation in this
> regard is that the client requires re-initialization for every 5~6
> POSTs'. I would be interested to help in this regard by any means
> possible if required.
>
> Best regards,
>
> Imran
>
> On Tue, Feb 17, 2009 at 12:57 PM, Imran M Yousuf
> <imyousuf_at_smartitengineering.com> wrote:
>> Hi,
>>
>> I am trying to integrate Spring Security with Jersey and in the
>> client
>> part I am trying to use Jersey Client and in order to make
>> authentication easier I am trying to use jersey-contrib's
>> jersey-apache-client. Before integrating the client I was getting
>> HTTP
>> Status 401 (as expected) and after integrating it I am getting the
>> following exception:
>> com.sun.jersey.api.client.ClientHandlerException:
>> org.apache.commons.httpclient.ProtocolException: Unbuffered entity
>> enclosing request can not be repeated.
>> The full stacktrace is in the attached
>> "com
>> .smartitengineering.bookstore.ws.server.BookStoreResourcesTest.txt"
>> file. The attached Java file is the source of the test file and the
>> attached patch file is the diff for integrating the apache http based
>> client.
>>
>> I would be grateful if someone could please guide me in fixing the
>> problem. Any suggestion is most welcome. The complete source code is
>> available at -
>> http://repo.or.cz/w/smart-bookstore.git?a=shortlog;h=refs/heads/auth
>>
>> --
>> Imran M Yousuf
>> Software Engineer
>> Smart IT Engineering
>> Dhaka, Bangladesh
>> Email: imran_at_smartitengineering.com
>> Blog: http://imyousuf-tech.blogs.smartitengineering.com/
>> Mobile: +880-1711402557
>>
>
>
>
> --
> Imran M Yousuf
> Entrepreneur & Software Engineer
> Smart IT Engineering
> Dhaka, Bangladesh
> Email: imran_at_smartitengineering.com
> Blog: http://imyousuf-tech.blogs.smartitengineering.com/
> Mobile: +880-1711402557
> <auth-thread-dump.txt><0001-Change-to-apache-http-based-jersey-
> client.patch><0002_2-Test-freezes.patch><0002_1-Get-test-to-work-
> with-
> authentication
> .patch
> >---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net