-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Inconsistent behaviour of ServletContext.getResources() #17233
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
Comments
Thanks for sharing your detailed findings. I've yet to digest everything, but the first thing I've noticed is that this is a partial duplicate of #8324. That |
Thanks for sharing the links. This makes some things clearer to me. For war files it might be unnecessary to expose Some additional thoughts about this:
|
This is what was considered in #8324 and we decided not to do it. I don't think we're going to change that decision I'm afraid.
In keeping with the servlet spec loading resources from
Agreed. We thought that things were consistent and we have tests the are intended to cover this so it would appear that we're missing something. We can use this issue to investigate and straighten things out. |
The expectations for a war file are incorrect. The servlet contains requires static resources to be served from the root of the war file or from |
I agree that the servlet specification doesn't require |
There's a bug in how we set up Undertow's |
After this is resolved, a few sentences should be added to the documentation about which locations are used as servlet context resources (and which locations are not used) and how this can be changed if necessary. Some other thoughts I had in the meantime:
I'd rather modify the underlying servlet container to include a custom location as resource root than creating a separate module. |
I've updated the tables above in order to include docker containers built with jib as third packaging option. |
There seems to be an additional inconsistency for repackaged wars running using When using an embedded Tomcat, |
To follow the principle of least surprise, I think it's important that we align with the Servlet spec. While it doesn't prohibit additional locations, I think would be surprising for additional locations to be used by default.
We have decided that it can and should be applied, with some translations to Spring Boot's layout. Where the spec talks about
The is no root of the context in a jar-based application. If we followed the war model, we'd have the same problem with accidentally serving content from the root of the jar.
It's almost entirely applicable, with
Thanks. Our main concern with hiding the loader is preventing it from being served over HTTP which we currently do. That said, we'll see if it's possible to hide it from |
Does that mean my initial expectation to see
I see, that the servlet spec, in fact, could be applied to spring-boot-repackaged jar files.
I think for most of these ways of running the application it would be difficult, error-prone or even improssible to distinguish between |
I think we've done all that we can here for the time being at least. The Undertow issue I opened remains open. If it's fixed we can revisit that part of things in the future. |
Uh oh!
There was an error while loading. Please reload this page.
The behavior of
javax.servlet.ServletContext#getResourcePaths
and (its sibling methods) is inconstent, depending on how the application is packaged and which servlet container is used.I've created the following example application to demonstrate the problem: https://github.com/larsgrefer/servlet-context-test
All example applications in this repository return a list of all found resources under localhost:8080/resources
Jar based applications
Expected behaviour
All applications should always return the following items (in any order)
Actual behaviour:
gradle bootRun
java -jar
/classpath-resource.txt
is missing/classpath-resource.txt
is missingWar based applications
Expected behaviour
All applications should always return the following items (in any order)
Actual behaviour:
gradle bootRun
java -jar
/classpath-resource.txt
is shown in addition to the expected ones/war-resource.txt
is shown/classpath-resource.txt
is shown in addition to the expected ones(**) jib uses a distroless jetty for war based project, so this is a traditional deployment to an external servlet container from the spring-boot point of view
Conclusion
src/main/webapp
seems to be used as resource root, even if the project is not war-based.classpath*:META-INF/resources
is only used as resource root by Tomcat and Jetty, but not by undertow.classpath*:META-INF/resources
is not used as resource root when its theBOOT-INF/classes
orWEB-INF/classes
folder of a repacked jar or war.The text was updated successfully, but these errors were encountered: