users@grizzly.java.net

Re: embedded grizzly + jersey + static files

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Fri, 07 Aug 2009 11:02:49 +0200

Hi Adam,

I think your last example was almost correct:

> 4. Add an "empty adaptor" as recommended here:
> http://blogs.sun.com/japod/entry/jersey_aplication_sharing_grizzly_with#comment-1244846255000
> _webServer = new GrizzlyWebServer(port, docRoot.getAbsolutePath());
> ServletAdapter jerseyAdapter = new ServletAdapter();
>
> jerseyAdapter
> .addInitParameter("com.sun.jersey.config.property.packages",
> "mdt.web.jersey");
> jerseyAdapter.setServletInstance(new ServletContainer());
> _webServer.addGrizzlyAdapter(jerseyAdapter, new String[] { "/" });
> _webServer.addGrizzlyAdapter(new GrizzlyAdapter() {
> @Override
> public void service(GrizzlyRequest request, GrizzlyResponse
> response) {
> }
> }, new String[] { "/" });
>
> _webServer.start();


though, you mapped grizzly empty adapter and jersey adapter to the
same path ("/");
Try to register jersey following way:

_webServer.addGrizzlyAdapter(jerseyAdapter, new String[] { "/jersey" });

and access your jersey resources via:
http://localhost:<port>/jersey

Hope this will help.

WBR,
Alexey.



On Aug 6, 2009, at 17:10 , Adam Rabung wrote:

> Hello, I am trying to use embedded Grizzly to serve static files and
> Jersey requests. I am trying to do this using the servlet-deployer
> class GrizzlyWebServer. I cannot seem to successfully serve static
> content and Jersey resources at the same time. I am using:
> grizzly-servlet-deployer-1.9.18-SNAPSHOT.jar
> grizzly-servlet-webserver-1.9.8.jar
> jersey-core-1.1.1-ea.jar
> jersey-server-1.1.1-ea.jar
>
> Below are my various attempts to do this - can someone point out my
> error? I'm unclear about what's expected for the String array passed
> in to addGrizzlyAdapter. Any help would be much appreciated.
>
> 1. No jersey adapter - serves static fine:
> private void launchGrizzly(int port, File docRoot) throws Exception {
> _webServer = new GrizzlyWebServer(port, docRoot.getAbsolutePath());
> _webServer.start();
> }
> Result: 200/serves static file
>
> 2. Simplest possible jersey adapter added:
> _webServer = new GrizzlyWebServer(port, docRoot.getAbsolutePath());
> ServletAdapter jerseyAdapter = new ServletAdapter();
>
> jerseyAdapter
> .addInitParameter("com.sun.jersey.config.property.packages",
> "mdt.web.jersey");
> jerseyAdapter.setServletInstance(new ServletContainer());
> _webServer.addGrizzlyAdapter(jerseyAdapter, new String[] {});
> _webServer.start();
> Result: 404
>
> 3. Perhaps that empty string array for the "mapping" for
> addGrizzlyAdapter is incorrect - let's move jersey out of the way:
> _webServer = new GrizzlyWebServer(port, docRoot.getAbsolutePath());
> ServletAdapter jerseyAdapter = new ServletAdapter();
>
> jerseyAdapter
> .addInitParameter("com.sun.jersey.config.property.packages",
> "mdt.web.jersey");
> jerseyAdapter.setServletInstance(new ServletContainer());
> _webServer.addGrizzlyAdapter(jerseyAdapter, new String[] { "/
> jersey" });
> _webServer.start();
> Result: 404
>
> 4. Add an "empty adaptor" as recommended here:
> http://blogs.sun.com/japod/entry/jersey_aplication_sharing_grizzly_with#comment-1244846255000
> _webServer = new GrizzlyWebServer(port, docRoot.getAbsolutePath());
> ServletAdapter jerseyAdapter = new ServletAdapter();
>
> jerseyAdapter
> .addInitParameter("com.sun.jersey.config.property.packages",
> "mdt.web.jersey");
> jerseyAdapter.setServletInstance(new ServletContainer());
> _webServer.addGrizzlyAdapter(jerseyAdapter, new String[] { "/" });
> _webServer.addGrizzlyAdapter(new GrizzlyAdapter() {
> @Override
> public void service(GrizzlyRequest request, GrizzlyResponse
> response) {
> }
> }, new String[] { "/" });
>
> _webServer.start();
> Result: 200/OK, but no content is served:
> < HTTP/1.1 200 OK
> < Content-Length: 0
> < Date: Thu, 06 Aug 2009 14:23:25 GMT
> Unfortunately, this also happens for requests for bad requests that
> should return a 404.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>