KingTravisG
KingTravisG

Reputation: 1336

Java, Jersey 1.17 & Jetty: Do not return stacktrace in response

I was wondering if anyone could help with a problem I'm having...

At the minute, I'm running a rest service using Jersey 1.17 in a Jetty 8.1.10v20130312 container. If I do something wrong, say for example send a request with a content-type of "abcdefg", I get a response, however the stacktrace is included. I can see from the logs that the exception is an IllegalArgumentException wrapped in a WebApplicationException, but my WebApplicationException mapper is not handling it - I'm guessing that the exception is being thrown somewhere within Jetty, rather than my resource classes?

Is there a way to pre-empt or catch the error? Or a way to prevent the stacktrace from being included?

Any help would be much appreciated as usual!

Upvotes: 1

Views: 1280

Answers (1)

Michal Gajdos
Michal Gajdos

Reputation: 10379

You can define your own page for handling errors in web.xml (because this seems to be an issue of Jetty rather than Jersey), i.e. for HTTP 500 it would be:

<error-page>  
    <error-code>500</error-code>  
    <location>/WEB-INF/error.jsp</location>  
</error-page> 

Note: I am not sure whether in this case Jersey wraps the IllegalArgumentException caused by the ParsingException (wrong media type of the response) into the WebApplicationException. The IllegalArgumentException is more likely passed to the underlying container (Jetty in this case) which handles it in it's own way.

Upvotes: 2

Related Questions