404 when loading icons

How are you doing?

When I open my app in a browser everything is fine.

But when I open another tab in another browser certain icons do not load.

The path is: META-INF/resources/frontend/images/svg-icons/bell.svg

the configuration of spring security for example is

    http.authorizeHttpRequests(
            authorize -> authorize.requestMatchers(new AntPathRequestMatcher(“/frontend/images/svg-icons/*.svg”))
                    .permitAll());

Already in the second tab of the other browser I end up getting a 404 when GETting the endpoint of the dynamic resource

    private static StreamResource setCustomImage() {
        return new StreamResource("usb-port-black",
                () -> SvgFactory.class.getResourceAsStream(FRONTEND_IMAGES_SVG_ICONS + "usb-port-black.svg"));

    }

I would not recommend to load static files in a SteamResource.
See Loading Resources and use

new Image(FRONTEND_IMAGES_SVG_ICONS + "usb-port-black.svg", "usb-port-black");
// or
avatar.setImage(FRONTEND_IMAGES_SVG_ICONS + "usb-port-black.svg");
1 Like

Further as you can see in the dev console, when a StreamResource the created, the url is handled by Vaadin and the path is /VAADIN/dynamic/resource. You then do not need a separate request matcher, that is already handled by Vaadin too.

In this specific case I am updating a MessageListItem then:

super.setUserImage(“frontend/images/svg-icons/” + EXECUTABLE_ICON); works as expected.

1 Like