开发者

How to do filter-mapping with servlet-name in Guice Servlet?

开发者 https://www.devze.com 2023-03-31 02:53 出处:网络
In my web.xml I have <filter> <filter-name>authFilter</filter-name> <filter-class>com.mystuff.AuthFilter</filter-class>

In my web.xml I have

<filter>
    <filter-name>authFilter</filter-name>
    <filter-class>com.mystuff.AuthFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>authFilter</filter-name>
    <servlet-name>requestFactoryServlet</servlet-name>
</filter-mapping>

<!-- Servlets -->
<servlet>
    <servlet-name>requestFactoryServlet</servlet-name>
    <servlet-class>com.google.web.bindery.requestfactory.server.RequestFactoryServlet</servlet-class>
    <init-param>
        <param-name>symbolMapsDirectory</param-name>
        <!-- You'll need to compile with -extras and move the symbolMaps directory 
            to this location if you want stack trace deobfusca开发者_如何学Pythontion to work -->
        <param-value>WEB-INF/classes/symbolMaps/</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>requestFactoryServlet</servlet-name>
    <url-pattern>/gwtRequest</url-pattern>
</servlet-mapping>

and I am attempting to convert this to use Guice Servlet configuration rather than the web.xml configuration.

I cannot figure out how to do the equivalent of the of the in Guice. I only see examples of how to filter patterns, not specific servlets.


Define a Guice listener in web.xml :

<listener>
    <listener-class>xxx.GuiceServletConfig</listener-class>
</listener>

And implement this listener :

public class GuiceServletConfig extends GuiceServletContextListener {

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

            @Override
            protected void configureServlets() {
                Map<String, String> params = new HashMap<String, String>();
                params.put("symbolMapsDirectory", "WEB-INF/classes/symbolMaps/");
                serve("/gwtRequest").with(RequestFactoryServlet.class, params);


            }

        });
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号