Exposing Workflows (extending the Xyna API) - Xyna-Factory/xyna GitHub Wiki
Steps to expose a Workflow via HTTP REST
In order to expose custom Workflows via Xyna's REST interface to any northbound interface, the following steps are necessary:
Create a Trigger
Create a Trigger Instance using the existing HTTP Trigger, delivered with Xyna:
./xynafactory.sh deploytrigger -workspaceName <workspace name> -triggerName Http -triggerInstanceName <desired name of trigger instance> -startParameters port=<number of port>
Example
Below command would create trigger instance named "Http_OAS4220" which listens on the port number 4220. This trigger will be deployed in the same workspace as the workflow is deployed in:
./xynafactory.sh deploytrigger -workspaceName 'Webpage_Impl_WS' -triggerName Http -triggerInstanceName Http_OAS4220 -startParameters port=4220
Create a Filter
Create a Filter Instance using the existing HTTPForwarding Filter, delivered with Xyna:
./xynafactory.sh deployfilter -filterName HTTPForwardingFilter -workspaceName <workspace name> -triggerInstanceName <trigger instance name created in previous step> -filterInstanceName <filter instance name>
Remark: Filter Instances do not necessarily have to live in the same Runtime Context as their Trigger Instance.
Create a dispatcher Workflow
The dispatcher Workflow will be called by the new Filter Instance to handle the incoming requests. Follow the below steps to create such a Workflow.
Remark: The modeled Workflow has to be deployed in the same workspace in which the Trigger and Filter are deployed.
Use the Xyna Process Modeller to model the Workflow:
Define the input signature (do not change the order of parameters):
- URL-path (xact.http.URLPath)
- host (base.Host)
- Port (base.Port)
- Http Method (xact.http.enums.httpmethods.HTTPMethod)
- Header (xact.http.Header)
- Document (xact.templates.Document)
Define the output signature (do not change the order of parameters):
- Document (xact.templates.Document)
- Header (xact.http.Header)
- HTTP Status Code (xact.http.enums.statuscode.HTTPStatusCode)
Differentiate HTTP methods
To differentiate the HTTP request's method, add a Type Choice step, search for the HTTP Method
data type and drag it into the Type Choice’s header.
Once the Type Choice has been set the HTTP Method
, it will create all the supported HTTP methods like POST
, GET
, DELETE
, PUT
, PATCH
, OPTION`.
Convert the input into a Xyna Data Type
The Document input parameter contains the request as (JSON) text. Since we want to work with that data inside this Workflow, it has to be converted into Xyna Data Types. So in order to do that we need to add the Coded Service called Parse Object From JSON with Options
. Search for it and drag the service in place.
Perform business logic
Now it's time to perform the business logic to process the input data which the user/system has sent.
Send response
Since the response also needs to be sent as a JSON object, we need another Coded Service named Write JSON with Options
or Write JSON List with Options
. Use latter if you have a list of items to be sent as JSON response.
Link dispatcher Workflow
Create the Order Type in the Factory Manager, which maps the incoming requests to the dispatcher Workflow:
- Name of the Order Type:
xact.http.ProcessHTTPRequest.port=4220
(port value must be the value used for the Trigger Instance) - Execution Destination: Full qualified name of the dispatcher Workflow (the one created above)