> Date: Mon, 19 Aug 2013 11:04:49 +0300
> From: [email protected]
> To: [email protected]
> Subject: Re: Copy JMS headers from request to response in CXF
>
> On 19/08/13 10:57, Dennis Walter wrote:
> >>> In a SOAP over JMS setting using CXF 2.6.9, I have to copy non-standard
> >>> JMS headers from the request to the response (on the server side).
> >>> Unfortunately, I cannot find any documentation or hints on how to do
> >>> that. I looked at the implementation of JMSDestination, where it looks as
> >>> if I cannot do this at all. Ideally, I'd use an interceptor. Can anyone
> >>> help?
> >>>
> >>> Background: our enterprise service bus uses several connected "ESB
> >>> clusters" and requires that all responses in a web service via SOAP over
> >>> JMS MUST contain a certain set of custom-made JMS headers (e.g.,
> >>> "com_myenterprise_esb_state") copied 1-to-1 from the request. This
> >>> requirement is not negotiable.
> >>>
> >>> We are using CXF 2.6.9, Websphere MQ 7.0.1.3, JBoss EAP 6.1.
> >> As far as I recall, all JMS headers will be available as
> >> Message.PROTOCOL_HEADERS map property on the inbound message, so what
> >> you can do is to add an outbound CXF interceptor which will do
> >>
> >> Message inMessage = outMessage.getExchange().getInMessage();
> >>
> >> then get the in headers from it and copy the required ones to the response
> >>
> > What phase would I have to add this interceptor to? PRE_PROTOCOL?
> I guess any phase before MARSHAL will do, as headers would typically be
> written out before the marshaling is done, but I'm not sure about JMS...
>
Your solution works! You saved my day.
For reference, this is what I did to achieve copying of JMS headers from SOAP
request to response:
In my applicationContext.xml, I added an outInterceptor to the jaxws:endpoint
<jaxws:outInterceptors>
<ref bean="webservice.soapJmsTimbOutInterceptor" />
</jaxws:outInterceptors>
The interceptor class extends AbstractPhaseInterceptor<SoapMessage> and
overrides handleMessage to set the configured Headers (List<String>
includeHeadersList) as follows:
@SuppressWarnings("unchecked")
@Override
public void handleMessage(SoapMessage message) throws Fault {
Map<String, List<String>> outHeaders =
(Map<String,
List<String>>)message.get(Message.PROTOCOL_HEADERS);
if (outHeaders == null) {
outHeaders = new TreeMap<String, List<String>>();
message.put(Message.PROTOCOL_HEADERS, outHeaders);
}
Message inMessage = message.getExchange().getInMessage();
Map<String, List<String>> inHeaders =
(Map<String,
List<String>>)inMessage.get(Message.PROTOCOL_HEADERS);
if (inHeaders != null) {
for (String header : includeHeadersList) {
if (inHeaders.containsKey(header)) {
outHeaders.put(header, inHeaders.get(header));
}
}
}
}
> Cheers, Sergey
>
> > Thank you!
> >
> >> HTH, Serggey
> >>>
> >>> Many thanks!
> >>>
> >>>
> >>
> >
> >
>