cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "abdelgadiri (JIRA)" <>
Subject [jira] [Commented] (CXF-5201) jaxrs2: unable to intercept response to add new response headers
Date Thu, 15 Aug 2013 11:02:47 GMT


abdelgadiri commented on CXF-5201:

I think this might be a problem with the Servlet implementation as opposed to cxf because
even if I set a new header within the servlet filter, I am  still unable to read it back.
See below

@WebFilter(urlPatterns = {"/*"})
public class ResponseDebugFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {
        //do nothing

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain
            throws IOException, ServletException {
        VelosHttpServletResponseWrapper responseWrapper = new VelosHttpServletResponseWrapper((HttpServletResponse)

        //carry on as normal
        filterChain.doFilter(servletRequest, responseWrapper);

        //I am explicitly defining a new header here so I would expect to be able to read
it back below   
        responseWrapper.setHeader("newlyDefinedHeader", "newHeaderValue");

        //print response headers on way out but above "newlyDefinedHeader" is not printing
i.e., missing
        Collection<String> headerNames = responseWrapper.getHeaderNames();
        for (String hn : headerNames) {
            Collection<String> headers = responseWrapper.getHeaders(hn);
            System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found response header (" + hn
+ "): " + headers);

    public void destroy() {
        //do nothing
> jaxrs2: unable to intercept response to add new response headers
> ----------------------------------------------------------------
>                 Key: CXF-5201
>                 URL:
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.7.5, 2.7.6
>         Environment: windows
>            Reporter: abdelgadiri
> In a WriterInterceptor, one expects to be able to modify response headers via:
> //here using putSingle() but could also use on of the addXXX variants
> context.getHeaders().putSingle("headerName", headerValue);
> However, above is not working in 2.7.5/2.7.6 (@see JIRA-4986)
> As a workaround, one should be able to inject the HttpServletResponse object via: @Context
HttpServletResponse response;
> then be able to add headers directly to the response object e.g.,
> response.setHeader("headerName", headerValue);
> however, above is also not working in (2.7.5/2.7.6). This is not always reproducable
as sometimes my client does see the new headers in the received response. On closer look it
seems the added headers get lost when it is a @GET request as opposed to e.g., a @POST. Basically,
my test case (a @GET) always fails with a missing header in the received response even though
I am pretty sure the server had added the header. 

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message