title: Jersey: A generic catch all handler for errors?
body: <p>Jersey supports ExceptionMappers as a way to generically handle bad things, but that only works if the call reached my code. If someone boffs the URL, say <code>http://host/fubar</code> instead of <code>http://host/foobar</code>, then it returns a generic 404.</p>
  
  <p>I need to get a hold of those boffed URLs and redirect to a page of my choosing, but after several hours I can't seem to find the right configuration to make that happen. I've been walking through the debugger, but I'm not finding the spot where I'd hook in some configuration to redirect such 404's to a page of my choosing.</p>
  
  <p>Edit: Note that a custom exception mapper for any WebApplicationException is ignored by Jersey (1.17.1). It's instead routed to a different method for handling. Here's the code snippet from Jersey's ContainerResponse.java:</p>
  
  <pre><code>if (cause instanceof WebApplicationException) {
      mapWebApplicationException((WebApplicationException)cause);
  } else if (!mapException(cause)) { ... }
  </code></pre>
  
  <p>That mapWebApplicationException((WebApplicationException)cause) is Jersey's own handling, so it never hits the mapException(cause) method in the elseif which is where the custom mappers are invoked.</p>