This is my first post to these lists, so I apologize if I'm sending
this to the wrong one.
I recently ran into an issue trying to map NotFoundException (and
friends) to my own custom exception mapper. The goal of this exercise
was to always return JSON-Formatted content, even on exceptions, to
allow for easier processing client-side.
This is also important for logging purposes - For example, taking a
custom action when a user requests a URI that isn't currently mapped,
and returning something other than the default 404.
I ended up making the following change to support my desired behavior,
but I'd love to know if theres a more standard way of achieving this.
---
a/jersey/jersey-server/src/main/java/com/sun/jersey/spi/container/Conta
inerResponse.java
+++
b/jersey/jersey-server/src/main/java/com/sun/jersey/spi/container/Conta
inerResponse.java
@@ -417,12 +417,8 @@ public class ContainerResponse implements
HttpResponseContext {
* @param e the web application exception.
*/
public void mapWebApplicationException(WebApplicationException e)
{
- if (e.getResponse().getEntity() != null) {
+ if (!mapException(e)) {
onException(e, e.getResponse(), false);
- } else {
- if (!mapException(e)) {
- onException(e, e.getResponse(), false);
- }
}
}