I want my ExceptionMapper to catch all exceptions and log them... I'm using Jersey 2.0 right now.
I have an exception mapper like so:
@Provider
public class RestExceptionMapper implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception e) {
log(e);
if (e instanceof WebApplicationException) {
return ((WebApplicationException) e).getResponse();
} else {
return buildResponse(e);
}
This exception mapper only gets called for non-WebApplication application exceptions.
How do I make one global exception mapper catch all the exceptions so I can log them. Is there another way I should approach this?
Thanks
Judging from the source code of Jersey where this is handled there is no way to do this with an ExceptionMapper
. WebApplicationExceptions
get a special treatment are never mapped.
A way to log all exceptions is to set the logger org.glassfish.jersey.server.ServerRuntime
to FINER
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.