Each workflow executor in the WSO2 API Manager is inherited from the
org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor abstract class, which has two abstract methods:
execute: contains the implementation of the workflow execution
complete: contains the implementation of the workflow completion
getWorkflowType: abstract method that returns the type of the workflow as a String
getWorkflowDetails(String workflowStatus): abstract method that returns a list of
WorkflowDTOobjects. This method is not used at the moment and it returns null for the time being.
To customize the default workflow extension, you override the
complete() methods with your custom implementation. For example, the following class is a sample implementation of the Subscription Creation workflow. It returns an email to an address provided through the configuration on each subscription creation:
Note the following regarding the above sample:
execute()method takes in a
WorkflowDTOobject (SubscriptionWorkflowDTO class) that contains information about the subscription that is being created.
emailPasswordare private String variables with public
settermethods. The values for these variables are populated through the server configuration.
- After sending the email, a call is made to the super class's
execute()method in order to create a reference entry in the database. This entry is generally used to look up the workflow when the workflow happens asynchronously (via a human approval).
- The complete() method contains the code to mark the subscription active. Until then, the subscription is in ON_HOLD state.
- In this sample, the
complete()method is called immediately to make the subscription active instantly. If the completion of your workflow happens asynchronously, you must not call the
complete()method from the
WorkflowExceptionis thrown to roll back the subscription in case of a failure.
In a distributed setup, the custom workflows should be deployed in the Store node.
After the implementation of the class is done, follow the steps below to implement the new workflow extension in the API Manager:
- Compile the class and export it as a JAR file. Make sure you have the following JARs in the classpath before compilation.
javax.mail.jar: see https://java.net/projects/javamail/pages/Home to download the JAR
- After exporting the JAR, copy it to
Log in to APIM management console (
https://<Server Host>:9443/carbon) and select Browse under Resources.
/_system/governance/apimgt/applicationdata/workflow-extensions.xmlresource, disable the Simple Workflow Executor and enable WS Workflow Executor. Also specify the service endpoint where the workflow engine is hosted and the credentials required to access the said service via basic authentication (i.e., username/password based authentication). For example:
Note that the
emailPasswordproperties will be assigned to the appropriate variables defined in the class through the public
settermethods of those variables.
If you use the same or similar sample to return an email, you must remove the
org.jaggeryjs.hostobjects.email_0.9.0.ALPHA4_wso2v1.jar file from
<API-M_HOME>/repository/components/plugins directory. Removing it results in a
ClassNotFoundException thrown at server startup, but it does not affect the server's functionality.