Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: https://wso2.org/jira/browse/DOCUMENTATION-3848

...

  • The execute() method takes in a WorkflowDTO object (SubscriptionWorkflowDTO class) that contains information about the subscription that is being created.
  • The adminEmail, emailAddress and emailPassword are private String variables with public getter and setter 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 the complete() method from the execute() 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:

  1. 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
  2. After exporting the JAR, copy it to <AM<API-M_HOME>/repository/components/lib.
  3. Log in to APIM management console (https://<Server Host>:9443/carbon) and select Browse under Resources.
     

  4. 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
    languagexml
    <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 and emailPassword properties will be assigned to the appropriate variables defined in the class through the public setter methods of those variables.

Note

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 <AM<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.