[Jersey] Re: JSONP and exception mapping

From: Francisco A. Lozano <>
Date: Wed, 15 Feb 2012 18:51:09 +0100

Maybe I am not understanding the question, but I think you can return
a JSONWithPadding in the toResponse method of the

                return Response.status(YOUR_STATUS_CODE)
                                .entity(new JSONWithPadding(yourJSONObject, yourCallback) ).build();

If the problem is to propagate the JS callback from the request, one
possible solution if you're using Spring would be to use a
request-scoped object injected (as an scoped proxy) both in the Jersey
resource and in the ExceptionMapper - put there everything you need
(the JS callback you got in the request, for example) and use it in
the ExceptionMapper.

Francisco A. Lozano

On Wed, Feb 15, 2012 at 04:22, Ed Anuff <> wrote:
> I'm wondering what the best way is to handle exceptions when using JSONP?
> I'm thinking that the best thing to do is to return a proper JSONP result
> with an error code inside of the response, but I can't really see how that
> would be accomplished with the existing ExceptionMapper mechanism.  Is there
> a way to do this?
> Ed