Versions Compared

Key

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

...

  1. Write the Task class
  2. Customize the task
  3. Compile and bundle the task
  4. Add the task to the WSO2 ESB class path
  5. Configure and schedule the task in ESB Console

...

See Writing Tasks Sample to learn more information on how to write tasks in Java. You can also use JavaScript, Ruby, Groovy or other Apache BSF scripting languages for this purpose.
The custom Task class should implement org.apache.synapse.startup.Task. Each task should therefore implement the Task interface. This interface has a single execute() method. This method contains the code that is to be run at the specified intervals.

Code Block
package org.apache.synapse.task;

/*** Represents an executable Task*/

public interface Task {

   /*** Execute method will be invoked by the QuartzJOb.
   */
   public void execute();
}

The execute() method contains following actions:

...

It is possible to pass values to a task at run time using property elements. When creating a Task object, WSO2 ESB will initialize the properties with the given values in the configuration file. For those properties given as XML elements, properties need to be defined within the Task class using the following format:

Code Block

public void setMessage(_property_ elem) {
message = elem;}

It can be initialized with an XML element as follows:

Code Block

<property name="message">
<m0:getQuote xmlns:m0="http://services.samples/xsd">
<m0:request>
<m0:symbol>IBM</m0:symbol>
</m0:request>
</m0:getQuote>
</property>

Wiki Markup{Anchor:Compile and bundle the task} 

...

Step 3. Compile and bundle the task
Anchor
compile
compile

Assemble the compiled class Task as a JAR file.

...

For more information see http://wso2.org/library/2900.

Excerpt
hiddentrue

Instructions on how to write a custom task for WSO2 ESB.