Details
-
Feature
-
Status: Released (View Workflow)
-
Minor
-
Resolution: Fixed
-
None
Description
Requirements
- Users want to call REST web services in job scripts and monitor scripts. This includes scripts implemented with Java or JavaScript.
- The web service response should be available as an object with properties.
Feature
- 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.
- JavaScript sample for use with a job: this sample requests the status information from the JobScheduler Universal Agent and returns the total number of tasks that have been executed during the Agents' lifetime:
<job stop_on_error="no" > <params > <param name="agent_service" value="localhost:4445/jobscheduler/agent/api/"/> </params> <script language="java:javascript"> <![CDATA[ function spooler_process() { var parameters = spooler.create_variable_set(); parameters.merge( spooler_task.params ); var agent_service = parameters.value( "agent_service" ); var response = com.sos.jitl.restclient.JobSchedulerRestClient.executeRestService( agent_service ); // alternative REST methods // 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:4445/jobscheduler/agent/api/" ); // var response = com.sos.jitl.restclient.JobSchedulerRestClient.getRestService( "localhost", 4445, "/jobscheduler/agent/api/", "http" ); if (response) { eval ( "var jsonObject = " + response + ";" ); spooler_log.info( jsonObject.totalTaskCount + " tasks on Agent [" + agent_service + "]: " + jsonObject.system.hostname ); } else { spooler_log.error( "no response from Agent web service at: " + agent_service ); } return (response != ""); } ]]> </script> <run_time /> </job>
Implementation
- Web Service Request
- REST web services can be used with any of the verbs GET, POST, PUT, DELETE
- A web service request optionally includes
- a JSON object
- a XML document object
- a file
- Header Information
- Additional headers such as "accepted mime-type", "content-type", "user", password" etc. can be specified
- Web Service Response
- A web service reponse optionally includes
- a JSON object provided with the mime type "application/json"
- a XML document object provided with the mime type "application/xml"
- a file, e.g. from a REST Web Service that return PDF documents, including the respective response headers, e.g. "application/pdf"
- Web Service Requests throw exceptions should an error occur. Such exceptions are handled in the job script or monitor script.
- A web service reponse optionally includes