users@jersey.java.net

Re: [Jersey] Get Response in object provider

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Wed, 13 Oct 2010 12:46:13 +0200

On Oct 12, 2010, at 3:10 PM, Alexander Chuprin wrote:

> Hello.
>
> All my resource methods returns Response type. I want to add field
> to all response enities depend in response status. I use
> MessageBodyWriter to json serialization. I want to add field to json
> depends on response status. In example i want to add success:true if
> my method returns Response.ok(entity).build() but don't have
> response status in writeable method.
>
> Is there ways to add this logic?
>

You can inject the Jersey interface:

   @Context HttpContext hc;


then do:

   hc.getResponse().getStatus();

Paul.