Squarespace / jersey2-guice

Jersey 2.0 w/ Guice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unclear how to use JerseyGuiceServletContextListener.

dlazerka opened this issue · comments

Hi Roger, nice tool!
By reading User Guide it's still a mystery for me on how to use JerseyGuiceServletContextListener. E.g. where to put Jersey config, or where to put pre-jersey filters.

package com.mypackage;

public class MyListener extends JerseyGuiceServletContextListener {

  @Override
  protected List<? extends Module> modules() {
    return Arrays.asList(new ServletModule(), new MyModule());
  }
}
// web.xml
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">

 <display-name>Example</display-name>

 <listener>
 <listener-class>com.mypackage.MyListener</listener-class>
 </listener>

 <filter>
 <filter-name>guiceFilter</filter-name>
 <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
 </filter>

 <filter-mapping>
 <filter-name>guiceFilter</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>

</web-app>

Thank you, but I meant:

  1. Jersey config -- exactly the same question as #15.
  2. Pre-jersey filter that is handled Guice. E.g. in Jersey 1 I could do filter("/*").through(MyFilter.class); in configureServlets(), because it went through guice-servlet.

I have doubt about GuiceContainer, for example in jersey 1.x we have used:

public class GuiceServletConfig extends GuiceServletContextListener {

     @Override
     protected Injector getInjector() {
         return Guice.createInjector(new JerseyServletModule() {

             @Override
             protected void configureServlets() {
                 bind(GuiceResource.class);

                 Map<String, String> params = new HashMap<String, String>();
                 params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "unbound");
                 serve("/*").with(GuiceContainer.class, params);
             }
         });
     }

}

And about GuiceContainer, do you have any example to clarify that?

Same question here.
A more elaborate "examples" section would be very helpful.

Same question here too.