3

I found this same question in here few times, but I couldn't find an answer to that.

When I run my application, Im getting the following error

javax.ws.rs.NotFoundException: Could not find resource for full path: http://localhost:8080/RemoteQuartzScheduler/rest/TestClass/hello
    at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73)
    at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
    at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)
    at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

Here is the pom file of the project (I only added the main parts)

<repositories>
    <repository>
        <id>JBoss repository</id>
        <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>3.0.9.Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-servlet-initializer</artifactId>
        <version>3.0.9.Final</version>
    </dependency>
</dependencies>

And here is my web.xml file

<web-app 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">


<display-name>RemoteQuartzScheduler</display-name>

<servlet-mapping>
    <servlet-name>resteasy-servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>


<!-- this should be the same URL pattern as the servlet-mapping property -->
<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
</listener>

<servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
</servlet>

Here is my Test.java class

@Path("/TestClass")
public class Test implements Serializable{

  private static final long serialVersionUID = -262701666015379272L;

  @GET
  @Path("/hello")
  public Response heloMessage() {

    String result = "Hello Word!!!!!!!!!";

    return Response.status(200).entity(result).build();
  }   
}

Please tell me where did I do wrong?? Thanks in advance

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Ravindu
  • 2,408
  • 8
  • 30
  • 46
  • Add the complete stacktrace please. – Jens Feb 16 '15 at 06:42
  • @Jens added the complete stack trace – Ravindu Feb 16 '15 at 06:44
  • Is `RemoteQuartzScheduler` the name of your `ear` file? – Jens Feb 16 '15 at 06:45
  • yes, its the name of my war file – Ravindu Feb 16 '15 at 06:47
  • and if I jut enter http://localhost:8080/RemoteQuartzScheduler/, it will show Hello World! . not Hello Word!!!!!!!!! which I used in my Test class – Ravindu Feb 16 '15 at 06:49
  • Without any version numbers? Any Excpetions in logfile at startup/ deployment? – Jens Feb 16 '15 at 06:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/70992/discussion-between-ravindu-and-jens). – Ravindu Feb 16 '15 at 06:49
  • Try and add the context param `resteasy.scan` to `true`. See [Configuration Switches](http://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html/Installation_Configuration.html#d4e125) – Paul Samsotha Feb 16 '15 at 06:56
  • @peeskillet still the same, I added resteasy.scan true – Ravindu Feb 16 '15 at 07:02
  • 2
    Try this. Comment out the whole web.xml, and create an `javax.ws.rs.core.Application` subclass in the project. Just leave it empty. Annotate it with `@ApplicationPath("/rest")`. This should for the most part work. Just trying to see if it is something else. – Paul Samsotha Feb 16 '15 at 07:05
  • @peeskillet then it gives a 404 error (The requested resource is not available.) – Ravindu Feb 16 '15 at 07:08
  • What Tomcat version are you using? – Paul Samsotha Feb 16 '15 at 07:11
  • oH.... I'M REALLY SORRY SIR, IT WORKS. Instead of a subclass I created a class named application – Ravindu Feb 16 '15 at 07:17
  • @peeskillet can u please explain what did u do there? now my web.xml file is completely empty. If u can, please give it as a answer so others also can see it. Thank you – Ravindu Feb 16 '15 at 07:18
  • I am facing same issue. I created another question http://stackoverflow.com/questions/41285602/jaxrs-could-not-find-resource-for-full-path – Prashant Thorat Dec 22 '16 at 14:40

1 Answers1

2

I haven't gotten a chance to test your version (with the web.xml), and honestly I don't work much with xml when I do use Resteasy, so I won't go trying to explain what is wrong (if anything) with the web.xml.

But when working with an javax.xs.rs.core.Application subclass, we can define an @ApplicationPath("/path") annotation. This defines a servlet for our JAX-RS application, with the url mapping of /path/*. This is specified in the JAX-RS spec.

You can see more here about this deployment option, as well as others, in section 2.3.2 Configuration - Servlet. This is a 1.1 spec (you are using 2.0), but the deployment options are similar. I just couldn't find an html link to the 2.0. You can download the pdf though from here.

You can also read more about deployments with Resteasy here in the documentation.

But basically, what this deployment option does is scan for annotations of @Path, @Provider, etc for the application. The reason is that JAX-RS will first look for classes and object in overridden getClasses() and getSingletons(), respectively. If then return empty sets, this tell JAX-RS to do scanning (per the spec).

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720