users@jersey.java.net

[Jersey] Re: returning default jersey responses as json

From: Jenn Sears <galtechservices_at_gmail.com>
Date: Wed, 18 Nov 2015 15:11:59 -0800 (PST)

Generally, if a path isn't mapped in your web.xml, or if you're using jax-rs, your resources, your server will go to whatever the default 404 is.  There is also a standard NotFountException in jax-rs that you can use the mapper I linked to.  That's what catches basically everything else.  Anything not explicitly defined gets a 500 - Internal Error response in json. That should cover just about all your cases.




HTH




Cheers,

J

On Wed, Nov 18, 2015 at 6:07 PM, Bobby Bissett <bbissett_at_gmail.com> wrote:

> On Wed, Nov 18, 2015 at 2:41 PM, Jennifer Sears <jsears_at_galtech.net> wrote:
>> Have you tried using a custom ObjectMapper? It sounds like you need to
>> map your exceptions like described at the link below.
>>
> Thanks for the quick response. My exceptions (meaning anything I throw or
> catch) are all ok since I can throw a custom Exception that can generate
> the JSON. It's the cases where my code isn't even called that I don't know
> how to handle.
> For instance, when someone hits http://myserver/this_is_not_a_real_url I
> don't know if Jersey generates an exception internally or if it just sees
> that the URI doesn't match anything and responds with the 404. If so, then
> maybe the mapping would work. I'll try that and just map to Exception to
> see if something useful pops out.
> Cheers,
> Bobby