users@jersey.java.net

[Jersey] Capturing service exceptions

From: phil swenson <phil.swenson_at_gmail.com>
Date: Tue, 5 Nov 2013 10:58:51 -0700

When I hit a jersey service and there is an exception in the service
implementation, the error isn't logged anywhere unless I put in log
handling around each method call like:

@GET @Path("/xml/{modelid}")
@Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML})
    public String processModelXml(@PathParam("modelid") String modelId) {
        try{
            modelId = "Order Fulfillment";

            String processModelXML =
glueProcessModelService.getProcessModelXML(modelId, 1);
        return processModelXML;
    }catch(Exception e){
        Logger.log(e);
        throw e;
    }

It seems to me this isn't very DRY. Anyone know a better solution? Does
jersey have a facility to intercep all service exceptions?

Has anyone implemented an annotation type approach to handle this?
would be cool if I could put @HandleException on all methods which calls a
HandleException implementation...

thanks for any thoughts!
phil