users@jersey.java.net

[Jersey] Custom handlers

From: Jose Antonio Illescas Del Olmo <jantonio.illescas_at_rbcdexia-is.es>
Date: Thu, 04 Aug 2011 12:28:33 +0200

Can I define custom handlers?


example:

     public class MyInvocationHandler {

         public Response process(Annotation[] annotations, MediaType
mediaType, InvocationContex context) {

                 // put your pre-process here: logs, security,
transactions...

                 context.invoke(); // this method calls to my found
REST service method

                 // put your post-process here: redirect/forwards,
Reponse modifications...
         }

and defining my hadler on my REST service (or use a META-INF/services
file to configure)

   @Path("hello")
   public class HelloWorld {

     @GET
     @Produces("text/xml")
     @Handle(MyInvocationHandler)
     public String sayHello() {
         return "<message>Hello world</message>";
     }