GiLA3
GiLA3

Reputation: 419

Authorization bearer soap request

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)

This is what i see in SoapUI

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

Answers (2)

Yury Shaban
Yury Shaban

Reputation: 105

To add bearer authorization header in SoapUI you have to: (keep in mind that Bearer token belongs to OAuth2)

  • click on "Auth" button in the left bottom corner of the request's window
  • using "Authorization" dropdown, select Add new Authorization.
  • then - Type -> OAuth2, press OK. you'll see a input field named
    Access Token. Just insert you token in it.

Running your request, on http log you'll see something like that: :DEBUG:>> "Authorization: Bearer .... [\r][\n]"

Upvotes: 0

user2581462
user2581462

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

Related Questions