I need to somehow include in my soap service envelope a header whose values are "Authorization"
and "Bearer xXsomeCode123xX"
, this is the part of the code I need to edit with the new header, which then returns me an xml document with some data requested through the soap web service.
//SERVICE
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endPointURL));
call.setSOAPActionURI(soapActionURI);
//INVOKE
SOAPEnvelope response = (SOAPEnvelope) call.invoke(new Message(soap.asXML()));
Document doc = new DOMReader().read(response.getAsDocument());
return doc;
This is what i see in SoapUI (and works with the header set like that)
I know the question is confusing, and I am, I've researched on the internet but almost every header is made of username:password fields, while i only have this "Authorization" to work on
If you are using WebServiceTemplate
you can do the method marshalSendAndReceive
with a WebServiceMessageCallback
, in these callback you can add RequestHeader
in that you can put the Authorization and bearer + token, your method doWithMessage must looks like as bellow:
public void doWithMessage(WebServiceMessage webServiceMessage) throws IOException, TransformerException {
TransportContext context = TransportContextHolder.getTransportContext();
HeadersAwareSenderWebServiceConnection connection = (HeadersAwareSenderWebServiceConnection) context.getConnection();
connection.addRequestHeader("Authorization", String.format("Bearer %s", "********"));
}
More info in this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With