First, I will introduce you to my testcase before handling my question. There are a few components in my basic Maven Webapplication:
- page.xhtml: Used to generate my request/reply (to initiate filtering)
- Pretty Faces: Used to redefine URLs, based on needs of my client
- FirstFilter: To be executed before Pretty Faces (in this stadium for testing purposes)
- ThirdFilter: To be executed after Pretty Faces (in this stadium for testing purposes)
- web.xml: To define the behaviour of my complete Filter Chain
I will share the code of important components.
pretty-config.xml
<url-mapping id="page">
<pattern value="/page" />
<view-id value="/page.xhtml" />
</url-mapping>
FirstFilter.java
@WebFilter
public class FirstFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("FirstFilter, request: " +
((HttpServletRequest)request).getRequestURL().toString());
chain.doFilter(request, response);
System.out.println("FirstFilter, response");
}
// override init and destroy
}
ThirdFilter.java
@WebFilter
public class ThirdFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("ThirdFilter, request: " +
((HttpServletRequest)request).getRequestURL().toString());
chain.doFilter(request, response);
System.out.println("ThirdFilter, response");
}
// override init and destroy
}
web.xml
<filter>
<filter-name>FirstFilter</filter-name>
<filter-class>nl.mhoogeveen.nl.rootapplication.FirstFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>FirstFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>testingapplications.filterchaining.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher>
</filter-mapping>
<filter>
<filter-name>ThirdFilter</filter-name>
<filter-class>testingapplications.filterchaining.ThirdFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ThirdFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Situation
Calling localhost:8080/page.xhtml (and thus not activating Pretty Faces redirection)
INFO: FirstFilter, request: http://localhost:8080/page.xhtml
INFO: ThirdFilter, request: http://localhost:8080/page.xhtml
INFO: ThirdFilter, response
INFO: FirstFilter, response
Calling localhost:8080/page (and thus activating Pretty Faces redirection)
INFO: FirstFilter, request: http://localhost:8080/page
INFO: FirstFilter, response
Question
What is causing this situation in which my chain will be incomplete? It will not be cut off as I still get my response on the FirstFilter. It just seems like it does not ever reach ThirdFilter.
Is there anything wrong with my web.xml
, am I missing a dispatcher
?
Thanks in advance.