users@jersey.java.net

javax.ws.rs.ext.ExceptionMapper<T>

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 09 Jun 2008 15:47:23 +0200

Hi,

I have just implemented support for javax.ws.rs.ext.ExceptionMapper<T>.

Now it is possible to map a runtime or checked exception thrown by the
application to a response.

For example, say the application has a checked or runtime exception
called ExceptionalException then one can write a provider as follows:

   @Provider
   public class ExceptionalExceptionMapper
       implements ExceptionMapper<ExceptionalException> {

     public Response toResponse(ExceptionalException e) {
        // build response
        Response r = ...
        return r;
     }
   }

One can also override that of WebApplicationException:

   @Provider
   public class WebAppExceptionMapper
       implements ExceptionMapper<WebApplicationException> {

     public Response toResponse(WebApplicationException e) {
        // build response
        Response r = ...
        return r;
     }
   }

provided that the WebApplicationException thrown does not have an entity
in its response. Such exceptions thrown by Jersey will never have an
entity, thus it is possible to override 4xx stuff thrown by Jersey.

Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109