Interface SessionlessRequestHandler

All Superinterfaces:
Serializable
All Known Implementing Classes:
FaviconHandler, TranslationFileRequestHandler, WebComponentProvider
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface SessionlessRequestHandler extends Serializable
A request handler for requests that do not need a VaadinSession, such as a resource that is the same for every user.

The service calls handleRequest(VaadinRequest, VaadinResponse) before it looks up the session of the request, so the handler runs the same way whether or not the request has a session, never creates one and does not lock it. VaadinSession.getCurrent() is null while it runs.

Request interceptors still run for the request before the handler. An interceptor that uses an existing session, such as the daily active user tracking, may lock that session in VaadinRequestInterceptor.requestStart(VaadinRequest, VaadinResponse), so the request can then wait for the session lock before the handler is called.

Not creating a session matters when a browser that has no session cookie yet sends several requests in parallel, for example a page that embeds an exported web component: each new session would replace the cookie of the previous one, leaving the browser with a cookie for a session other than the one its UI was created in.

Register the handler with ServiceInitEvent.addSessionlessRequestHandler(SessionlessRequestHandler). All registered sessionless handlers are asked before any RequestHandler, in the order of VaadinService.getSessionlessRequestHandlers(). A request that none of them handles continues to the session lookup and the request handlers.

Since:
25.4
Author:
Vaadin Ltd
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Called for every request before the service looks up its session.
  • Method Details

    • handleRequest

      boolean handleRequest(VaadinRequest request, VaadinResponse response) throws IOException
      Called for every request before the service looks up its session. If a response is written, this method should return true to indicate that no more request handlers should be invoked for the request.
      Parameters:
      request - the request to handle
      response - the response object to which a response can be written
      Returns:
      true if a response has been written and no further request handlers should be called, otherwise false
      Throws:
      IOException - if an IO error occurred