Hi,
setting the response HTTP headers is more complicated than setting the
request HTTP headers.

The problem with setting the response headers is that the protocol
headers object is instantiated by the BareOutInterceptor during its
invocation in default. And this BareOutInterceptor is also responsible
for copying the headers to the HttpservletResponse. So, simply
inserting your interceptor to manipulate the protocol headers after
this interceptor, which is located at the marshal phase, will bring no
effect.

One possible approach is to put your interceptor in front of the
BareOutInterceptor. (e.g., using the write phase or using the marshal
phase with an addAfter option). In your interceptor's handleMethod,
you can't find the protocol headers unless another interceptor
instatiated the protocol headers object. So you need to instatiate one
if it is not there and set it to the message. For CXF 2.4.x, there is
a utility class that you can use as shown below:

import org.apache.cxf.transport.http.Headers;
...
    public void handleMessage(Message message) throws Fault {

        Map<String, List<String>> headers =
Headers.getSetProtocolHeaders(message);

This method returns the protocol headers if it is available.
Otherwise, it creates one, sets it to the message and returns it.

For CXF 2.3.x, you don't have this utility method, so you need to do
something like

Map<String, List<String>> headers = message.get(Message.PROTOCOL_HEADERS);
if (headers == null) {
    headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    message.put(Message.PROTOCOL_HEADERS, headers);
}


regards, aki

2011/5/10 minred <[email protected]>:
> Hi
>
> My webservice has one method void send(String msg ).
>
> I'm trying to set HTTP header (e.g Content-Type) in webservice using
> Interceptor.
> I have implemented an Interceptor extending AbstractPhaseInterceptor and
> added his in
> Phase.POST_PROTOCOL.
>
>
> I can see from the logs that this interceptor get registered but
> when an HTTP response is sent the handleMessage() is never invoked.
>
> What could be the reason?
>
> rgds
> minred
>
> --
> View this message in context: 
> http://cxf.547215.n5.nabble.com/Interceptor-not-invoking-handleMessage-custome-HTTP-headers-in-response-tp4383719p4383719.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Reply via email to