Overview
In the Etlworks Integrator, you can use a memory Connection to parse the response from the web service.
Example
The typical use of this case is when you need to call a web service, parse the response, and (depending on the response) conditionally do something, like throw an exception.
For instance, the run Flow by name API can be used to execute the Flow configured in the Etlworks Integrator. It is possible to build a very complex workflow when the main Flow conditionally calls other Flows using this API. If the call that successfully went through the API endpoint returns HTTP 200 and a response in the JSON Format, it will look like this:
"flowId":123,
"messageUuid":"UUID of the message",
"auditId":"ID of the record in audit table",
"status":4,
"exception":"exception-stack-trace"
}
The status
can be one of the following:
0
: just started.1
: Flow is still running.2
: Flow has been canceled.3
: Flow has not been executed.4
: Flow executed successfully.5
: Flow executed with an error (exception).
Process
In this example, we will create a Flow that executes other Flows by name, reads the response, and throws an exception if the Flow called by name was executed with an error.
Step 1. Let's assume that we have already created a Flow called "the-transformation." This is the Flow we are going to be calling from the other Flow.
Step 2. Create a "caller" source-to-destination Flow, where the source is a web service, and the destination is a memory Connection. The source Connection is going to be an HTTP Connection pointed to the run Flow by name API (make sure that you are executing "the-transformation" Flow synchronously), and the source and destination Formats are going to be JSON.
Step 3. Add a JavaScript code to the Flow created in step 2, which will be parsing the response from the web service. Click MAPPING
and select Additional Transformations
. Paste the following JavaScript in the After Extract
field:
var status = dataSet.getFieldValue(dataSet.getRecord(0), 'status');
var exception = dataSet.getFieldValue(dataSet.getRecord(0), 'exception');
// error
if (status == 5) {
throw 'There was an exception when executing the flow:' + exception;
}
// still running
else if (status == 0 || status == 1) {
throw 'The flow is still running but expected to finish already';
}
// canceled
else if (status == 2) {
throw 'The flow has been canceled';
}
// has not been executed
else if (status == 3) {
throw 'The flow has not been executed';
}
Step 4. Save the caller Flow.
Now, when you call the caller Flow and "the-transformation," and the Flow finishes with an error, the caller will also throw an exception.
Comments
0 comments
Please sign in to leave a comment.