How to set MessageId and ReplyTo header values
This question relates to WS-Addressing client.
Here is a snippet of the SOAP request from page 45 of the Spring documentation version 1.5.8:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:wsa="http://www.w3.org/2005/08/addressing">
<SOAP-ENV::Header>
<wsa:MessageID>urn:uuid:21363e0d-2645-4eb7-8afd-2f5ee1bb25cf</wsa:MessageID>
<wsa:ReplyTo>
<wsa:Address>http://example.com/business/client1</wsa:Address>
</wsa:ReplyTo>
<wsa:To S:mustUnderstand="true">http://example/com/fabrikam</wsa:To>
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<f:Delete xmlns:f="http://example.com/fabrikam">
<f:maxCount>42</f:maxCount>
</f:Delete>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I want to set the ReplyTo and MessageID header values in my SOAP request. Here is the documentation on WS-addressing SOAP client on Page 55:
"For setting WS-Addressing headers on the client, you can use the
org.springframework.ws.soap.addressing.client.Acti onCallback. This callback takes the desired Action
header as a parameter. It also has constructors for specifying the WS-Addressing version, and a To header. If
not specified, the To header will default to the URL of the connection being made"
I have looked up the class definition in Spring API. It does not contain a call back definition for specifying the MessageID and ReplyTo headers in the client. How do I do that?
Thanks.
Bharat
Re: How to set MessageId and ReplyTo header values
Hi Bharat,
You could make your client extend class org.springframework.ws.client.core.support.WebServ iceGatewaySupport.
In there, use any of the sendAndReceive or marshalSendAndReceive methods as in the following piece of sample code:
Code:
getWebServiceTemplate().marshalSendAndReceive(yourDataRequest,
new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage message)
throws IOException, TransformerException {
log.debug("adding soap aheader");
SaajSoapMessage soapMessage = (SaajSoapMessage) message;
soapMessage.getSoapHeader()
.addAttribute(new QName("correlation_ID"),"yourCorrelationId");
soapMessage.getSoapHeader()
.addAttribute(new QName("reply_to"), "yourReplyToAddress");
}
});
Hth,
- Sjoerd