mercredi 5 août 2015

How to use Jersey's internal routing mechanism to extract a class/method reference?


I have a Jersey 1.8 application running. Jersey is running as a Servlet.

I need to write a servlet filter that given a plain request/response, is able to figure out which REST resource/method will respond to the request and extract values from annotations.

For example, imagine I have the following resource:

@Path("/foo")
@MyAnnotation("hello")
public class FooResource {
   @GET
   @Path("/bar")
   @MyOtherAnnotation("world")
   public Response bar(){ 
      ... 
   }
}

When a request GET /foo/bar comes in, I need my servlet filter to be able to extract the values "hello" and "world" from MyAnnotation and MyOtherAnnotation before Jersey's own servlet processes the request.

This filter logic should be able to work for all requests and all resources registered.

Is there a way to access Jersey's internal routing mechanism to obtain a class/method reference where Jersey will dispatch the request?

I'm open to other suggestions as well, but ideally nothing like trying to hack my own routing mechanism by reading the @Path annotations myself.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire