On Mar 23, 2009, at 4:00 PM, Mats Henricson wrote:
> Hi!
>
> I'm trying to setup HTTP JUnit test of the Jersey resources, and
> after long struggles
> I managed to get Grizzly setup in my @Before function:
>
> @Before
> public void setup() throws IllegalArgumentException, IOException {
> final Map<String, String> initParams = new HashMap<String,
> String>();
>
> initParams.put("com.sun.jersey.config.property.packages",
> packageName);
>
> initParams.put("com.sun.jersey.config.property.resourceConfigClass",
> MyApplication.class.getName());
>
> threadSelector = GrizzlyWebContainerFactory.create(baseUri,
> initParams);
> }
>
> Then I create a java.net.URL object, open a stream and read. This
> works fine,
> except I can't get the config to understand my ExceptionMapper
> classes, so all
> sunshine tests works fine, and all failure tests fail with
> exceptions, instead of
> being mapped to proper Response objects by my ExceptionMappers.
>
> So, how would I do that? Is that because my mappers aren't in the
> same package
> as my resources?
>
I presume so. Root resource and provider classes will be scanned for
given the ";" separated list of package names.
You should get a logged output presenting the scanned root resource
and provider classes found.
The configuration you are using above may or may not be correct. Is
your MyApplication class extending from PackagesResourceConfig ?
Paul.