Search the FirstSpirit Knowledge Base
Hi,
we want to intercept requests in ContentCreator by using a javax.servlet.Filter. But it won't get triggered. I just see that the init() method is called but never the doFilter() in ContentCreator. The same filter works perfectly fine on the ROOT webapp.
The filter dis declared via web.xml and should listen via * to any url.
I wonder if this has something to do with the use of Spring boot in ContentCreator.
Hi Sebastian,
can you please have a look at the merged web.xml in the deployment directory of your Servlet Container? Does it list the filter as expected?
Alternatively you can annotate your filter with the Component annotation which is part of spring-context. Do not add this dependency to your module though, just include it in your build with compileOnly (Gradle) or provided (Maven). It would be best to choose a version that is similar to that shipped with the ContentCreator module you are using.
Hi,
thanks for helping me out. The combined web.xml looks good to me (here is the start of the file grapped directly from the fs5webedit.war)
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="global_fs5webedit" metadata-complete="false" version="3.0" 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_3_0.xsd">
<display-name>global_fs5webedit</display-name>
<description>Lorem Ipsum</description>
<description>WebApp to provide all classes.</description>
<description>WebApp to provide all classes.</description>
<description>WebApp to provide all classes.</description>
<description>WebApp to provide all classes.</description>
<description>WebApp to provide all classes.</description>
<filter>
<filter-name>CustomWebeditLogoutFilter</filter-name>
<filter-class>com.xxx.yyy.contentcreator.ConfigurableLogoutFilter</filter-class>
<init-param>
<param-name>customRedirectUrl</param-name>
<param-value>https://yyy.xxx.com/FIRSTspiritWeb/permlink/wcms_bd_-wcms_webclient-DE</param-value>
</init-param>
<init-param>
<param-name>useCustomRedirectUrl</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>SamlLoginFilter</filter-name>
<filter-class>com.xxx.yyy.login.SamlLoginFilter</filter-class>
<init-param>
<param-name>samlReferrer</param-name>
<param-value>login.microsoftonline.com</param-value>
</init-param>
<init-param>
<param-name>redirect</param-name>
<param-value>https://yyy%s.xxx.com/FIRSTspiritWeb/redirect/wcms/complete?%s</param-value>
</init-param>
</filter>
<filter>
<filter-name>BrowserCachingFilter</filter-name>
<filter-class>de.espirit.firstspirit.webedit.server.BrowserCachingFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>CustomWebeditLogoutFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CustomWebeditLogoutFilter</filter-name>
<url-pattern>/logout</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>CustomWebeditLogoutFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>SamlLoginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>SamlLoginFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>BrowserCachingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<context-param>
<param-name>firstspirit.host</param-name>
<param-value>localhost</param-value>
</context-param>
The filter itself looks something like this
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
/**
*
*/
// @WebFilter(urlPatterns = {"*"}, description = "My filter ")
// @Component
public class CachingFilter implements Filter {
private static final Logger LOGGER = LoggerFactory.getLogger(CachingFilter.class);
private static final String HTTP_HEADER = "cache_used";
@Override
public final void init(final FilterConfig filterConfig) {
LOGGER.info("Init CachingFilter");
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
LOGGER.info("doFilter");
if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse)) {
filterChain.doFilter(request, response);
return;
}
LOGGER.info("##############" + ((HttpServletRequest) request).getContextPath());
(....)
}
@Override
public void destroy() {
}
}
I tried with declaration in web.xml, "@Component" and "@WebFilter" but with no success. I see the log message "Init CachingFilter" from the "init()" method in the log but never the ones inside the "doFilter()" method.