Groovy 43 – Calling a SOAP WS that needs header authentication from groovy
Call SOAP WS from Groovy
Let's say we need to call a SOAP WS directly from Groovy that requires authentication details in the header.
For this example, we'll use an ICS WS, as ICS web services require this header in the payload.
WSDL used: WSDL Link
This WS has a method called process and the XML payload looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://xmlns.oracle.com/apps/crmCommon/content/outboundMessage/types/" xmlns:cus="http://xmlns.oracle.com/apps/custom">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>USER_NAME</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<typ:process>
<typ:OBJECT>
<cus:ATTRIBUTE>67323741</cus:ATTRIBUTE>
</typ:OBJECT>
</typ:process>
</soapenv:Body>
</soapenv:Envelope>
To call this WS from Groovy, first register the WS in Sales Cloud. Use authentication as "none" or "basic" in the security schema, as we send the authentication in the payload.
Let's use the reference name for the WS: ICS_WS
Now the Groovy code:
Create the Header:
def soapHeader = '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">' +
'<wsse:UsernameToken>' +
'<wsse:Username>USERNAME</wsse:Username>' +
'<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">PASSWORD</wsse:Password>' +
'</wsse:UsernameToken>' +
'</wsse:Security>';
Create the Payload:
def payload = [[
'ATTRIBUTE' :
]]
Call the WS:
def wsdc = adf.webServices.ICS_WS;
wsdc.requestSoapHeader = soapHeader;
def response = wsdc.process(payload);
Hope this helps with calling such web services.