Skip to end of metadata
Go to start of metadata

Scope

  • 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  JITL-213 - Enable Job scripts and Monitor scripts to use REST web services Released
  • POST and PUT with a body is provided with JITL-272 - Enable POST and PUT commands with a body when calling REST Web Services Released

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.

Methods

MethodArgumentsDescription
com.sos.jitl.restclient.JobSchedulerRestClient.executeRestService
 execute a GET operation and return the result object
 urla URL that includes host and port of the web service, e.g.
http://localhost:44445/jobscheduler/agent/api/
com.sos.jitl.restclient.JobSchedulerRestClient.executeRestServiceCommand
 execute a configurable operation and return the result object
 operation

one of the HTTP verbs:

GET, POST, PUT, DELETE

POST|PUT can be parameterized with the body

POST(<person><id>4711</id><name>helloworld</name></person>)

 urla URL that includes host and port of the web service, e.g.
http://localhost:44445/jobscheduler/agent/api/
com.sos.jitl.restclient.JobSchedulerRestClient.getRestService
 execute the web service operation using GET
 
host

hostname or ip address of the web service, e.g.

localhost

 port

port for which the web service is accessible, e.g.

4445
 path

path and query string of the web service URL, e.g.

/jobscheduler/agent/api/

 protocol

protocol in use including http, https

com.sos.jitl.restclient.JobSchedulerRestClient.postRestService
 execute the web service operation using POST
 host

hostname or ip address of the web service, e.g.

localhost

 port

port for which the web service is accessible, e.g.

4445
 path

path and query string of the web service URL, e.g.

/jobscheduler/agent/api/

 bodyThe body for the POST
com.sos.jitl.restclient.JobSchedulerRestClient.putRestService
 execute the web service operation using PUT
 host

hostname or ip address of the web service, e.g.

localhost

 port

port for which the web service is accessible, e.g.

4445
 path

path and query string of the web service URL, e.g.

/jobscheduler/agent/api/

 bodyThe body for the PUT
com.sos.jitl.restclient.JobSchedulerRestClient.setProxy set Http proxy without credentials
 proxyHosthostname or ip address of the http proxy
 proxyPortport of the http proxy
com.sos.jitl.restclient.JobSchedulerRestClient.setProxy set Http proxy with credentials if necessary
 proxyHost / proxyPortsee setProxy without credentials
 proxyUseruser of the http proxy if necessary
 proxyPassworduser's password of the http proxy if necessary

 

Adding Header items

  • The header "Accept=application/json" will automatically be added.
  • You can add header items with
    • com.sos.jitl.restclient.JobSchedulerRestClient.headers.put("header","value");

Integration with JavaScript

  • 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:

        Example for REST web service client processing a JSON response  Expand source
  • The web service returns an XML document:
    • The result can be parsed using the SOSXMLXPath Java class.
      • see example below

        Example for REST web service client processing an XML response  Expand source

Examples

Simple standalone Job with REST Client

  • 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 
     
Job rest_client  Expand source

Full standalone Job with GET|POST|PUT|DELETE and XML Responses

Job rest_client processing XML responses  Expand source

Full Job Chain with GET|POST|PUT|DELETE and JSON Responses

Download the example: rest_client.zip

Job: rest_client

Job rest_client processing JSON responses  Expand source

Job Chain: rest_client

Job Chain rest_client  Expand source

Orders: rest_client

Order rest_client_post_json  Expand source

Find additional orders for REST operations with the download of this example.

 

Example for HTTPS

  • We assume that a SSL certificate is imported in a Java truststore /path/to/java/myTruststore.jks
  • Please note that the REST client varify the hostname of the URL with the certificate
  •  Expand source

References

See also

Change Management References

Loading
T Key Linked Issues Fix Version/s Status P Summary Updated
Fix JITL-407 JITL-213 1.9.13, 1.10.9, 1.11.5, 1.12 Released Major Enable proxy settings in JITL REST client Nov 11, 2017
Fix JITL-272 JITL-213 1.9.8, 1.10.3, 1.11 Released Minor Enable POST and PUT commands with a body when calling REST Web Services Jan 06, 2016
Feature JITL-213 JITL-407 , JITL-272 1.9.8, 1.10.2, 1.11 Released Minor Enable Job scripts and Monitor scripts to use REST web services Oct 16, 2017

Documentation

  • REST (Representational State Transfer)

 

  • No labels