users@jersey.java.net

Re: [Jersey] Basic Authentication in junit TestContainer

From: Patrick Duin <patrick.duin_at_mpi.nl>
Date: Wed, 25 Aug 2010 16:19:06 +0200

On Aug 25, 2010, at 3:41 PM, Pavel Bucek wrote:

> On 8/25/10 2:22 PM, Patrick Duin wrote:
>>
>>
>> On Aug 25, 2010, at 2:00 PM, Pavel Bucek wrote:
>>
>>> On 8/25/10 1:48 PM, Patrick Duin wrote:
>>>>
>>>> Hello,
>>>>
>>>> I am trying to upgrade jersey in my application from 1.1.5 to 1.3
>>>> and I am running into some troubles with my authentication in
>>>> junit tests.
>>>> I am using the grizzly test container with an extra Filter that
>>>> adds a UserPrinciple to my HttpServletRequest.
>>>> My test extends com.sun.jersey.test.framework.JerseyTest and
>>>> overrides:
>>>>
>>>> @Override
>>>> protected AppDescriptor configure() {
>>>> WebAppDescriptor.Builder builder = new
>>>> WebAppDescriptor
>>>> .Builder
>>>> (ComponentRegistryRestService
>>>> .class
>>>> .getPackage().getName()).addFilter(DummySecurityFilter.class,
>>>> "DummySecurityFilter");
>>>> return builder.build();
>>>> }
>>>>
>>>>
>>>> My root resource has the HttpServletRequest injected in a field
>>>> like this:
>>>> @Context
>>>> private HttpServletRequest request;
>>>>
>>>> In my tests I then create a request with the proper
>>>> authentication in the header. This works fine for most of my
>>>> tests. I have one test that does some concurrent requests, it
>>>> fails sometimes. The Grizzly FilterChain is not threadsafe and
>>>> fails on a nullpointer when using extra filters (this is in the
>>>> grizzly version 1.9.18-i used by jersey-test-framework-
>>>> grizzly-1.3). It is supposed to be fixed in grizzly 1.9.19
>>>> version. Is there any workaround at the moment, am I doing
>>>> something wrong to get this server authentication working?
>>>>
>>>> What I have tried:
>>>> - Use newer version of grizzly, but that is not compatible with
>>>> the Jersey-test-framework-grizzly at the moment.
>>> what does this mean? I'm able to build jersey-test-framework-
>>> grizzly with 1.9.19 without problems.. (I'm going to update this
>>> dependency in the trunk right now)
>> Sorry my bad, I couln't find the 1.9.19 version from http://download.java.net/maven/2
>> so I downloaded it from the grizzly website and installed it to my
>> local maven repo. I forgot to add the transitive dependencies so I
>> got some class not found errors. Bad idea to test these things
>> after a long day of debugging. Are the 1.9.19 versions available
>> from a public maven repo? I would love to test this.
> yes, looks like 1.9.19 is available, but in the java.net *glassfish*
> repo - see http://download.java.net/maven/glassfish/com/sun/grizzly/grizzly-servlet-webserver/

Thank you my tests are working again!
I am now using:
     <dependency>
       <groupId>com.sun.jersey.jersey-test-framework</groupId>
       <artifactId>jersey-test-framework-grizzly</artifactId>
       <version>1.3</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>com.sun.grizzly</groupId>
       <artifactId>grizzly-servlet-webserver</artifactId>
       <version>1.9.19</version>
       <scope>test</scope>
     </dependency>
I will update to jersey 1.4 when available. Thanks for the quick
replies, you helped a lot.

Cheers,
  Patrick.