users@jersey.java.net

Re: [Jersey] Basic Authentication in junit TestContainer

From: Patrick Duin <patrick.duin_at_mpi.nl>
Date: Thu, 26 Aug 2010 12:08:39 +0200

On Aug 26, 2010, at 11:38 AM, Pavel Bucek wrote:

> On 8/25/10 4:19 PM, Patrick Duin wrote:
>>
>>
>> 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.
>
> I had to revert back to 1.9.18-i, 1.9.19 breaks some osgi related
> tests; I'm not very familiar with OSGi, so I created a task for
> Jakub [1]. It might not get into 1.4 release.. (Jakub is on vacation
> right now). Sorry for troubles.
>
> Pavel
>
> [1] https://jersey.dev.java.net/issues/show_bug.cgi?id=576

No problem I can work like this I am not using osgi. It seems to work
fine, I will keep an eye on the next releases, so I can clean up the
dependencies again.

>
>>
>> Cheers,
>> Patrick.
>>
>>
>