The current invoke tag via the com.niku.union.gel.SOAPTagLibrary doesn’t allow one to modify the request headers and many web service require authentication such as ServiceNow.
So you have a couple of options:
Use the Jelly soap invokeRaw tag which allows you to define the HTTP headers via the soapAction attribute. For ServiceNow, you would need to include the Authorization header. This tag lib doesn’t come out of the box, so you will need to find the jar and drop it into the lib.
Write a simple wrapper class that handles getting information from external web services and just use the invokeStatic tag in the jelly:core tag lib.
Using brute force to make the soap call by using the java.net.URL class. Being in the On-Demand environment (but not for long!), I often find myself resorting to a brute force method.
The script below calls a simple ServiceNow getRecords on the sys_user table.
<gel:script
xmlns:core="jelly:core"
xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
xmlns:nikuq="http://www.niku.com/xog/Query"
xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sql="jelly:sql"
xmlns:util="jelly:util"
xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
xmlns:xog="http://www.niku.com/xog"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<gel:log>Start this Script</gel:log>
<!-- Set the endpoint to ServiceNow and set our Authorization for Basic -->
<core:set var="soapEndPoint" value="https://demo.service-now.com/sys_user.do?SOAP" />
<core:invokeStatic var="base64" className="com.niku.union.utility.Base64" method="encode">
<core:arg type="java.lang.String" value="admin:password" />
</core:invokeStatic>
<core:set var="basicAuth" value="Basic ${base64}" />
<gel:log>basicAuth = ${basicAuth}</gel:log>
<!-- Open a connection to ServiceNow and set our request headers -->
<core:new var="soapUrl" className="java.net.URL">
<core:arg type="java.lang.String" value="${soapEndPoint}" />
</core:new>
<core:invoke var="connection" on="${soapUrl}" method="openConnection"/>
<core:expr value="${connection.setDoOutput(true)}" />
<core:expr value='${connection.setRequestMethod("POST")}'/>
<core:expr value='${connection.setRequestProperty("Content-type", "text/xml; charset=utf-8")}'/>
<core:expr value='${connection.setRequestProperty("SOAPAction", soapEndPoint)}'/>
<core:expr value='${connection.setRequestProperty("Authorization", basicAuth)}'/>
<core:set var="requestXml">
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<Action soapenv:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.service-now.com/sys_user/getRecords</Action>
</soapenv:Header>
<soapenv:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<getRecords xmlns="http://www.service-now.com/sys_user">
<last_name xmlns="">greiff</last_name>
</getRecords>
</soapenv:Body>
</soapenv:Envelope>
</core:set>
<!-- Write out our getRecords request to ServiceNow -->
<core:invoke var="outputStream" on="${connection}" method="getOutputStream" />
<core:new var="outputStreamWriter" className="java.io.OutputStreamWriter">
<core:arg type="java.io.OutputStream" value="${outputStream}" />
</core:new>
<core:expr value="${outputStreamWriter.write(requestXml)}" />
<core:expr value="${outputStreamWriter.close()}" />
<!-- Read in the response from ServiceNow into a string -->
<core:invoke var="inputStream" on="${connection}" method="getInputStream" />
<core:new var="inputStreamReader" className="java.io.InputStreamReader">
<core:arg type="java.io.InputStream" value="${inputStream}" />
</core:new>
<core:new var="stringBuilder" className="java.lang.StringBuilder" />
<core:set var="data" value="${inputStreamReader.read()}" />
<core:while test="${data != -1}">
<core:invokeStatic var="char" className="java.lang.Character" method="toChars" >
<core:arg type="int" value="${data}" />
</core:invokeStatic>
<core:invokeStatic var="charString" className="java.lang.String" method="valueOf" >
<core:arg value="${char}" />
</core:invokeStatic>
<core:set var="char" value="${java.lang.String.valueOf(java.lang.Character.toChars(data))}"/>
<core:invoke method="append" on="${stringBuilder}">
<core:arg value="${charString}" />
</core:invoke>
<core:set var="data" value="${inputStreamReader.read()}" />
</core:while>
<!-- Here is a string of the xml reponse payload -->
<gel:log>${stringBuilder.toString()}</gel:log>
<gel:log>End this Script</gel:log>
</gel:script>
V/r,
Gene