Skip to content

In a reactive web app, SslBundle can no longer open store file locations without using a 'file:' prefix #44535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

nosan
Copy link
Contributor

@nosan nosan commented Mar 5, 2025

See #43953

…tResource

Prior to this update, FilteredReactiveWebContextResource was not
considered when preferFileResolution was set to true.

This commit updates the ApplicationResourceLoader to include support for
FilteredReactiveWebContextResource.

Signed-off-by: Dmytro Nosan <[email protected]>
@@ -132,8 +132,8 @@ public static ResourceLoader get(ResourceLoader resourceLoader) {
* class loader at the time this call is made.
* @param resourceLoader the delegate resource loader
* @param preferFileResolution if file based resolution is preferred over
* {@code ServletContextResource} or {@link ClassPathResource} when no resource prefix
* is provided.
* {@code ServletContextResource}, {@code FilteredReactiveWebContextResource} or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look to this and, unfortunately, I don't think that we can use that option as I realize now that it's an implementation detail (package private on top of it). This seems a bit fragile that we rely on this, compared to the standard ServletContextResource. I am still digging what our options are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resource implementation that replaces the {@link org.springframework.web.context.support.ServletContextResource} in a reactive web application.

org.springframework.boot.web.reactive.context.FilteredReactiveWebContextResource is a
part of Spring Boot codebase, so its ServletContextResource but for Reactive.

This seems a bit fragile that we rely on this, compared to the standard ServletContextResource. I am still digging what our options are.

You're right. Unfortunately, it is. With the introduction of ResourceLoader delegation in #42835, followed by the regression fix in #43274, the ApplicationResourceLoader has become a bit complex and fragile overall.

@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Mar 7, 2025
@philwebb philwebb added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Apr 23, 2025
@philwebb philwebb self-assigned this Apr 23, 2025
@philwebb philwebb added this to the 3.4.5 milestone Apr 23, 2025
philwebb pushed a commit that referenced this pull request Apr 23, 2025
Update `ApplicationResourceLoader` so that the `preferFileResolution`
flag now also supports `FilteredReactiveWebContextResource`.

See gh-44535

Signed-off-by: Dmytro Nosan <[email protected]>
philwebb added a commit that referenced this pull request Apr 23, 2025
Refactor `ApplicationResourceLoader` so that `preferFileResolution`
is supported using a new `ResourceFilePathResolver` strategy interface.

This update allows us to locate `ResourceFilePathResolver`
implementations in more suitable packages that are closer to the
code that they support.

See gh-44535
@philwebb philwebb closed this in 76f6e30 Apr 23, 2025
@philwebb
Copy link
Member

Thanks @nosan! Since ApplicationResourceLoader is getting a little hairy I've refactored it to lean on a new ResourceFilePathResolver strategy. This has allowed code to be moved about a bit and locate classes in better packages.

@nosan
Copy link
Contributor Author

nosan commented Apr 23, 2025

Thanks @philwebb

I really like the idea of adding a dedicated FilePathResolver!

What do you think about changing the return type to File or Path instead of String, since the primary purpose of the FilePathResolver is to resolve the provided location as File?

@nosan
Copy link
Contributor Author

nosan commented Apr 23, 2025

I also feel that ResourceFilePathResolver is a bit too generic, and ApplicationResourceFilePathResolver might be a more suitable name. It helps emphasise that this strategy interface is specifically designed for use with ApplicationResourceLoader. What do you think?

@philwebb
Copy link
Member

@nosan Thanks for the suggestions. How do you feel about commit 3531071? I tried changing the return type as well but it made all the implementations a little more awkward since they all needed to implement this logic.

@nosan
Copy link
Contributor Author

nosan commented Apr 23, 2025

Thanks @philwebb!

How do you feel about commit 3531071?

I think the nested interface is a great idea. I really like it.

I tried changing the return type as well but it made all the implementations a little more awkward since they all needed to implement this logic.

Oh, I completely overlooked cleanPath. In that case, it is probably better to leave things as they are.


One potential option could be to change the return type to either FileSystemResource or possibly ApplicationResource.

public interface ApplicationResourceResolver {

	ApplicationResource resolve(String location, Resource resource);

}

However, in such a case, ApplicationResource would also need to be made public and I can't say that is worthwhile.

@philwebb
Copy link
Member

philwebb commented Apr 23, 2025

I went though a similar thought process, but I agree that an extra public class is not ideal. I also considered returning a FileSystemResource, but then we'd be throwing it away or wrapping it to create the ApplicationResource.

Given that this stuff is somewhat internal, I think what we have is probably the least bad option.

Thanks for the extra review!

@philwebb philwebb closed this Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants