Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Invoking a service from a task API event handler in WebSphere Process Server V7

Samir Nasser (snasser@us.ibm.com), Senior Managing Consultant, Certified IT Specialist, IBM
Photo of Samir Nasser
Samir Nasser is a Senior Managing Consultant and Certified IT Specialist with the IBM Software Services for WebSphere team in Durham, North Carolina. He is currently architecting and developing SOA solutions based on the WebSphere family of products.

Summary:  WebSphere® Process Server supports different types of human tasks. Each task type has a lifecycle with well-defined states, which emit events to signal the occurrence of such states. This tutorial shows how to create a task API event handler and how to invoke a service from the handler.

Date:  28 Sep 2011
Level:  Intermediate PDF:  A4 and Letter (292 KB | 10 pages)Get Adobe® Reader®

Activity:  12727 views
Comments:  

Creating the task API event handler

Follow these steps to create the task API event handler:

  1. Create a Java project and add the Process Server runtime library to it. The tutorial creates the Java project Task Event Handler.
  2. Create an optional, but recommended, Java package in the src folder. If the package is not created, the default package is used (as is done in the tutorial).
  3. Create a Java class that extends the com.ibm.task.spi.APIEventHandler class. You have the option to create a handler that implements the APIEventHandlerPlugin5 interface. However, extending the APIEventHandler class is recommended because if there is any future change in the task API with future product releases, APIEventHandler of the new release will provide a default (do nothing) implementation of the various declared methods in the APIEventHandlerPlugin5 interface or potentially other interfaces.
  4. Override the appropriate methods of the APIEventHandler class. Which method is overridden depends on the business requirements. The tutorial overrides the preCreateTask and postCreateTask methods.

Listing 1 shows the preCreateTask method of the TaskEventHandler plug-in.


Listing 1. The preCreateTask method
public void preCreateTask(TaskModel newTaskModel, TaskTemplate template, 
 Serializable inputMessage, ReplyHandler replyHandler) throws ApplicationVetoException {
	ServiceManager serviceManager = new ServiceManager();
	Service myService = (Service) serviceManager.locateService("MyServiceIntPartner");
	myService.invoke("getIt", "preCreateTask method is executed.");
}

This is a simple implementation of the preCreateTask method. The task container of Process Server executes this method in the context of the Java EE application that represents the logic implemented in the MyProcess SCA project before the task is created. This implementation shows how to invoke a service that is located in the MyService SCA module, which is a different SCA module from MyProcess. To invoke the service in the MyService module, the preCreateTask method:

  1. Gets a reference to the singleton service ServiceManager as shown in the ServiceManager serviceManager… line.
  2. Looks up the service MyServiceIntPartner as shown in the Service myService… line. MyServiceIntPartner is the service reference that points to the Java component exposed as an SCA service in the MyService project.
  3. Invokes the method getIt of the MyServiceIntPartner service reference as shown in the myService.invoke… line.

The task API event handler TaskEventHandler is configured as a Java EE service provider. To configure it, follow these steps:

  1. Create the META-INF/services folder in the root of the Task Event Handler project.
  2. Create a text file called com.ibm.task.spi.plug-inNameAPIEventHandlerPlugin in the META-INF/services folder. Replace plug-inName with an arbitrary text that may appropriately be your event handler class name. For the tutorial, the event handler class name is TaskEventHandler.
  3. Type the fully qualified name of the plug-in name (package.name) in the first line of the text file. For the tutorial, the default package is used. So, the first line in the text file is TaskEventHandler.
  4. Save the text file com.ibm.task.spi.plug-inNameAPIEventHandlerPlugin.

4 of 11 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Business process management, WebSphere
ArticleID=762324
TutorialTitle=Invoking a service from a task API event handler in WebSphere Process Server V7
publish-date=09282011
author1-email=snasser@us.ibm.com
author1-email-cc=dwu@us.ibm.com