In Jersey 1.x As I recall if Jersey doesn't find a matching Resource for the request, it issues something like a WebApplicationException or something like that.
You could create a WebApplicationExceptionMapper (see Jersey ExceptionMapper) to "catch" this and return a JSON response.
--joe
From: Bobby Bissett <bbissett_at_gmail.com<mailto:bbissett_at_gmail.com>>
Reply-To: "users_at_jersey.java.net<mailto:users_at_jersey.java.net>" <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Date: Wednesday, November 18, 2015 at 4:51 PM
To: "users_at_jersey.java.net<mailto:users_at_jersey.java.net>" <users_at_jersey.java.net<mailto:users_at_jersey.java.net>>
Subject: [Jersey] Re: returning default jersey responses as json
On Wed, Nov 18, 2015 at 5:56 PM, Joe Mocker <jmocker_at_tremorvideo.com<mailto:jmocker_at_tremorvideo.com>> wrote:
If its not reaching your code, and so I'm guessing not even reaching Jersey, you'll probably have to add some custom error pages to your web.xml -
No, it's definitely in the Jersey code. If nothing else, a DELETE call to one of my resources that doesn't support DELETE results in a 405 that lists the actions that *are* possible (which only the Jersey annotation processor knows). I just don't have any code for that action, so none of my code is called. To expand on my earlier example, I have /api/<etc>/* mapped to the Jersey servlet, and a URI that starts with that but doesn't match any of my paths gets into the Jersey servlet, but of course doesn't call my code since I don't have anything that matches.
It looks like Jersey 2.X has specifically what I'm looking for in its server filter objects; am trying to figure out how to do the same thing with 1.X, unless there's some other setting I don't know about in Jersey that does the same thing for me.
Thanks,
Bobby