users@jersey.java.net

[Jersey] Re: Capturing service exceptions

From: Bill O'Neil <oneil5045_at_gmail.com>
Date: Tue, 5 Nov 2013 13:01:00 -0500

Take a look at ExceptionMappers. You can implement your own and handle all
logging there.


On Tue, Nov 5, 2013 at 12:58 PM, phil swenson <phil.swenson_at_gmail.com>wrote:

> 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
>
>