Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page describes how to write a custom task. To better illustrate the topic, we provide instructions based on the example.

...

In addition to the execute() method, it is also possible to make the class implement a JavaBean interface. The WSO2 ESB EI console can then be used to configure the properties of this JavaBean.

...

Info

When creating the customized schedule tasks, if the injecting sequence of the message flow contains Publish Event mediatorsmediators, set the following property in the Synapse message context:

mc.setProperty("CURRENT_TASK_EXECUTING_TENANT_IDENTIFIER",PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());

Also, add the following dependency to the POM file of the custom task project: WSO2 Carbon - Utilities bundle (symbolic name: org.wso2.carbon.utils)

...

Since a task implements ManagedLifecyle interface, ESB WSO2 EI will call the init() method at the initialization of a Task object and destroy() method when a Task object is destroyed:

...

In PlaceStockOrderTask it is stored the Synapse environment object reference in an instance variable for later use with the init() method. The SynapseEnvironment is needed to inject messages into the ESBWSO2 EI.

...

Step 2. Customize the Task
Anchor
Customizing a task
Customizing a task

It is possible to pass values to a task at run time runtime using property elements. In this example, the location of the stock order file and its address was given using two properties within the Task object.

...

When creating a Task object, WSO2 ESB EI will initialize the properties with the given values in the configuration file.

...

(OMElement comes from Apache AXIOM which is used by WSO2 ESBEI. AXIOM is an object model similar to DOM. To learn more about AXIOM, see the tutorial in the AXIOM user guide.) 

...

Assemble the compiled class Task as a JAR file.

...

Step 4. Add to the WSO2

...

EI Class Path
Anchor
Packaging the Custom Mediator
Packaging the Custom Mediator

After compiling and bundling the Task class, you need to add it to the WSO2 ESB EI class path. Place the JAR file to the repository/components/lib directory of the ESBWSO2 EI. The Task class will be available for use from the next time you start WSO2 ESBEI.

Info
titleNotice

It is required to restart the ESB WSO2 EI for the JAR containing the task implementation to be picked up by the server runtime. An OSGi bundle containing the task implementation will be created automatically and it will be deployed in the server.

...

Step 5. Configure and Schedule in

...

WSO2 EI console
Anchor
below
below

After adding the Task class to class path classpath and restarting the WSO2 ESBEI, you can add configuration settings using the ESB WSO2 EI console. Follow the steps given below (for the detailed information on how to schedule tasks see Adding and Scheduling Tasks):

1. Log in to the ESB into the WSO2 EI's management console.

2. Click the "Main" button to access the "Manage" menu.

...