users@jersey.java.net

Re: [Jersey] embedding jersey inside GrizzlyWebServer

From: Zoltan Arnold NAGY <Zoltan.Nagy_at_Sun.COM>
Date: Tue, 28 Apr 2009 13:20:24 +0200

Paul Sandoz wrote:
>
> On Apr 28, 2009, at 12:32 PM, Zoltan Arnold NAGY wrote:
>
>> Paul Sandoz wrote:
>>>
>>> The problem is specific to the way the the initialization parameter
>>> is set.
>>>
>>> You need to call:
>>>
>>> jerseyAdapter.addInitParameter("javax.ws.rs.Application",
>>> JerseyAdaptor.class.getName());
>> you're right, I missed the part where I had to use addInitParameter
>> instead of setParameter :)
>>
>> but still no luck, it's not working.
>>
>> first I tried to whip up a simple, one-file example, but apperently,
>> the packages must be public
>> in order to work this way
>>
>
> Use inner public static classes and it should work fine.
ok, that did it. should have thought of that. :)
>
>
>> (else I'd get Caused by: java.lang.IllegalAccessException:
>> Class com.sun.jersey.spi.container.servlet.WebComponent can not
>> access a member of class JerseyAdaptor with modifiers "",
>> which is okay from the stacktrace, as the container is in an other
>> package, so cant see mine.)
>>
>> so I split them up. Here's the complete code:
>> http://nagyz.pastebin.com/m5d97e7db
>>
>> I get a 404 when I try to access it, so it seems Jersey hasnt
>> discovered my resource.
>>
>
> What is the URI you are using?
>
> http://localhost:7000/jersey/helloworld
>
> ?
yep.
> I have not tried using Jersey with the following:
>
> ws.addGrizzlyAdapter(jerseyAdapter, new String[] { "/jersey" });
>
> The Jersey ServletContainer needs to know the correct base URI that
> the resource classes are deployed at and i am wondering if this is an
> issue.
>
> You might want to try the following instead:
>
> adapter.setContextPath("/jersey");
>
that did the trick!

as always, thanks :)
> Generally when using Grizzly i tend to use the Jersey/Grizzly factory
> mechanisms, if i do not require any additional Grizzly configuration:
>
> https://jersey.dev.java.net/nonav/apidocs/1.0.3/jersey/com/sun/jersey/api/container/grizzly/GrizzlyWebContainerFactory.html
>
saw that, but I'm writing a lightweight IoC container (for educational
purposes, mainly teaching advanced java), and wanted to
plug jersey into the current architecture.

but it's working now as it should.

Thanks for your help!

Zoltan