Page History
...
In order to reduce the overhead of REST client implementation a JavaScript class is suggested for simplified access to the JS7 REST Web Service by jobs.
JavaScript REST API Class
A JavaScript class is suggested that
- connects to JOC Cockpit and performs sign-in to JOC Cockpit for access to the JS7 REST Web Service API using
let api = new JS7RestApi(step)
- performs calls to the JS7 REST Web Service API from the method
post(path, body)
...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
class JS7RestApi {
_step = null;
_accessToken = null;
_apiExecutor = null;
constructor(step) {
this._step = step;
try {
this._apiExecutor = new com.sos.js7.job.jocapi.ApiExecutor(this._step.getLogger());
this._accessToken = this._apiExecutor.login().getAccessToken();
} catch (e) {
if (this._apiExecutor) {
if (this._accessToken) {
this._apiExecutor.logout(this._accessToken);
}
this._apiExecutor.close();
}
throw e;
}
}
destructor() {
if (this._apiExecutor) {
if (this._accessToken) {
this._apiExecutor.logout(this._accessToken);
}
this,_apiExecutor.close();
}
}
post(path, body) {
var response = this._apiExecutor.post(this._accessToken, path, body);
this._step.getLogger().debug('[post: response.getStatusCode] ' + response.getStatusCode());
this._step.getLogger().debug('[post: response.getResponseBody] ' + response.getResponseBody());
return response;
}
} |
...
Further Resources
Overview
Content Tools