1

In Jersey 1 you can create a container response filter and get access to the Response:

public ContainerResponse filter(ContainerRequest request, ContainerResponse response)
{
   Response r = response.getResponse();

   // Now I have access to Reponse.getMetadata(), etc.
}

But in Jersey 2, the ContainerResponseFilter only gives me the response context:

public void filter(ContainerRequestContext  requestContext,
                   ContainerResponseContext responseContext) throws IOException
{
    // responseContext gives me the entity, but I want the JAX-RS Response object that my resources created
}

The implementation of ContainerResponseContext is ContainerResponse, which requires a JAX-RS Response object to build. So why can't I get access to it from within the filter? Am I missing something?

The problem I have is that my resources all build Response objects and attach meta data to them, and I'd like a response filter that can examine this meta data. Without access to the raw Response, this doesn't seem possible.

Mike
  • 4,722
  • 1
  • 27
  • 40

2 Answers2

0

According to the Javadocs API the Response.getMetadata() is considered deprecated, even though it's not marked as such as of 2.12. The preferred alternative is to use HTTP headers.

Mike
  • 4,722
  • 1
  • 27
  • 40
0

you can get access to every response object by implementing a custom ResourceMethodInvocationHandler. Look at my answer @ Registering a custom ResourceMethodInvocationHandler in Jersey

Community
  • 1
  • 1
snbl
  • 76
  • 3