Skip to content

Allow implementing RequestHandler's that do not need VaadinSession creation #23306

@mcollovati

Description

@mcollovati

Describe your motivation

There are cases where you want to implement a RequestHandler that do not need at all the existence of a VaadinSession. One example is the TranslationFileRequestHandler that only needs a reference to VaadinService to properly work with and without a session.
However, this is currently not supported since request handlers are invoked after VaadinService attempts to get or create VaadinSession, potentially causing an exception to be raised.

A workaround for now is to make the request handler implement SessionExpiredHandler so it will be called even if the session cannot be created.

Describe the solution you'd like

A better solution would be that the request handler can specify if it needs a valid session or not, and if so, it could be invoked before the service attempts to create or get one.
An idea could be to add an additional handleRequest(VaadinRequest request, VaadinResponse response) method to the RequestHandler interface, and make VaadinService always call at the start of the request processing. The method could have a no-op default implementation, so it would not be a braking change.

Describe alternatives you've considered

Making the request handler implement SessionExpiredHandler and call the logic also from that method if the request matches the criteria.

Additional context

See #23239 for an example of the implementation of the workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Inbox (needs triage)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions