We need to consume webservices developed by other team. Using JAX-WS
for generating the webservices. We are using wsimport to generate the client side stubs.
The problem is that i need to pass the following info as a header along with the SOAP body:
<soapenv:Header>
<ns1:HeaderData xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:ns1="http://www.example.com/esb/data_type/HeaderData/v1">
<ChannelIdentifier>ABC</ChannelIdentifier>
</ns1:HeaderData>
</soapenv:Header>
We are using:
BindingProvider.getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
serviceConfig.getServiceEndPoint()
);
to set the endpoint.
Can anyone suggest how to pass headers with request?
Thanks, VK
use param
header = true
of@WebParam
annotationheader = true, mode = Mode.OUT
means that paramheaderParam
will be only in output in header.If you want this this param in input and in output, make
Mode.INOUT
I had to add user credentials into the header so I made it like this:
And everything works fine. Every call to web service comes with username and password passed to this header. You can easily change this to work in your case.
EDIT
The code above is using
CXF
API to modify header. I have also done this usingJAX-WS
. It does almost the same, modifies the header to add the user credentials:And I define this handler in
Spring
configuration like this:All you need to do is to implement
SOAPHandler<SOAPMessageContext>
interface, override its methods and then you can do what ever you want with aSOAP
message.