Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Jobs can be implemented to access RESTful web services.
  • A REST web service client is available for Scripting of Jobs and Monitors that are implemented with Java or JavaScript.
  • This feature is provided with 
    Jira
    serverSOS JIRA
    columnskey,summary,type,created,updated,due,assignee,reporter,priority,status,resolution
    serverId6dc67751-9d67-34cd-985b-194a8cdc9602
    keyJITL-213
  • POST and PUT with a body is provided with
    Jira
    serverSOS JIRA
    columnskey,summary,type,created,updated,due,assignee,reporter,priority,status,resolution
    serverId6dc67751-9d67-34cd-985b-194a8cdc9602
    keyJITL-273272


Implementation

  • JITL provides a static Java class that can be used with Java and JavaScript. This class accepts a URL and returns an object in JSON syntax.
  • For use with JavaScript the JSON object can be converted to a JavaScript object.

...

  • 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:44445/jobscheduler/agent/api/" );
    • var response = com.sos.jitl.restclient.JobSchedulerRestClient.executeRestServiceCommand( "get", "http://localhost:44445/jobscheduler/agent/api/" );
  • Webservice 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:
      • jsonObject.system.hostname
  • The web service returns an XML document:Webservice returns a xml element
    • The result can be parsed using the SOSXMLXPath Java class.
      • see example below
Code Block
languagejs
linenumberstrue
collapsetrue
function spooler_process() { 
  var s = com.sos.jitl.restclient.JobSchedulerRestClient.executeRestService( "http://www.thomas-bayer.com/sqlrest/CUSTOMER/18/" );
  spooler_log.info( s);
  var xmlDOM = new Packages.sos.xml.SOSXMLXPath( new java.lang.StringBuffer( s ) );
   spooler_log.info( "Firstname is " + xmlDOM.selectSingleNodeValue( "//CUSTOMER/FIRSTNAME" ));
 
  return false;
}

Examples

Simple REST Client Example

  • JavaScript example for use with a job: this job requests the status information from the JobScheduler Universal Agent and returns the total number of tasks that have been executed during the Agents' lifetime. This job reads the web service URL from a job parameter.
  • Download: rest_client.job.xml 
     

...