1

I'm doing a Rest Service + Web Site with Wildfly and JAX-RS. My point is to make the Rest Service as some kind of "Controller". I can normally load my index.jsp page, but when it comes to other kind of files (like main.css) it returns 404 HTTP file not found error.

Are those files supposed to be in the same project? Or should I create one Java project for the Rest Service and another for the web site?

My Endpoint looks like this:

@Path("/restservice")
@Produces("text/html; charset=UTF-8")
public class FalkEndpoint {

    @GET
    public String defaultMessage(@Context HttpServletRequest request,@Context HttpServletResponse response){
        return "The server is up! :)";
    }


}

My web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <servlet-mapping>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>
Swadish
  • 100
  • 10
  • Please show the folder structure of your project. That will help identify the problem. – Alain O'Dea Nov 08 '15 at 21:04
  • [See related](http://stackoverflow.com/q/30111978/2587435). It has to do with using the url pattern `/*`. It hogs the request not allowing the static content to be retrieved. Either change the url pattern or check out the configuration in the answer – Paul Samsotha Nov 09 '15 at 00:28

1 Answers1

0

You should not normally serve static files with JAX-RS. That is reinventing the wheel. Serving dynamically generated files (like report PDFs or CSV exports) is totally fine.

Those (static resource) files are most easily handled if they are in the same project.

If you put them in the web or src/webapp folder (depending on your project setup) along side your JSPs they will be served by the container (Tomcat/Jetty/Glassfish) servlets for you.

In Wildfly this is achievable with standalone.xml by adding file handlers:

Add another file handler and another location to the undertow subsystem in standalone.xml:

<server name="default-server">
    <http-listener name="default" socket-binding="http"/>
    <host name="default-host" alias="localhost">
        <location name="/" handler="welcome-content"/>
        <location name="/img" handler="images"/>
    </host>
</server>
<handlers>
    <file name="welcome-content" path="${jboss.home.dir}/welcome-content" directory-listing="true"/>
    <file name="images" path="/var/images" directory-listing="true"/>
</handlers>

Source: https://stackoverflow.com/a/22695843

Community
  • 1
  • 1
Alain O'Dea
  • 21,033
  • 1
  • 58
  • 84