You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Gabo Manuel <km...@solegysystems.com> on 2009/02/17 10:56:40 UTC

Re: [OutInterceptor][HttpHeader] Adding Authorization-Info entry to http header

Hi Sergey,

 > so I'll try to write one and see what happens.

Sorry for the late reply. I tried this again with the recent snapshot 
and the headers are still lost unless I abort the interceptor chain.

The implementation I have extends AbstractPhaseInterceptor<Message>. 
Phase is at Phase.POST_PROTOCOL. Code to set the header is as follows:

        Map<String, List<String>> responseHeaders = (Map<String, 
List<String>>)message.get(Message.PROTOCOL_HEADERS);
       
        if (responseHeaders == null) {
            responseHeaders = new HashMap<String, List<String>>();
            message.put(Message.PROTOCOL_HEADERS, responseHeaders);
        }
       
        responseHeaders.put("header1", Arrays.asList(new 
String[]{"headerValue"}));
        logger.debug("out message headers: " + responseHeaders);

then I do something similar to what was done here:

http://www.nabble.com/-OutInterceptor--HttpHeader--Adding-Authorization-Info-entry-to-http-header-td20375003.html

On the other hand, I was able to successfully retain the headers using a 
ResponseHandler implementation with the following statement:

        MultivaluedMap<String, Object> map = response.getMetadata();
        map.add("header1", "headerValue");
        //I think it is worth noting in the docs it is this easy to 
modify the headers :D

So I guess I will be using the the ResponseHandler from now on. At least 
for header post-processing.

One thing though, with messages the expected value for headers is a 
List<String>, while with Response it is just String. Would it be 
possible to adjust one so they would expect the same object?

Again, my thanks.

Gabo

Sergey Beryozkin wrote:
> Hi Gabo
>
>> Hi Sergey,
>>
>> Is there a resource that shows how the filter is integrated with the 
>> rest of the application? I mean, where do I state that I want this 
>> filter used, i.e. how would the spring configuration file look like?
>
> I've updated the documentation a bit to show how filters can be 
> configured from Spring. As they're considered
> as JAXRS providres by CXF JAXRS runtime, they're registered the same 
> way as other JAXRS providers (message body readers/writers, exception 
> mappers. context handlers, etc)
>
>
>>
>> As of now, what I did is to set the phase at POST_PROTOCOL and force 
>> the chain to abort and flush whatever it already currently has. I'm 
>> thinking that skipping the USER_ and POST_ STREAM is not a good idea, 
>> no? Does the trick tho.
>
> I guess what I don't understand is whether your POST_PROTOCOL CXF 
> interceptor invoked before JAXRSOutInterceptor or after. My 
> understanding is that it has to be invoked after, so I don't get why 
> the headers are lost if a message is not aborted and preserved if it 
> is. Perhaps AbstractHttpDestination swallows custom headers ? but we 
> do have tests confirming it's not...I don't have tests at the moment 
> involving JAXRS and CXF interceptors, so I'll try to write one and see 
> what happens.
>
> Cheers, Sergey
>