WorkflowEJBBean.java

Abstract This example contains sample source code for an Enterprise Java Bean invoking MQWF API calls.
This example shows ...
  • How an EJB can implement API calls in WebSphere and how to call the EJB from a remote client program.
You can use this example ...
  • As a design pattern for your own EJB implementation.
Minimum MQWF version required
  • V3.4.0
Other required products
  • WebSphere Application Server Version 5 or any other J2EE 1.3 Application Server.  
Description

This sample contains the definition of a Session Bean that implements a small subset of the MQWF Java programming interface.
A remote client program demonstrates how to look up the bean's interface, create a bean instance, invoke its methods and process the result.

The focus of this sample is to demonstrate how to use object wrapper classes to transport API objects to the client and how to use stateless API calls to implement a production ready multi-user multi-threaded EJB environment. 

Setup

This sample was developed with WebSphere Studio Version 5 and tested with Websphere Application Server Version 5 on Windows 2000. The following setup steps are for this environment, however the Java code does not depend on this operating system or EJB container. It adheres to the EJB 2.0 standards.

To prepare the sample, perform the following steps:

  1. Install and configure IBM WebSphere MQ Workflow and IBM WebSphere Application Server.
  2. Package the files WorkflowEJB.java and WorkflowEJBBean.java into a stateless Enterprise Java Bean. For simplicity, this sample assumes that the EJB client classes are packaged into the same jar file. So you must also package the files EJBTestClient.java, ServiceWrapper.java, ProcessTemplateWrapper.java, ProcessInstanceWrapper.java and WorkItemWrapper.java into the bean project.
    To do this in IBM WebSphere Studio, perform the following:
    1. Create a new EJB project.
    2. Create 2.0 Stateless Enterprise Session Bean WorkflowEJB in the new project.
    3. Import the java source code into the packages com.ibm.workflow.api.smp.EJB and com.ibm.workflow.api.smp.EJB.client.
    4. Generate the deploy and RMIC code and export the enterprise application as an ear file containing all the required EJB interface classes, deployment descriptor and META-INF files.
  3. Deploy the resulting ear file in WebSphere Application Server. If you have Java2 security enabled the sample will need the following security permissions:
    • When using the MQWF Classic Java API classes:
      grant codeBase "file:${application}" {
           permission java.lang.RuntimePermission "loadLibrary.fmcojprf";
           permission java.util.PropertyPermission "java.execsuffix", "read";
           permission java.util.PropertyPermission "user.dir", "read";
           permission java.lang.RuntimePermission "loadLibrary.fmcojloc";
           permission java.lang.RuntimePermission "loadLibrary.fmcojiop";
      };
    • When using the MQWF Native Java API classes:
           permission java.io.FilePermission "fmcrc", "read";
           permission java.io.FilePermission "${app.installed.path}/fmcjapi.jar", "read"; 
           permission java.io.FilePermission "fmctrc.log", "write";
  4. Ensure that the EJB application has access to the MQWF Java API classes. If you have configured and deployed the Web Client your Application Server will already have global access to the API classes.

To prepare the EJB client code, perform the following steps:

  1. Edit the file EJBInvocation.properties and customize it for your environment.
    It contains default values for the EJB lookup function and for the workflow client logon.
  2. Export the class files of the packages com.ibm.workflow.api.smp.EJB and com.ibm.workflow.api.smp.EJB.client as a jar file (alternatively you can export this jar file from the exported enterprise application ear file). Place this jar file into directory EJBInvocation. 
  3. On Windows operating systems edit and customize the file startclient.cmd to your environment. It contains classpath settings that your client code requires during compile and runtime.
  4. On all other operating systems, create a script file similar to startclient.cmd to start the client program.
Running the sample To run the sample, perform the following steps:
  1. Start the WebSphere Application Server and ensure that your EJB application is running. 
  2. Run startclient.cmd. The sample client program logs on, queries the process templates, creates a process instance, queries the process instances and workitems, deletes the process instances and finally logs off. 
  3. Problems during start of the EJB or during running of the client will be printed to the WebSphere console log file SystemOut.log.
View source code

 

WorkflowEJBBean.java
WorkflowEJBBean.html (Javadoc)

EJBTestClient.java
ServiceWrapper.java
ProcessTemplateWrapper.java
ProcessInstanceWrapper.java
WorkItemWrapper.java


[ Back to Java index ]