...
- Basically a web service call is implemented by executing one of the above methods from the JITL Java class, e.g.:
var response = com.sos.jitl.restclient.JobSchedulerRestClient.executeRestService( "http://localhost:4445/jobscheduler/agent/api/" );
var response = com.sos.jitl.restclient.JobSchedulerRestClient.executeRestServiceCommand( "get", "http://localhost:4445/jobscheduler/agent/api/" );
- The web service returns a serialized JSON Object:
- The result object returned by the web service can be converted to a JavaScript JSON object by use of the
eval()
function:eval ( "var jsonObject = " + response + ";" );
- Properties of the JSON object can be accessed within the object hierarchy provided by the web service result object like this:
see example for
jsonObject.system.hostname
from the JobScheduler Agent REST web service below:Code Block language js title Example for REST web service client processing a JSON response linenumbers true collapse true function spooler_process() { var response = com.sos.jitl.restclient.JobSchedulerRestClient.executeRestService( "http://localhost:4445/jobscheduler/agent/api/" ); if (response) { eval ( "var jsonObject = " + response + ";" ); spooler_log.info( jsonObject.totalTaskCount + " tasks executed on Agent [" + rest_service + "]: " + jsonObject.system.hostname ); } else { spooler_log.error( "no response from REST web service at: " + rest_service ); } return false; }
- The result object returned by the web service can be converted to a JavaScript JSON object by use of the
- The web service returns an XML document:
- The result can be parsed using the SOSXMLXPath Java class.
see example below
Code Block language js title Example for REST web service client processing an XML response linenumbers true collapse true function spooler_process() { var response = com.sos.jitl.restclient.JobSchedulerRestClient.executeRestService( "http://www.thomas-bayer.com/sqlrest/CUSTOMER/18/" ); spooler_log.info( response ); var xmlDOM = new Packages.sos.xml.SOSXMLXPath( new java.lang.StringBuffer( response ) ); spooler_log.info( "Firstname is " + xmlDOM.selectSingleNodeValue( "//CUSTOMER/FIRSTNAME" )); return false; }
- The result can be parsed using the SOSXMLXPath Java class.
...