users@jersey.java.net

[Jersey] Re: Explicitly declare the root resource and provider classes - not working for provider class

From: Glen Mazza <gmazza_at_talend.com>
Date: Thu, 1 Mar 2012 08:50:26 -0500

Whew! Looks like you need a vacation now. :) I'm happy to see you got
it working, and am impressed with your no-quit determination.

Glen

On 03/01/2012 08:45 AM, Farrukh Najmi wrote:
> I was finally able to get my jersey rest end point to work inside an
> app that was launched via JNLP / java webstart. It was painful because
> i had to do the following...
>
> * Replace spring based bean config with hard-coded bean creation
> * Replace org.glassfish.grizzly.servlet.ServletHandler based Grizzly
> HttpServer creation with ResourceConfig based Grizzly HttpServer
> creation
> * Replace code in root resources that used
> HttpServletRequest/HttpServletResponse Context params
> * Upgrade from default Grizzly version for jersey 1.10 to grizzly
> 2.1.10 to get fix for http://java.net/jira/browse/GRIZZLY-1208
> (thank Oleksiy Stashok for the quick fix!)
> * Replace package scaning for root resources and provider classes by
> extending DefaultResourceConfig and defining a getSingleton()
> override method to explicitly declared root resources and provider
> classes
>
> All this was necessary because package scanning for root resources and
> provider classes do not seem to work inside java webstart for reasons
> I do not understand.
>
> I have created http://java.net/jira/browse/JERSEY-999 to see if the
> root issue could be addressed. Thanks to Glen Mazza and Oleksiy
> Stashok for their kind help.
>
> On 02/29/2012 09:02 AM, Farrukh Najmi wrote:
>>
>> I was using a org.glassfish.grizzly.servlet.ServletHandler to create
>> the HttpServer as follows:
>>
>> import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
>> import org.glassfish.grizzly.http.server.HttpServer;
>> import org.glassfish.grizzly.http.server.ServerConfiguration;
>> import org.glassfish.grizzly.http.server.StaticHttpHandler;
>> import org.glassfish.grizzly.servlet.ServletHandler;
>>
>> ...
>> URI uri = ...
>> ServletHandler servletHandler = new ServletHandler();
>> HttpServer server = GrizzlyServerFactory.createHttpServer(uri,
>> servletHandler, false);
>>
>> So I tried the following to use jersey ContainerFactory to create my
>> handler so it takes into account my ResourceConfig (so I can
>> explicitly set root resource and provider classes so I can run my
>> jersey server inside a webstart / jnlp launched app):
>>
>> ServletHandler servletHandler =
>> ContainerFactory.createContainer(ServletHandler.class, resourceConfig);
>> HttpServer server = GrizzlyServerFactory.createHttpServer(uri,
>> servletHandler, false);
>>
>>
>> The problem I get is:
>>
>> No container provider supports the type class
>> org.glassfish.grizzly.servlet.ServletHandler
>>
>> com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:196)
>>
>> com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:134)
>>
>> I am on my 5th day trying to get an app with a jersey server endpoint
>> that worked fine standalone to work in javawebstart environment.
>>
>> I feel I am close but at the end of my knowledge of jersey to get
>> this seemingly simple problem solved:
>>
>> How to explicitly declare the root resource and provider classes when
>> using a ServletHandler in creating the Grizzly server.
>>
>> Any other ideas from the jesrey dev team?
>>
>> On 02/28/2012 08:04 PM, Glen Mazza wrote:
>>> Just more detective work, basically see what Jersey does
>>> behind-the-scenes. Go to grepcode on "GrizzlyServerFactory" -- line
>>> 75 in the Main.java I linked to below. You'll see what Jersey does:
>>> http://grepcode.com/file/repo1.maven.org/maven2/com.sun.jersey/jersey-grizzly2/1.11/com/sun/jersey/api/container/grizzly2/GrizzlyServerFactory.java#GrizzlyServerFactory.createHttpServer%28java.net.URI%2Ccom.sun.jersey.api.container.grizzly2.ResourceConfig%29
>>>
>>> I see an HttpHandler in that method, so I'll leave the rest to you
>>> as an exercise. :)
>>>
>>> Glen
>>>
>>>
>>> On 02/28/2012 07:36 PM, Farrukh Najmi wrote:
>>>> On 02/28/2012 01:22 PM, Glen Mazza wrote:
>>>>> On 02/28/2012 01:04 PM, Farrukh Najmi wrote:
>>>>>> BTW, when I set breakpoints inside my getClasses() and
>>>>>> getSingletons() methods of my "class HubSubscriber extends
>>>>>> javax.ws.rs.core.Application" I find they are never called!
>>>>>
>>>>> Did you remember to wire your Application subclass in like here:
>>>>> http://java.net/projects/jersey/sources/svn/content/tags/jersey-1.11/jersey/samples/jacksonjsonprovider/src/main/java/com/sun/jersey/samples/jacksonjsonprovider/Main.java?rev=5665
>>>>> (lines 72-75)? Also, I'd try a System.out.println() in those two
>>>>> methods to confirm they're not being called -- it could be the
>>>>> debugger is wrong for some reason.
>>>>
>>>> I did not do that! So that explains why the getClasses() and
>>>> getSingletons() methods are not being called.
>>>>
>>>> Now here is my problem. I am using the following method
>>>> <http://grepcode.com/file/repo1.maven.org/maven2/com.sun.jersey/jersey-grizzly2/1.10/com/sun/jersey/api/container/grizzly2/GrizzlyServerFactory.java#GrizzlyServerFactory.createHttpServer%28java.net.URI%2Ccom.sun.jersey.api.container.grizzly2.HttpHandler%2Cboolean%29>
>>>> to create my HttpServer. I need to specify an HttpHandler. So how
>>>> do I pass it a ResourceConfig instance? I think there is a way to
>>>> create an HttpHandler with a specified ResourceConfig but I do not
>>>> know how to do that. Any advice?
>>>>
>>>> Thanks again for your kind help.
>>
>
> --
> Regards,
> Farrukh Najmi
>
> Web:http://www.wellfleetsoftware.com
>


-- 
Glen Mazza
Talend Community Coders - coders.talend.com
blog: www.jroller.com/gmazza