Description of the bug
As a developer, I want to use StreamResource API with a Button component to download a resource file in a portlet application.
But in a portlet world, the dynamic resources url should be embedded into portlet parameters part.
For instance, regular servlet dynamic resource url:
http://localhost:8080/VAADIN/dynamic/resource/0/82c11682-792d-4d74-b323-aeb26fe3ce6a/pom.xml,
should be embedded as:
http://localhost:8080/en/web/guest/home?p_p_id=my_portlet_id&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=%2FVAADIN%2Fdynamic%2Fresource%2F0%2F82c11682-792d-4d74-b323-aeb26fe3ce6a%2Fpom.xml&p_p_cacheability=cacheLevelPage.
File file = new File("/path/to/file");
InputStream inputStream = new FileInputStream(file);
StreamResource streamResource = new StreamResource(fileName, () -> inputStream );
final StreamRegistration registration = VaadinPortletSession.getCurrent().getResourceRegistry().registerResource(streamResource );
UI.getCurrent().getPage().open(registration.getResourceUri().toString());
Expected and actual behavior
Expected: file is downloaded in browser, actual: The requested resource could not be found. http://localhost:8080/en/web/guest/VAADIN/dynamic/resource/0/deced29f-e427-45be-b587-4520a6c0fdcc/pom.xml is shown (http code 404).
Versions:
Vaadin Portlet version: snapshot from feature/liferay branch
StreamResource
API with aButton
component to download a resource file in a portlet application. But in a portlet world, the dynamic resources url should be embedded into portlet parameters part. For instance, regular servlet dynamic resource url:http://localhost:8080/VAADIN/dynamic/resource/0/82c11682-792d-4d74-b323-aeb26fe3ce6a/pom.xml
, should be embedded as:http://localhost:8080/en/web/guest/home?p_p_id=my_portlet_id&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=%2FVAADIN%2Fdynamic%2Fresource%2F0%2F82c11682-792d-4d74-b323-aeb26fe3ce6a%2Fpom.xml&p_p_cacheability=cacheLevelPage
.Proposition: create a custom implementation of
StreamResource
for portlets, which would return correct "wrapped" resource url, like it's already done here https://github.com/vaadin/portlet/blob/b545000cbf32c50131fb663f901caa2d1c438d6d/vaadin-portlet/src/main/java/com/vaadin/flow/portal/PortletStreamResourceRegistry.java#L51.The requested resource could not be found. http://localhost:8080/en/web/guest/VAADIN/dynamic/resource/0/deced29f-e427-45be-b587-4520a6c0fdcc/pom.xml
is shown (http code 404).