I am using a @WebFilter with urlMapping = "/*" option. (Also tried with servlet). I use it to manage my oAuth single sign ons. It runs fine on local with tomcat on eclipse.
On prod it throws a 404. Disabling the filter(thus, by passing the filter) works fine.
Any pointers anyone?
AppConfig.java:
@Configuration
@EnableWebMvc
@EnableAsync
@ComponentScan(basePackages = "com.my.package")
public class AppConfig extends WebMvcConfigurerAdapter implements AsyncConfigurer {
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/");
viewResolver.setSuffix(".html");
viewResolver.setExposeContextBeansAsAttributes(true);
return viewResolver;
}
@Bean
public ViewResolver contentNegotiatingViewResolver() {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
List<ViewResolver> viewResolvers = new ArrayList<ViewResolver>();
viewResolvers.add(viewResolver());
resolver.setViewResolvers(viewResolvers);
return resolver;
}
AppInitializer.java:
public class AppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext container) throws ServletException {
//container.addFilter("name", AccessFilter.class);//Have tried toggling this
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
//configuration mapping
ctx.register(AppConfig.class);
ctx.setServletContext(container);
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}
MyFilter.java:
//@WebFilter(urlPatterns = "/*") //Commenting this out works fine. Problem is surely with the filter.
public class AccessFilter implements Filter {
SSOHelper ssoHelper;
public void init(FilterConfig filterConfig) throws ServletException {
//init the helper and internal property objects
System.out.println("Filter init for dispatcher servlet");
ssoHelper = new SSOHelper();
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
//This is never hit when applied on prod. Local runs as expected.
}