0

I'm trying to develop a RESTful webapp using the Servlet 3.0 Application class on Tomcat 7.0.34.0, but nothing seems to work. I've had no problem with previous apps using the Jersey ServletContainer approach and declaring all REST services in the web.xml.

My current Application sub-class:

package aaa;

@ApplicationPath("/test")
public class ApplicationConfig extends Application
{
    @Override
    public Set<Class<?>> getClasses ()
    {
        Set<Class<?>> resources = new java.util.HashSet<Class<?>> ();
        resources.add (aaa.TestResource.class);
        return resources;
    }
}

and the web service:

package aaa;

@Path("test")
public class TestResource
{
    public TestResource () {}

    @GET
    @Produces("text/html")
    public String getXml ()
    {
        return "TEST SUCCESS";
    }
}

When I try to deploy the app, Tomcat tells me the context has been reloaded:

INFO: Reloading Context with name [/WebApplication1] has started
Nov 10, 2013 7:06:25 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/WebApplication1] is completed

The web app itself is deployed (I can access its JSP pages) - however, the "test" resource remains unavailable. I've tried every possible URL and get only 404 in response. It seems ApplicationConfig is never even loaded.

A point of interest: following the suggestions in this question, I've tried adding a small web.xml with no and removing the @ApplicationPath. The result is a NullPointerException, which is exactly the behaviour I would expect in a Servlet 2.x environment (no class specified, so the ClassLoader crashes).

I'm at a loss here. Any suggestion on what I'm doing wrong ?

PS: I'm using NetBeans 7.3.1, project is [Java Web -> Web Application -> Java EE 6 Web] with no extra library and no context/dependency injection.

Community
  • 1
  • 1
  • I don't see a subclass. Show us the code of `SimpletestResource`. –  Nov 12 '13 at 09:26
  • @LutzHorn My apologies - I actually renamed SimpletestResource to TestResource in the middle of posting the question, and forgot to correct the code I posted. ApplicationConfig does in fact add TestResource properly - editing the question now to reflect it. – Francois M Nov 15 '13 at 15:37

1 Answers1

1

Your test resource is defined in TestResource class, while the overriden getClasses method returns a set with only SimpletestResource.class. Although I don't know how does SimpletestResource look like, but AFAIK @Path is not inherited. So, I think you should put TestResource.class in that set.

Tried and tested on Tomcat 7.0.27 with NetBeans 7.4. Added the libraries: JAX-RS 2.0 and Jersey 2.0.

Csaba
  • 965
  • 9
  • 20
  • That's a mistake on my part: the code actually adds `TestResource` in `ApplicationConfig`. I've updated the question. Sorry for that. – Francois M Nov 15 '13 at 16:43