users@jersey.java.net

[Jersey] Re: How to intercept response and get original entitiy object?

From: <marceloverdijk_at_gmail.com>
Date: Thu, 22 Aug 2013 10:30:41 +0000 (UTC)

Hi Jakub,

Thanks for your reply. So with @Context UriInfo uriInfo I can get the
"suppress response codes" request parameter.
But what I wonder more is how to get the response body to enhance it?
To be more concrete I send a a Response in my resource using:

javax.json.JsonObject json = ..
return Response.ok().entity(json).build()

Can I get hold on this json (JsonObject) in a response interceptor?


/M



=======================================================
Hi,

Confirmed this should be possible using an interceptor.

You only need to inject e.g. UriInfo (with @Context UriInfo uriInfo)
into your interceptor to get access to the query parameters.

HTH,

~Jakub


On Aug 22, 2013, at 8:48 AM, marceloverdijk@... wrote:

> My resource method is returning a javax.json.JsonObject containing
> data.
>
> I want to intercept this response, and enhance the JsonObject with
> additional data.
>
> Is this possible in an interceptor?
>
>
> The use case is I want to implement "suppress response codes"
> functionality similar to Twitters api.
> If a certain request parameter is present in the api request (e.g.
> ?suppress_response_codes=true) I want to wrap my actual response in
> something like:
> { "status": 200,
> "response": { .. }
> }