RequestHandler not working on first loading

Context:
My development server is a tomcat 6 (vaadin 7.2.4), running on http://127.0.0.1:8080 and my application is called FOO.
I’ve added a RequestHandler to allow download clients retrieve required information depending on the URL, for instance http://127.0.0.1:8080 /FOO/sigup should sign-up a new user and return status message whether user was created.

I added my request handler in the init() method of my LegacyApplication class.

Problem:
The first time(after a server restart) that I visit this page: http://127.0.0.1:8080/FOO/signup, my request handler is not invoked. Reloading the page (F5) makes it works.

When using NET-Web-Client the request handler will never be invoked as each request is a new one and there is no F5-option.

As far as I see the problem is that my request handler is added after SessionServletHandler handles the request (where it queries for request handlers from session):

VaadinSession.getRequestHandlers() line: 714    
SessionRequestHandler.handleRequest(VaadinSession, VaadinRequest, VaadinResponse) line: 57    
VaadinServletService(VaadinService).handleRequest(VaadinRequest, VaadinResponse) line: 1405    
LegacyVaadinServlet(VaadinServlet).service(HttpServletRequest, HttpServletResponse) line: 237    
LegacyVaadinServlet(HttpServlet).service(ServletRequest, ServletResponse) line: 717    
ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 290    

At this point VaadinSession.getRequestHandlers() has no custom request handlers. These are added later:

VaadinSession.addRequestHandler(RequestHandler) line: 683    
MyApplication.init() line: 91    
MyApplication(LegacyApplication).doInit(URL) line: 83    
LegacyVaadinServlet$1(LegacyApplicationUIProvider).getApplication() line: 137    
LegacyVaadinServlet$1(LegacyApplicationUIProvider).getUIInstance(UIProviderEvent) line: 89    
LegacyVaadinServlet$1(LegacyApplicationUIProvider).getUIClass(UIClassSelectionEvent) line: 45    
ServletBootstrapHandler(BootstrapHandler).synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse) line: 168    

So far I have found a suggestion to derive from LegacyVaadinServlet and add the request handler in servlet:

[code]
public class MyServlet extends VaadinServlet {
private final RequestHandler requestHandler = new RequestHandler()
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

    getService().addSessionInitListener(new SessionInitListener() {
        @Override
        public void sessionInit(SessionInitEvent event)
                throws ServiceException {
            event.getSession().addRequestHandler(requestHandler);
        }
    });
}

}
[/code]In this case however a number of request handlers increase over a number of server requests, i.e. requestHandlers in VaadinSession contains with each new request a new instance of my custom request handler.

So the questions are:

  • is there a chance that the behavior will be changed in one of next vaadin versions?
  • what is a right way to remove a session init listener after request has been handled?