users@jersey.java.net

[Jersey] Response headers gets removed using HttpContext

From: charlesk <charlesk40_at_yahoo.com>
Date: Wed, 3 Aug 2011 16:03:02 -0700 (PDT)

Hi,
I'm using the @Context private HttpContext _context to write headers.
_context.getResponse().getHttpHeaders().putSingle("Content-Location",
uri.toString());

While stepping through the code,
com.sun.jersey.server.impl.application.WebApplicationContext gets "reset?"
for the response object (com.sun.jersey.spi.container.ContainerRespons)
which has my headers such as:
{ETag=["d6ef538b"], Content-Location=[http://localhost:4080/helloWorld],
Content-Language=[en-US]}
from below method. (Please see context.getResponse().setResponse(r) portion
of the code snippet)

com.sun.jersey.core.spi.factory.ResponseImpl object has no headers when its
created thus my headers are gone from the WebApplicationContext.

Only header gets added is the CONTENT_TYPE but this happends at later stage
by examining the media type.

Is this expected behavior? Is there something I'm missing or is there a
different way to set Response headers?

Thanks

This is with Jersey 1.4

package
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider

    private static final class TypeOutInvoker extends EntityParamInInvoker {
        private final Type t;

        TypeOutInvoker(AbstractResourceMethod abstractResourceMethod,
                InjectableValuesProvider pp) {
            super(abstractResourceMethod, pp);
            this.t = abstractResourceMethod.getGenericReturnType();
        }

        public void _dispatch(Object resource, HttpContext context)
        throws IllegalAccessException, InvocationTargetException {
            final Object[] params = getParams(context);

            final Object o = method.invoke(resource, params);
            if (o != null) {
                Response r = new ResponseBuilderImpl().
                        entityWithType(o, t).status(200).build();
                context.getResponse().setResponse(r);
            }
        }
    }


--
View this message in context: http://jersey.576304.n2.nabble.com/Response-headers-gets-removed-using-HttpContext-tp6650678p6650678.html
Sent from the Jersey mailing list archive at Nabble.com.