Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin request filter with filter chain?

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().

like image 375
Askar Kalykov Avatar asked Nov 28 '25 11:11

Askar Kalykov


1 Answers

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;
    }
}
like image 187
Askar Kalykov Avatar answered Dec 01 '25 02:12

Askar Kalykov