users@jersey.java.net

[Jersey] Re: docroot when using Grizzly2 server and ServletHandler

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Mon, 09 Jan 2012 17:02:19 -0500

Hi ALeksey,

Per your suggestion, I have created a reproducable test case and filed
an issue here:

http://java.net/jira/browse/JERSEY-911

I would be very grateful for any quick workaround etc. that you could
provide. I suspect / hope its something really trivial with an easy
workaround and may likley be an error on my part rather than a bug.
Thanks very much for all your help.

On 01/09/2012 12:57 PM, Farrukh Najmi wrote:
>
> Hi Alexey,
>
> I think we are getting closer to resolving this.
>
> I now use the following code to add the StaticHttpHandler to my
> ServerConfiguration:
>
> ServerConfiguration serverConfiguration =
> server.getServerConfiguration();
> String cwd = System.getProperty("user.dir");
> String docRootFolder = cwd + "/target/classes/webapp";
> serverConfiguration.addHttpHandler(new
> StaticHttpHandler(docRootFolder), servletHandler.getContextPath() +
> "/static");
>
> The servletHandler.getContextPath() value is "/myserver/rest".
>
> If I comment out the last line of code above then the following URLs
> to my jersey REST endpoint work fine:
>
> http://localhost:9070/myserver/rest/search?queryId=urn:oasis:names:tc:ebxml-regrep:query:BasicQuery&name=%25usa%25
>
> But if I uncomment it then the same query returns a 404 as does the
> following GET request for the static resource readme.txt
>
> http://localhost:9070/myserver/rest/static/readme.txt
>
> Does it seem like I am doing everything as you would expect? Is there
> anything else to try before creating a standalone test case (a lot of
> work) and filing an issue?
> Can any one tell me if they have gottent Grizzly2 server to serve both
> dynamic resource from a jersey endpoint as well as static resources
> using com.sun.jersey.spi.spring.container.servlet.SpringServlet which
> is what I am using.
>
> Thanks again for your help.
>
> On 01/09/2012 12:29 PM, Oleksiy Stashok wrote:
>> Hi Farrukh,
>>
>> Servlet and Static Handlers should be registered in Grizzly with
>> proper mapping, and most probably there is an issue.
>> If you register ServletHandler with some URI, say "/myservlet" - then
>> try to register static handler with "/myservlet/static" URI. In this
>> case all the requests to "/myservlet/static/..." will be redirected
>> to StaticHandler and other requests to "/myservlet/..." will be
>> redirected to ServletHandler.
>>
>> Thanks.
>>
>> WBR,
>> Alexey.
>>
>> PS: you can create an issue and attach the testcase to it.
>>
>>
>> On 01/09/2012 06:09 PM, Farrukh Najmi wrote:
>>>
>>> Hi Alexey,
>>>
>>> Thank you for offering to help. Before I do the fair amount of work
>>> to create a standalone test case I thought to share observations
>>> below in case it helps identify my problem:
>>>
>>> * If I do not call "serverConfiguration.addHttpHandler" on my
>>> HttpServer's configuration then I can get dynamic resources
>>> served by my jersey rest endpoint. This is the base line that
>>> has worked for a long time before I had need for static
>>> resources to be served by same servlet as jersey endpoint
>>> * If I call "serverConfiguration.addHttpHandler" on my
>>> HttpServer then:
>>> o If I specify a context path for the StaticHttpHandler
>>> that is different from the context path for the
>>> ServletHandler for the SpringServlet for my jersey rest
>>> endpoint then I am able to get static resources served
>>> by the StaticHttpHandler. However, then I am no longer
>>> able to get dynamic resources served by my jersey rest
>>> endpoint.
>>> o If I specify a context path for the StaticHttpHandler
>>> that is same as the context path for the ServletHandler
>>> for the SpringServlet for my jersey rest endpoint then I
>>> am not able to get static resources served by the
>>> StaticHttpHandler nor am I able to get dynamic resources
>>> served by my jersey rest endpoint.
>>>
>>> See code fragment in my previous email for reference. It seems that
>>> if I include it my email gets tagged as spam.
>>>
>>> Can you give me a rough sketch of how I create my HttpServer such that:
>>>
>>> * The Grizzly2 server serves static resources (in my case
>>> javascript files) from some context path from my servlet
>>> * The Grizzly2 server serves dynamic HTML resources from my
>>> jersey rest endpoint that references the static javascript
>>> resources within <script> tags
>>> * The reference to static resources is relative to the dynamic
>>> resources rather than absolute
>>>
>>> Thanks for your help.
>>>
>

-- 
Regards,
Farrukh Najmi
Web: http://www.wellfleetsoftware.com