On Sep 17, 2009, at 1:32 PM, Stephen Duncan Jr wrote:
> Ok, I spoke too soon. I wrote my ExceptionMapper as
> ExceptionMapper<Throwable>, since I wanted it to be the fallback.
> But it goes too far; now I don't get the default Jersey behavior of
> 404 when URLs don't match, etc. Instead I get my 500 error. I'm
> not sure how to replace just the old 500 error behavior. Should I
> be looking at a servlet filter or some other technique instead?
>
I think if you add some logic to your mapper to check for instances of
WebApplicationExceptions and when one of those is passed in then just
return the embedded response you should get the right behavior:
if (ex instanceof WebApplicationException)
return ((WebApplicationException)ex).getResponse();
You might still want to add a standard body to the returned response
like this:
if (ex instanceof WebApplicationException) {
Response r = ((WebApplicationException)ex).getResponse();
if (r.getEntity() == null)
r =
response.fromResponse(r).entity(someBody).type(someType).build();
return r;
}
Marc.
>
> On Wed, Sep 16, 2009 at 4:02 PM, Stephen Duncan Jr <stephen.duncan_at_gmail.com
> > wrote:
> Thanks, that worked perfectly.
>
>
> --
> Stephen Duncan Jr
> www.stephenduncanjr.com
>
>
> On Wed, Sep 16, 2009 at 2:35 PM, Marc Hadley <Marc.Hadley_at_sun.com>
> wrote:
> Sounds like the standard ExceptionMapper will do what you want:
>
> https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/ext/ExceptionMapper.html
> https://jsr311.dev.java.net/nonav/releases/1.0/spec/
> spec3.html#x3-510004.4
>
> Marc.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>
>
> --
> Stephen Duncan Jr
> www.stephenduncanjr.com