> -----Original Message----- > From: Sergey Beryozkin [mailto:[email protected]] > Sent: Wednesday, March 23, 2011 10:06 AM > To: [email protected] > Subject: Re: Avoiding stack trace for particular > WebApplicationExceptions & 500 instead of 403 > > Hi > > On Wed, Mar 23, 2011 at 4:08 PM, KARR, DAVID (ATTSI) <[email protected]> > wrote: > > > I have a condition I need to check for in my CXF REST service that > may > > result in having to throw back an error with status 403 (forbidden). > I'd > > like to log this occurred, but I don't need to have a stack trace > appear in > > my log. > > > > > > I had tried to make this happen, but it's still putting the > > WebApplicationException stack trace into my log. > > > > Another possibly related problem is that the client isn't getting a > 403, > > it's getting a 500. > > > > In my controller handler, when I detect the condition, I do this: > > > > throw new WebApplicationException(Response.Status.FORBIDDEN) > > > > I've defined the following: > > --------------- > > public class WebApplicationExceptionMapper implements > > ExceptionMapper<WebApplicationException> { > > private static Logger logger = > > Logger.getLogger(WebApplicationExceptionMapper.class); > > > > @Override > > public Response toResponse(WebApplicationException ex) { > > if (ex.getResponse().getStatus() == > > Response.Status.FORBIDDEN.getStatusCode()) > > logger.error("Request failed with FORBIDDEN status > code."); > > else > > logger.error(ex); > > return null; > > } > > } > > --------------- > > > > > In the custom exception mapper you need to return Response, probably: > > return ex.getResponse(); > > With CXF filters returning a non-null Response means the request was > blocked > or overridden (in case of out filters), but with exception mappers > Response > should be returned. > > Cheers, Sergey
That did it, thanks.
