Search code examples
javaxmljbosswildflywildfly-10

WildFly Could not find resource for full path (No XML, using CLI Deployment)


I've been reading threads on SO about this for a while, but I can't figure out whether this is a WildFly deployment issue or a RESTEasy issue. Any help would be appreciated.

When I try to access: http://localhost:8080/HelloWorld-1.0-SNAPSHOT/json/hi

Error message:

12:27:04,159 ERROR [org.jboss.resteasy.resteasy_jaxrs.i18n] (default task-1) RESTEASY002010: Failed to execute: javax.ws.rs.NotFoundException: RESTEASY003210: Could not find resource for full path: http://localhost:8080/HelloWorld-1.0-SNAPSHOT/json/hi

JAXActivator.java:

package com.sentiment360.helloworld;
    
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
    
@ApplicationPath("/")
public class JAXActivator extends Application { }

web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0">
    
    <display-name>hello</display-name>
</web-app>

index.html:

<!DOCTYPE html>
    <html>
        <head>
            <title>Start Page</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        </head>

        <body>
            <h1>Hello World WOO!</h1>
        </body>
    </html>

HelloWorld.java:

package com.sentiment360.helloworld;
    
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
    
public class HelloWorld {
    //@Inject
    //HelloService helloService;
    
    @GET
    @Path("/json/{p}")
    @Produces({ "application/json" })
    public String getHelloWorldJSON(@PathParam("p") String param) {
        return "{\"result\":\"" + param + "\"}";
        //return "{\"result\":\"" + helloService.createHelloMessage(param) + "\"}";
    }
    
    @GET
    @Path("/xml/{p}")
    @Produces({ "application/xml" })
    public String getHelloWorldXML(@PathParam("p") String param) {
        return "<xml><result>" +param+ "</result></xml>";
        //return "<xml><result>" + helloService.createHelloMessage(param) + "</result></xml>";
    }
}

My directory structure: pic to show my directory directory structure

WildFly server commands:

Terminal 1:

/etc/opt/wildfly-10.0.0.Final/bin/standalone.sh

Terminal 2:

/etc/opt/wildfly-10.0.0.Final/bin/jboss-cli.sh --connect --command="deploy --force /home/king/NetBeansProjects/HelloWorld/target/HelloWorld-1.0-SNAPSHOT.war"


Solution

  • It isn't obvious but I've never been able to have static content on the same path at JAX-RS content. Change your JAXActivator.java file to have a path like /rest or whatever you'd like. Ultimately when a request comes in Wildfly needs to determine how to route it. As you have it now your services start at / but so does the static content. Partition your URL space between services and static and you won't run into this issue.

    EDIT:

    Weird - I copied you code directly and am running under Ubuntu also. I've got a totally fresh Wildfly 10.1.0.Final. If I use your code as is I too get a 404. But if I put a @Path annotation on the class:

    package com.sentiment360.helloworld;
    
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    
    @Path("/hello")
    public class HelloWorld {
    
        @GET
        @Path("/json/{p}")
        @Produces({"application/json"})
        public String getHelloWorldJSON(@PathParam("p") String param) {
            return "{\"result\":\"" + param + "\"}";
        }
    
        @GET
        @Path("/xml/{p}")
        @Produces({"application/xml"})
        public String getHelloWorldXML(@PathParam("p") String param) {
            return "<xml><result>" + param + "</result></xml>";
        }
    }
    

    and include that path in the URL it works fine. I'll admit I always have that extra class level Path on my services to help scope them but I didn't think it was required. I'll have to learn some more.

    EDIT 2:

    Well, I learned something - the "root resource" declaration (a.k.a. the @Path at the class level) is required. This is why my IDE was telling me that the class was unused when I didn't have it. I've always done it this way but never know that it was required. Between the @ApplicationPath and the @Path at the class level it was all working as expected.