...
- The
execute()
method takes in aWorkflowDTO
object (SubscriptionWorkflowDTO class) that contains information about the subscription that is being created. - The
adminEmail
,emailAddress
andemailPassword
are private String variables with publicgetter
andsetter
methods. 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 thecomplete()
method from theexecute()
method. - The
WorkflowException
is thrown to roll back the subscription in case of a failure.
Info |
---|
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.
<AM<API-M_HOME>/repository/components/plugins/org.wso2.carbon.apimgt.impl_1.2.1.jar
<AM<API-M_HOME>/repository/components/plugins/org.wso2.carbon.apimgt.api_1.2.1.jar
javax.mail.jar
: see https://java.net/projects/javamail/pages/Home to download the JAR
- After exporting the JAR, copy it to
<AM<API-M_HOME>/repository/components/lib
. Log in to APIM management console (
https://<Server Host>:9443/carbon
) and select Browse under Resources.
Go to
/_system/governance/apimgt/applicationdata/workflow-extensions.xml
resource, 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:Code Block language xml <WorkFlowExtensions> ... <!--SubscriptionCreation executor="org.wso2.carbon.apimgt.impl.workflow.SubscriptionCreationSimpleWorkflowExecutor"/--> <SubscriptionCreation executor="org.wso2.sample.workflow.SubsCreationEmailSender"> <Property name="adminEmail">to_user@email.com</Property> <Property name="emailAddress">from _user@email.com</Property> <Property name="emailPassword">from_user_password</Property> </SubscriptionCreation> ... </WorkFlowExtensions>
Note that the
adminEmail
,emailAddress
andemailPassword
properties will be assigned to the appropriate variables defined in the class through the publicsetter
methods of those variables.
Note |
---|
If you use the same or similar sample to return an email, you must remove the |