users@jersey.java.net

Re: [Jersey] Problems with jersey-test-framework and Guice

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 26 Aug 2009 11:32:41 +0200

On Aug 25, 2009, at 4:07 PM, Naresh wrote:

> Paul Sandoz wrote:
>>
>> On Aug 25, 2009, at 1:56 PM, Naresh wrote:
>>
>>> Hi,
>>>
>>> is your application a web application? If so, can you try with
>>> EmbeddedGlassFish. I hope it should work, if your web.xml defines
>>> the filters.
>>>
>>> bea wrote:
>>>> Hi everyone,
>>>>
>>>> I've been trying to use a IoC container with jersey-test-
>>>> framework in order to access a PersistenceManager / Factory
>>>> within my tests. I've found that, in order to use Google Guice, I
>>>> need to create the web container and add to it a filter, used for
>>>> the IoC container bootstrapping. I've been stuck with the problem
>>>> for a couple of days, using Grizzly as the lightweight container,
>>>> but found that the test framework may be missing something
>>>> necessary to bootstrap Guice.
>>>>
>>>> I've spotted a couple of changes that may help:
>>>>
>>>> Adding the possibility to the GrizzlyWebContainer class of the
>>>> test-framework
>>>> (com.sun.jersey.test.framework.impl.container.grizzly.web) to add
>>>> a filter (so we could add the GuiceFilter to the filter chain).
>>> The latest version (1.1.2-ea-SNAPSHOT)
>>
>> Latest version in the trunk is now 1.1.3-ea-SNAPSHOT as we are in
>> the process of releasing 1.1.2-ea.
> :) I was kind of confused whether to mention 1.1.2-ea-SNAPSHOT or
> 1.1.3-ea-SNAPSHOT since the release process is still happening.
>>
>>
>>> has this option of adding a filter, but I realized that this
>>> filter class isn't being utilized. I shall try adding this support
>>> in the trunk, and let you know once done, then may be you could
>>> check if it works.
>>>
>>
>> Perhaps it would be best to add a simple Guice sample to the Jersey
>> samples?
> Great idea. I will see if I can help you in this.

See attached for a really simple example i presented at JavaOne, we
can use that as the starting point. Just refactor the classes in the
package "com.sun.jersey.samples.javaone.guice.x" to
"com.sun.jersey.samples.javaone.guice", they were back up classes (in
case i could not type properly or something went wrong when demoing).

Paul.