users@jersey.java.net

[Jersey] Re: Capturing service exceptions

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Tue, 5 Nov 2013 19:02:18 +0100

On 05 Nov 2013, at 18:58, 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?

JAX-RS ExceptionMappers:
https://jersey.java.net/documentation/latest/representations.html#d0e3586

Marek

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