This entry guides you through the steps on calling a Job via the REST API. In this example, we are using HTTP POST as an example.
- The sample Job used in this example (i.e. render.job):
- A simple job to render a report.
- In addition, the report requires a parameter to be sent in.
-
Create a new Java class.
(For example, triggerJob.java) -
In triggerJob.java, declare the jobPath and the generated API token.
//declare String URL
String jobPath = "/hkp/render.job";
String token = "&elx.token=eno:api-d3a58949deb985612b565dff1d2472f0";
String url = "http://localhost:8080/elx/do/eno/jo"+jobPath+"?mode=run"+token;
- Next, add the request parameters.
(i.e.“Staff Name”=“Jasmine Chen” )
//add request parameter, form parameters
List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair("Staff Name", "Jasmine Chen"));
- Next, add the following line of codes to send the POST request.
//send POST request
HttpPost post = new HttpPost(url);
post.setEntity(new UrlEncodedFormEntity(urlParameters));
- Lastly, add the following line of codes to print request status and header info to console.
try (CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = httpClient.execute(post)) {
//Print request status and header info to console
System.out.println("Status returned : "+response.getStatusLine());
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
System.out.println(header.getName()+ ": " + header.getValue());
}
}
-
Upon execution of codes, you would be able to see the following in the console:
-
For the report template output, depending on how “Target” is configured, you would be able to view the output based on the respective configuration.
For example,
- If Target is configured at “userhome”, output will be found in the specific user’s home directory.
Full Java Code Sample & Sample Job used above can be found here (1.5 KB).