Hosting Static Content and JAX-RS Services Under the Same Root Context

后端 未结 2 952
情歌与酒
情歌与酒 2021-01-05 20:54

We have multiple Java web apps packaged as WARs all packaged in an EAR. Our RESTful services are built using JAX-RS and in version specific WARs.

We\'d like to add

相关标签:
2条回答
  • 2021-01-05 21:19

    So I found a solution (tested) that works. As stated in the Resteasy Documentation - RESTEasy as a servlet Filter:

    The downside of running Resteasy as a Servlet is that you cannot have static resources like .html and .jpeg files in the same path as your JAX-RS services. Resteasy allows you to run as a Filter instead. If a JAX-RS resource is not found under the URL requested, Resteasy will delegate back to the base servlet container to resolve URLs.

    web.xml example

    <web-app>
        <filter>
            <filter-name>Resteasy</filter-name>
            <filter-class>
                org.jboss.resteasy.plugins.server.servlet.FilterDispatcher
            </filter-class>
            <init-param>
                <param-name>javax.ws.rs.Application</param-name>
                <param-value>com.restfully.shop.services.ShoppingApplication</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>Resteasy</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    </web-app>
    
    0 讨论(0)
  • 2021-01-05 21:39

    I found another solution (thanks to https://stackoverflow.com/a/3582215/589525 ). This works for RestEasy on JBoss 6. Simply add the default servlet to the mapping

    <!--existing mapping: -->
    <servlet-mapping>
      <servlet-name>Resteasy</servlet-name>
      <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
      <servlet-name>default</servlet-name>
      <url-pattern>*</url-pattern>
    </servlet-mapping>
    
    0 讨论(0)
提交回复
热议问题