[Jersey] Problem with custom generic RuntimeException mapper & Tomcat error response

From: ManiKanta G <>
Date: Thu, 15 Sep 2011 01:51:41 +0530


I m using Jersey 1.9 and I've written a RuntimeExceptionMapper to handle all
the application runtime exceptions, including Jersey' thrown as well.

public class RuntimeExceptionMapper implements
ExceptionMapper<RuntimeException> {
     public Response toResponse(RuntimeException e) {
          if(e instanceof WebApplicationException) {
                return ((WebApplicationException) e).getResponse();
          // handle other exceptions...

Even I m handling the exceptions, these response are forwarded to http
container (Tomcat, in my case) and the client is receiving the Tomcat
specific HTML response, where as I want the clients to receive only the
status code. I tried with 'null' entity, but it is not working.

return Response.fromResponse(((WebApplicationException)

If I set some non-null entity, the response is just the headers and the
entity (no Tomcat specific HTML).

return Response.fromResponse(((WebApplicationException)

Is this what the actual behaviour and if yes, can we change that behaviour?

ManiKanta G