Vaadin request filter with filter chain?

1.4k Views Asked by At

Is there a way in Vaadin to hook into a request chain and perform operations around the real request/response cycle with VaadinSession provided? Currently I use javax.servlet.Filter, but it seems that VaadinSession.getCurrent() is set somewhere deeper, and in the filter itself it is unset both before and after chain.doFilter().

1

There are 1 best solutions below

0
On

I have found a workaround. First of all, I can't plug into a request handler chain, as there is no such structure. To simulate it, I have split my code into pre-request and post-request code (It's somewhat OK in my case). I'm doing my pre-request stuff in an ordinary VaadinRequestHandler and returning false (for a normal request to proceed). Post-request stuff goes to a javax.serlvet.Filter mapped in web.xml.

Second, if anybody else is having the same problem, and the code is also splittable using the same pattern, here is the a pre-request (vaadin-side) listing:

public class MyVaadinServlet extends VaadinServlet{
    @Override
    protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration) throws ServiceException {
        VaadinServletService service = new VaadinServletService(this,
                deploymentConfiguration){
            @Override
            protected List<RequestHandler> createRequestHandlers() throws ServiceException {
                List<RequestHandler> handlers = super.createRequestHandlers();
                handlers.add((session, request, response) -> {
                    // HERE GOES THE CODE
                    return false;
                });
                return handlers;
            }
        };
        service.init();
        return service;
    }
}