cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "abdelgadiri (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-5201) jaxrs2: unable to intercept response to add new response headers
Date Thu, 15 Aug 2013 09:20:48 GMT

    [ https://issues.apache.org/jira/browse/CXF-5201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13740826#comment-13740826
] 

abdelgadiri commented on CXF-5201:
----------------------------------

I have wrapped the response and passed it to the jax-rs interceptor which sets the header
on it. I can see the setHeader() method getting called on my response wrapper but when printing
the available headers from the filter (on way out), the just added header is missing.


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

        //proceed
        filterChain.doFilter(servletRequest, responseWrapper);

		//print on way out - however, the additional header added by the jax-rs interceptor is missing
        Collection<String> headerNames = responseWrapper.getHeaderNames();
        for (String hn : headerNames) {
            Collection<String> headers = responseWrapper.getHeaders(hn);
            System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found response header (" + hn
+ "): " + headers);
        }
}

/** The response wrapper passed to the JAX-RS interceptor. */
public class MyHttpServletResponseWrapper extends HttpServletResponseWrapper {
    public MyHttpServletResponseWrapper(HttpServletResponse response) {
        super(response);
    }

    @Override
    public void setDateHeader(String name, long date) {
        System.out.println("****** setting date header ... " + name);
        super.setDateHeader(name, date);
    }

    @Override
    public void addDateHeader(String name, long date) {
        System.out.println("****** adding date header ... " + name);
        super.addDateHeader(name, date);
    }

    @Override
    public void setHeader(String name, String value) {
		//this method is being invoked by the OutboundMsgInterceptor
        System.out.println("****** setting header ... " + name);
        super.setHeader(name, value);
    }

    @Override
    public void addHeader(String name, String value) {
        System.out.println("****** adding header ... " + name);
        super.addHeader(name, value);
    }

    @Override
    public void setIntHeader(String name, int value) {
        System.out.println("****** setting int header ... " + name);
        super.setIntHeader(name, value);
    }

    @Override
    public void addIntHeader(String name, int value) {
        System.out.println("****** adding int header ... " + name);
        super.addIntHeader(name, value);
    }
}


@Provider
public class OutboundMsgInterceptor implements WriterInterceptor {

    @Context
    private HttpServletResponse response;
	
	  public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException
{
		//this will definitly invoke the relevant methods in MyHttpServletResponseWrapper. 
	    response.setHeader("headerName", "headerValue");
	  }
}
                
> jaxrs2: unable to intercept response to add new response headers
> ----------------------------------------------------------------
>
>                 Key: CXF-5201
>                 URL: https://issues.apache.org/jira/browse/CXF-5201
>             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: http://www.atlassian.com/software/jira

Mime
View raw message