cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "KARR, DAVID (ATTSI)" <dk0...@att.com>
Subject RE: Avoiding stack trace for particular WebApplicationExceptions & 500 instead of 403
Date Wed, 23 Mar 2011 18:50:53 GMT

> -----Original Message-----
> From: Sergey Beryozkin [mailto:sberyozkin@gmail.com]
> Sent: Wednesday, March 23, 2011 10:06 AM
> To: users@cxf.apache.org
> 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) <dk068x@att.com>
> 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.

Mime
View raw message