users@jersey.java.net

Re: Re: [Jersey] JerseyTest and Guice

From: Srinivas Naresh Bhimisetty <shri.naresh_at_gmail.com>
Date: Wed, 27 Oct 2010 00:05:37 +0530

Kristof,

On Tue, Oct 26, 2010 at 11:14 PM, Kristof <kr_adr_at_yahoo.co.uk> wrote:

> Hi Naresh,
>
> I was originally trying the 'addFilter' method but apparently that does not
> work (I'm using version 1.4 for all the jersey libs).
>

  probably there's some bug there.
May be you should log an issue in the issue tracker.

- Naresh


>
> I noticed that in the example you mentioned that the 'filterClass' method
> is used and that does work.
> So now my resource is working and I can inject Guice managed dependencies
> in the its constructor.
>
> Thanks for you help!
> Kristof
>
>
> -------- Original Message -------- Subject: Re: [Jersey] JerseyTest and
> Guice Date: Mon, 25 Oct 2010 10:26:18 +0530 From: Srinivas Naresh
> Bhimisetty <shri.naresh_at_gmail.com> <shri.naresh_at_gmail.com> To:
> users_at_jersey.dev.java.net
>
> Hi Kristof,
>
> On Sun, Oct 24, 2010 at 11:57 PM, Kristof <kr_adr_at_yahoo.co.uk> wrote:
>
>> Hi all,
>>
>> I'm trying to get a unit test running which extends the JerseyTest class
>> and which is configured to use Guice for dependency injection.
>>
>> I'm setting up the JerseyTest by using the constructor which takes a
>> AppDescriptor object which I build using the WebAppDescriptor.Builder
>> functionality.
>>
>> When debugging my test I see that my context listener which configures
>> the Guice Injector with my Guice modules is executed but I think the
>> GuiceFilter is not executed.
>>
>> When I execute my test it fails with an error message stating that no
>> root resource classes are found. I am however binding my Resource in my
>> Guice module like in the examples. eg:
>>
>> bind(HelloWorldResource.class);
>>
>> serve("/*").with(GuiceContainer.class);
>>
>> I'm using the GrizzlyWebTestContainer.
>>
>> It could be that I'm not correctly configuring the GuiceFilter. In a
>> web.xml you defined the name of the filter and the class and also the
>> filter-mapping to the url-pattern for the filter. I don't know how exactly
>> to configure this using the WebAppDescriptor.Builder?
>>
>
> Did you try using the "filterClass()" or "addFilter()" methods?
> Please refer the jersey-guice-filter sample [1].
>
>
>>
>> Or is there a way to point the JerseyTest class to the web.xml and use
>> that instead of configuring it through code?
>>
>
> I do not think this is there yet. Probably, Pavel can give you more
> update.
>
> [1]
> http://download.java.net/maven/2/com/sun/jersey/samples/guicefilter-webapp/1.4/guicefilter-webapp-1.4-project.zip
>
> - Naresh
>
>>
>>
>> Thanks,
>> Kristof
>>
>>
>
>
>