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: Imran M Yousuf <imran_at_smartitengineering.com>
Date: Wed, 18 Feb 2009 09:29:55 +0600

Hi Paul,

On Tue, Feb 17, 2009 at 9:01 PM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> Hi Imran,
>
> I reproduced both of your issues:

Firstly, thanks a lot for taking time go through the issues and I am
glad that I produced something reproduceable :).

>
> 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.
>

I agree with the solution and its rational to have repeatable set by default.

> 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 IMHO is a very important fix and I am glad that now its in the trunk.

> 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.
>

Great! I will give the 1.0.3-SNAPSHOT a try sometime later this week.
Just FYI, I am working on a simple RESTful WS example that uses Jersey
in Server and Client side along with Spring through and through for
multi-layer binding plus authentication and authorization. To be
honest the Jersey mailing list is so helpful that I could not choose
any other JAX-RS implementation :). Thanks a lot.

Best regards,

Imran

> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>



-- 
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