users@jersey.java.net

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

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 15 Sep 2011 10:06:51 +0200

Hi ManiKanta,

I do not think this could be fixed/handled in Jersey.

I presume there are some (Tomcat specific) settings
to make Tomcat leave the response body intact.

I do not know any details on that, but i think you should
look at Tomcat docs or seek for help at Tomcat user list.

~Jakub


On 14.9.2011 22:21, ManiKanta G wrote:
>
> Hi,
>
> 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> {
> @Override
> 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)
> e).getResponse()).entity(null).build();
>
>
> If I set some non-null entity, the response is just the headers and
> the entity (no Tomcat specific HTML).
>
> return Response.fromResponse(((WebApplicationException)
> e).getResponse()).entity("error").build();
>
>
> Is this what the actual behaviour and if yes, can we change
> that behaviour?
>
> Thanks,
> ManiKanta G
> twitter.com/ManiKantaG <http://twitter.com/ManiKantaG>