Hello,

Our app launches from void main() with embedded Jetty. 
We try to keep it light weight, and don't have full WebAppContext, instead 
with start with HandlerCollection and simply map the servlets to paths.

I would like to integrate Guice into the mix, I've followed 
http://code.google.com/p/google-guice/wiki/ServletModule and re-factored the 
code to replace Jetty mapping with guiced based approach. I'm not sure if 
my problem is with Jetty or Guice but after switch to Guice serve() mapping 
I can't seem to be able to have any GET requested to be redirected into the 
appropriate servlets, which makes Jetty always return a 404.


My relevant code code snippets:

=== Launcher class:

    public static void main(String[] args) throws Exception {
        Guice.createInjector(
                new MadServingModule(),
                new MadMockModule(),
                new MadTrackModule(),
                new MadMiscModule());

        ServletContextHandler servletContextHandler = new 
ServletContextHandler();
        servletContextHandler.addFilter(new 
FilterHolder(GuiceFilter.class), "/", FilterMapping.ALL);

        Server server = new Server(PORT_NUMBER);
        server.setHandler(servletContextHandler);

        // Init the application itself
        MADServiceMgr.init();

        // ### Launching the application...
        server.start();
        System.out.println(server.dump());
        server.join();
    }

=== MadMiscModule class

public class MadMiscModule extends ServletModule {
    @Override
    protected void configureServlets() {
        // ### STATUS ###
        serve("/status").with(StatusServlet.class);

        // ### STATIC STUFF ###
        serve("/crossdomain.xml").with(CrossdomainServlet.class);
        serve("/robots.txt").with(RobotsTxtServlet.class);
    }
}


I've verified that both GuiceFilter.init() 
and MadMiscModule.configureServlets() methods are called on server startup. 
But sending GET requests does not seem to be intercepted and always result 
in 404.

Seeking integration examples, one mostly finds tips about using Context but 
this interface seems to be deprecated in jetty 7.5 so before I dig deeper I 
would be happy to know if someone here has already integrated Guice with 
Embedded Jetty and would be willing to share his thoughts.

My motivation for having Guice right at the servlet entry point level 
is simplicity, I love the framework and among other great features the 
small "quick wins", for example the @Singleton.


Prior to Guice, our mapping code looked like this:

    __addServlet(ServletContextHandler servletContextHandler, String path, 
Class<? extends Servlet> servletClazz) {
        try {
            servletContextHandler.addServlet(new 
ServletHolder(servletClazz.newInstance()), path);
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }



Thank you,
Maxim.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/hJNBXVtWUF4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to