cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Avoiding stack trace for particular WebApplicationExceptions & 500 instead of 403
Date Wed, 23 Mar 2011 16:08:49 GMT
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);

    public Response toResponse(WebApplicationException ex) {
        if (ex.getResponse().getStatus() == Response.Status.FORBIDDEN.getStatusCode())
            logger.error("Request failed with FORBIDDEN status code.");
        return null;

In my debugger, I saw it throw the exception and the first if block, but in my console it
shows the following (slightly elided) exception:

<Mar 23, 2011 8:57:45 AM PDT> <Error> <HTTP> <BEA-101020> <[ServletContext@8348067[app:shop
module:/apiservice path:/apiservice spec-version:2.5]] Servlet failed with Exception
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault
        at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(
        at org.apache.cxf.transport.servlet.ServletDestination.invoke(
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(
        Truncated. see log file for complete stacktrace

Caused By: org.apache.cxf.interceptor.Fault
        at org.apache.cxf.service.invoker.AbstractInvoker.createFault(
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$
        Truncated. see log file for complete stacktrace

Caused By:
        at mypackage.MyClass.checkCondition(

View raw message