0
votes

What do I need to make this minimalist REST Example work ?

Projet Name : hello-rest

App Code :

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("resources")
public class MyJAXWSApp extends Application {
}

MessageResource :

import javax.ws.rs.GET;
import javax.ws.rs.Path;

    @Path("message")
    public class MessageResource {
    @GET
    public String Hello() {
        return "hello!";
    }
}

MAVEN config :

<dependency>
   <groupId>javax</groupId>
   <artifactId>javaee-api</artifactId>
   <version>7.0</version>
   <scope>provided</scope>
</dependency>

Problem :
So far, Deployment via Eclipse Neon in WildFly 10x results in 404 error when I call Service URI :

http://localhost:8080/hello-rest/resources/message

Source : Adam Bien

PS : Server Deployment OK :

22:20:04,486 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080 ...

22:20:04,582 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "hello-rest-0.0.1-SNAPSHOT.war" (runtime-name: "hello-rest-0.0.1-SNAPSHOT.war") ...

22:20:04,974 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443 ....

22:20:06,992 INFO [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 59) RESTEASY002225: Deploying javax.ws.rs.core.Application: class JAXRSConfiguration ...

22:20:07,074 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 59) WFLYUT0021: Registered web context: /hello-rest-0.0.1-SNAPSHOT

22:20:07,135 INFO [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "hello-rest-0.0.1-SNAPSHOT.war" (runtime-name : "hello-rest-0.0.1-SNAPSHOT.war")

2

2 Answers

3
votes

One thing I see in your server output is it registered the path as "/hello-rest-0.0.1-SNAPSHOT". So until you change your Maven config to not append the version to your war you'll have to add "-0.0.1-SNAPSHOT" to your URL when calling the service.
i.e. http://localhost:8080/hello-rest-0.0.1-SNAPSHOT/resources/message

I've also always seen the ApplicationPath and Path annotations on resources (not methods) as starting with '/'. I'm not sure if it's required or not but I'd recommend it as a best practice regardless.

UPDATE: Looked it up here and as of JAX-RS 2 the trailing and leading slashes should not be required.

-1
votes

Do you have this in your MyJAXWSApp ?

private void addRestResourceClasses(Set<Class<?>> resources) {
    resources.add(your.package.name.MessageResource.class);
}

Note: Make sure the package is correct. I've just put your.package.name as an example, but you'll need to provide the fully qualified class name.