users@jersey.java.net

[Jersey] Decorating response entities

From: <sbailliez_at_gmail.com>
Date: Sat, 30 Jul 2011 20:32:16 +0000 (GMT)

For all rest services responses, I would like to provide a consistent
response format which includes some headers/metadata/information
related to the operations. Typically include in the response itself,
the hostname, the operation timing information, etc.. I may pass
information in http headers as well.

so in json, something like:
{
  "headers": { "timing": 12, "hostname": "alpha-svc",
   timestamp: "2011-08-01T00:01:02Z", "service": { "version": "1.2.3",
"name": "alpha" }
   ...},
  "data": ...
}

So the "header" parts would need to be added for all responses, whereas
the data is effectively the response entity.

Is there any particular place that one think of would be suitable to
decorate entity response in such a way ? I was thinking it could
probably be done by binding the headers metadata information to the
thread local then use a special implementation of the messagebodywriter
to decorate the entity.

Thoughts ?