users@jersey.java.net

[Jersey] Grizzly 2 + jersey unit test question

From: Christopher Piggott <cpiggott_at_gmail.com>
Date: Thu, 7 Jun 2012 16:50:28 -0400

http://java.net/projects/jersey/sources/svn/content/trunk/jersey/contribs/jersey-guice/src/test/java/com/sun/jersey/guice/AbstractGuiceGrizzlyTest.java?rev=5717

In this file, line 105, in the tests you create a GuiceFilter (which
makes sense to me) but also a Servlet that does nothing.

Can somebody explain why the servlet?

I'm trying to more or less replicate setting up grizzly2 + guice +
jersey. This was all working great with grizzly 1.9 but I want to
upgrade to grizzly 2, and a lot has changed. What I have so far is
this:

                WebappContext ctx = new WebappContext("hub", "/");
                ctx.addListener(HubContextListener.class);
                FilterRegistration reg = ctx.addFilter("gf", GuiceFilter.class);
                reg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), "/*");

                HttpServer ws = HttpServer.createSimpleServer("/", 8890);
                ctx.deploy(ws);

This isn't exactly the same as that unit test because I'm not using
the jersey-grizzly2 package. I need to create the server myself, I
think, because I have to attach an SSLConfig to it, and I didn't see a
way to do that when you create it through GrizzlyServerFactory
(correct me if I'm wrong here). Either way ... it doesn't seem like
it should be necessary: create an HttpServer and deploy this
WebappContext to it.

What happens is:
 * Server starts on the right port
 * Context listener gets called
    * Main injector gets created
    * My custom container request filter gets created
    * All my root resources and providers get found by
ScanningResourceConfig (yay!)

but when I go to make any request, all that happens is my container
request filter gets hit (which emits some log messages). The request
doesn't seem to go any further than that. It returns a 404. (The
resource module ends with .serve("/*") like usual).

Now, all of this worked under grizzly 1.9.4 OK, but of course the way
you set up the server/filters is completely different.


Any idea what could be wrong?

--Chris