jax-rs nested provider with Jersey+Jetty

12 Views Asked by At

I'm recently began to learn JAX-RS and got a code example which is doesn't work but I can't understand if its because I missing some configuration or this code doesn't suppose to work. Actually the question is around two classes:

@Provider
@Path("/")
public class RootController{
        
    @GET
    @Path("/services/{service}")
    public Service getService(@PathParam("service") String serviceId) {
        ...// returns instance of Service
    }
}

@Provider
public class Service{
   @GET
   @Path("time")
   @Produces("text/plain")
   public String getTime(@PathParam("timezone") String timeZone) {
        ...// returns string representation of now time in given timezone
   }
}

The problem is when I put my browser to http://localhost:port/services/MY_SERVICE/time or http://localhost:port/services/MY_SERVICE then I receive an error page as below:

HTTP ERROR 404 Not Found
URI:    /services/MY_SERVICE/time
STATUS: 404
MESSAGE:    Not Found
SERVLET:    org.glassfish.jersey.servlet.ServletContainer-5f683daf
Powered by Jetty:// 10.0.13

If I add @Produces(MediaType.APPLICATION_JSON) for RootController#getService then http://localhost:port/services/MY_SERVICE gives me a JSON representation of my Service class instance, but if understood correctly its not that should be for this example but the Service resource should be supplied and on it should then be invoked path time . So the question is it possible for such configuration and if yes then what I missing to make it work?

0

There are 0 best solutions below