vaadin / vaadin/spring

StreamResource handling is broken in Spring applications

Open
#273 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

@Legioth commented on Wed Jan 03 2018

A simple link for downloading a dynamically generated file does not work in the Spring skeleton starter, but the same code works as expected in the non-spring skeleton starter.

StreamResource resource = new StreamResource("filename", () -> new ByteArrayInputStream("Hello world".getBytes()));
Anchor download = new Anchor("", "Download configuration");
download.getElement().setAttribute("href", resource);

In the Spring case, the target URL seems to trigger the RouteNotFoundError handler instead of serving the StreamResource contents.


@Legioth commented on Wed Jan 03 2018

This seems to be caused by the way the servlet is mapped when using Spring.

Requests reaching StreamRequestHandler have the VAADIN/ part of the requested URL as getServletPath() whereas the logic expects the full URL to be in getPathInfo(). This is further complicated by the fact that getServletPath() is only available in VaadinServletRequest, but not in the generic VaadinRequest interface.


@Legioth commented on Wed Jan 03 2018

One idea for fixing this might be to introduce an additional method into VaadinRequest that gets the request URL relative to the context root, i.e. servletPath+ pathInfo. Logic that is always assumed to be mapped to the context root, e.g. anything related to the VAADIN/ namespace would then use this new method instead of the currently used getPathInfo().


@Legioth commented on Tue Jan 09 2018

The same issue probably also applies to e.g. Upload handling.


@heruan commented on Tue Jan 09 2018

I confirm, same issue with Upload.

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 with StreamRequestHandler and compare how VaadinServletRequest exposes servletPath and pathInfo through the VaadinRequest interface. Check the Spring servlet mapping and the related Upload handling mentioned in the issue. Done means StreamResource downloads work in the Spring skeleton without triggering RouteNotFoundError, while existing non-Spring behavior remains intact.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.