vaadin / vaadin/spring

Custom HandlerMapping to avoid conflicts between vaadinRootMapping and resourceHandlerMapping

Open
#604 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
186
Forks
98
PR merge metrics
No merged PRs in 30d

Description

This is a follow-up to #602.

When no vaadin.urlMapping is defined, both vaadinRootMapping (VaadinServletConfiguration) and resourceHandlerMapping (WebMvcConfigurationSupport) will map to /* or /**.
With the vaadinRootMapping having higher precedence, the resourceHandlerMapping can no longer serve static resources.
So the idea is, instead of using the purely URL-pattern-based SimpleUrlHandlerMapping for the vaadinRootMapping, create a custom implementation, that only captures requests that we know are intended for Vaadin and ignore all others so the resourceHandlerMapping can handle them.

The general gist is: Requests are captured and directed to the VaadinServlet if

  1. they have a parameter named ApplicationConstants.REQUEST_TYPE_PARAMETER with any of the known RequestTypes.
  2. their URL starts with /vaadinServlet/ or /VAADIN/
  3. The SessionRouteRegistry (if there is a session) or ApplicationRouteRegistry (if there isn't) have a navigation target for the URL.

[My prototype (feel free to use it) so far seemed to work pretty well.] (https://gist.github.com/Frettman/778e98ac2c4fdc4ceffc12423f929d4a) Both Vaadin and static resources living happily together in the servlet root. There was one major issue though:
When persistent sessions are restored, the VaadinSessions are still lacking some transient information, like the lock. Usually that information will be restored once the request passes through the VaadinServlet. This hasn't happened yet in the HandlerMapping. The VaadinService might not even exist yet, if the VaadinServlet hasn't received any requests yet (I suppose servlets are lazily initialized?).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing VaadinServletConfiguration, WebMvcConfigurationSupport, and the existing SimpleUrlHandlerMapping behavior. Trace how VaadinServlet, SessionRouteRegistry, ApplicationRouteRegistry, and VaadinService participate in request handling and session restoration. Done means Vaadin requests are routed correctly while resourceHandlerMapping still serves static resources, including after persistent sessions are restored.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, web-dev
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.