Reputation: 419
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
Upvotes: 4
Views: 10692
Reputation: 105
To add bearer authorization header in SoapUI you have to: (keep in mind that Bearer token belongs to OAuth2)
Running your request, on http log you'll see something like that: :DEBUG:>> "Authorization: Bearer .... [\r][\n]"
Upvotes: 0
Reputation: 31
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
Upvotes: 2