Skip to content

Resource handling is inconsistent across different embedded containers #8299

Closed

Description

@wilkinsona

The behaviour of embedded Tomcat, Jetty, and Undertow is inconsistent when the containers themselves are dealing with static resources, i.e. when Spring MVC's resource handling isn't involved. For example, support for loading resources from META-INF/resources of nested jars works with Tomcat but doesn't work with Undertow. Furthermore, I believe it only works with Tomcat when Jasper's on the classpath.

Activity

  1. self-assigned this
    on Feb 15, 2017
  2. wilkinsona commented on Feb 16, 2017

    @wilkinsona
    MemberAuthor

    Expectations

    Fat war

    For war files, we're interested in resources in these three locations:

    app.war
    ├── META-INF
    │   └── resources
    │       └── meta-inf-resource.txt
    ├── WEB-INF
    │   └── lib
    │       └── resources.jar
    │           └── META-INF
    │               └── resources
    │                   └── nested-meta-inf-resource.txt
    └── resource.txt
    

    Accessing resources via HTTP and via the servlet context (SC) should have the following results:

    Path Method Result
    /nested-meta-inf-resources.txt HTTP 200
    /nested-meta-inf-resources.txt SC URL
    /meta-inf-resources.txt HTTP 404
    /meta-inf-resources.txt SC Null
    /resource.txt HTTP 200
    /resource.txt SC URL

    Fat jar

    For jar files, we're interested in resources in these locations:

    app.jar
    ├── BOOT-INF
    │   └── lib
    │       └── resources.jar
    │           └── META-INF
    │               └── resources
    │                   └── nested-meta-inf-resource.txt
    ├── META-INF
    │   └── resources
    │       └── meta-inf-resource.txt
    └── resource.txt
    

    Accessing resources via HTTP and via the servlet context should have the following results:

    Path Method Result
    /nested-meta-inf-resources.txt HTTP 200
    /nested-meta-inf-resources.txt SC URL
    /meta-inf-resources.txt HTTP 404
    /meta-inf-resources.txt SC Null
    /resource.txt HTTP 404
    /resource.txt SC 404

    Actual behaviour

    Fat war

    Path Method Jetty Tomcat Undertow
    /nested-meta-inf-resources.txt HTTP ❌ ❌/✅ (1) ❌
    /nested-meta-inf-resources.txt SC ❌ ❌/✅ (1) ❌
    /meta-inf-resources.txt HTTP ✅ ✅ ✅
    /meta-inf-resources.txt SC ✅ ✅ ✅
    /resource.txt HTTP ✅ ✅ ✅
    /resource.txt SC ✅ ✅ ✅

    (1) - Tomcat only works when Jasper in on the classpath

    Fat jar

    Path Method Jetty Tomcat Undertow
    /nested-meta-inf-resources.txt HTTP ❌ ❌/✅ (1) ❌
    /nested-meta-inf-resources.txt SC ❌ ❌/✅ (1) ❌
    /meta-inf-resources.txt HTTP ✅ ✅ ✅
    /meta-inf-resources.txt SC ✅ ✅ ✅
    /resource.txt HTTP ✅ ✅ ✅
    /resource.txt SC ✅ ✅ ✅

    (1) - Tomcat only works when Jasper in on the classpath

  3. added this to the 1.4.5 milestone on Feb 17, 2017
  4. wilkinsona commented on Feb 18, 2017

    @wilkinsona
    MemberAuthor

    We should consider configuring the containers such that they can serve resources from BOOT-INF/classes/META-INF/resources. This would allow a jar-packaged project to place static resources in src/main/resources/META-INF/resources rather than having to move them out into a separate project that's depended upon (see #8324). A war file doesn't have this problem as war projects can place resources directly in src/main/webapp from where they'll end up in the root of the war.

  5. added a commit that references this issue on Mar 1, 2017
    b443b74
  6. bjorntj commented on Mar 28, 2017

    @bjorntj

    Just wondering, where should I put static resources when using embedded Undertow? I have created a jar file that contains these resources and this is working fine when unsing tomcat or jetty, but undertow does not find the resources.
    Or is a fix for this issue imminent?

  7. wilkinsona commented on Mar 28, 2017

    @wilkinsona
    MemberAuthor

    As long as you're using the latest version of 1.4.x and 1.5.x, it should work the same way in all three embedded containers. If you've found a situation where that's not the case, please open a new issue with a small sample that reproduces the problem.

  8. bjorntj commented on Mar 28, 2017

    @bjorntj

    I am using 1.5.2 and tomcat and jetty is working fine, but not undertow. All I do to switch, is change this dependency: compile("org.springframework.boot:spring-boot-starter-jetty") to either starter.tomcat or starter.undertow..
    I am also using JSF, not sure if that makes a difference...

  9. bjorntj commented on Mar 28, 2017

    @bjorntj

    Seems like this is related to JSF, more specific Primefaces and their themes.
    Under /META-INF/resources/ there is another directory called resources and beneath this, there is a directory called theme-name, and beneath this again is the folders needed for this theme (css, images, etc).
    The error I get when running under Undertow, is:
    JSF1064: Unable to find or serve resource, css/layout.css, from library, theme-name

    Does this help or do you still need me to open a new issue with a sample case?

  10. wilkinsona commented on Mar 28, 2017

    @wilkinsona
    MemberAuthor

    If you'd like us to investigate, we'll need a new issue with a sample case please.

  11. pleku commented on Dec 3, 2018

    @pleku
  12. wilkinsona commented on Dec 3, 2018

    @wilkinsona
    Author
  13. pleku commented on Dec 3, 2018

    @pleku

    Will do, sorry and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions