Search code examples
javaservletsjax-rsjersey-2.0forward

Invoke Jersey 2.x filter chain when using RequestDispatcher.forward


Does anyone has an idea, how to handle filters correctly within an Jersey-2.x application when using RequestDispatcher.forward()?

RequestDispatcher dispatcher=pCtx.getRequestDispatcher("/app2");    
dispatcher.forward(request, response);

When I do a forward between two webapps, both using Jersey-2.5+, the webapp that is being redirected to, contains request filters. They should be invoked when doing the forward (like when requesting the app directly) but are not.

Several post do outline to use the <filter-mapping> element with the <dispatcher> tag in the web.xml, like here. But this looks to me like javax servlet filters and I am not sure how to include this, if ever possible.

Is there a way to achieve the same with Jersey-2.x filters?

UPDATE:

My ContainerRequestFilters are post-matching filters, as they are not annotated with @PreMatching


Solution

  • As I found out, the RequestFilters are actually invoked. I didn't recognise that by mistake. What really is not invoked, is tomcat container authentication like a realm. But this is clear to me, as we already passed tomcat layer when the request is processed by any application.