How to use Guice Servlet with a wicket

After setting up my Wicket project using Guice Servlet, I get java.lang.IllegalStateException: filter path was not configured . However, the filter path is configured. Did I miss something?

web.xml

 <?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>node-sitter</display-name> <listener> <listener-class>com.mycompany.wicketapp.inject.ServletConfig</listener-class> </listener> <filter> <description>Initialises Guice</description> <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> 

Guice Servlet Listener:

 public class ServletConfig extends GuiceServletContextListener { @Override protected Injector getInjector() { return Guice.createInjector(new Servlets()); } private static class Servlets extends ServletModule { @Override protected void configureServlets() { bind(WicketFilter.class).in(Singleton.class); filterRegex("/.*").through(WicketFilter.class, withApplicationClass(WicketApplication.class)); } private Map<String, String> withApplicationClass(Class<? extends WebApplication> applicationClass) { Map<String, String> initParams = new HashMap<String, String>(1); initParams.put("applicationClassName", applicationClass.getName()); return initParams; } } } 

Stack Trace (when the page is visited):

 java.lang.IllegalStateException: filter path was not configured at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:124) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194) at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163) at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58) at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118) at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:474) 
+4
source share
1 answer

Apparently , this problem can be fixed by adding the following init parameter to the filter:

 initParams.put(WicketFilter.FILTER_MAPPING_PARAM, "/*"); 
+9
source

Source: https://habr.com/ru/post/1345973/


All Articles