Invoking webMethods Services From an EJB

Overview

In addition to creating services with Adapter for EJB that enable you to invoke methods on EJBs deployed on an application server, you can also invoke services on IBM webMethods Integration Server (IS) from an EJB. The IS services invoked can be any service available on Integration Server. This model does not interact with Adapter for EJB, although an EJB developer could use this functionality to invoke an adapter service created by Adapter for EJB.

To demonstrate this functionality, you should work with the following components:

  • Sample EJB application (available for download on the IBM TechXchange Community)
  • Sample webMethods Java service (provided with the adapter)
  • webMethods APIs (packaged with Integration Server)

Through the APIs, an EJB may establish an HTTP connection to Integration Server and instruct it to execute a particular service. Upon completion, the service results are returned to the EJB. Upon receiving the results, you can have the EJB, process this information, to suit its needs. Inputs to and outputs from the service are passed using webMethods proprietary IData objects. Included in the API used by the EJB are tools for creating and manipulating IData instances. This interaction is logically depicted in the following diagram.

The following sections describe each of these components and explain how an EJB developer might implement code that invokes services on Integration Server.

Sample EJB Application

To use the sample EJB application, download it from the IBM TechXchange Community and extract the downloaded zip file to the Integration Server_directory\packages\WmEJBAdapter\templates\EJBToWebmSamples directory. The sample EJB application contains EJB source code that demonstrates the procedure for invoking services running on Integration Server from within an EJB. The sample EJB application must be installed on your application server in order to demonstrate this facility.

The sample EJB application includes the following files:

  • Source code for a simple stateless session EJB (HelloBean) that talks to a simple stand-alone Java service that is part of the adapter (see Sample webMethods Java Service).
  • EJB deployment descriptor files for the HelloBean EJB, one set for each supported application server.
  • Source code for a simple EJB client (HelloEJBClient) designed to run on the application server and used to invoke HelloBean.
  • JNDI properties file needed by HelloEJBClient, one for each supported application server.
  • Ant build scripts used to compile HelloBean and HelloEJBClient, deploy HelloBean, and run HelloEJBClient. There is one build script for each supported application server.
  • Readme file describing how to build the sample EJB and the EJB client, deploy the sample EJB, and run the EJB client. There is one readme file for each supported application server (ReadMeappserver.txt).

Sample webMethods Java Service

The sample testEJBToWebm service is a standalone Java service and built in to Adapter for EJB. The service appears in the IS namespace as pub.ejbadapter.testEJBToWebm.

The HelloBean sample EJB will attempt to invoke testEJBToWebm. The testEJBToWebmservice simply echoes the string sent by the sample EJB back to the pipeline.

webMethods APIs

The sample EJB uses the webMethods APIs to establish communications with Integration Server and subsequently interact with the testEJBToWebm Java service. The webMethods APIs are available in the packages com.wm.app.b2b.client and com.wm.data, which can be found in the following file:

Integration Server_directory\lib\client.jar

  • The com.wm.app.b2b.client package contains classes that you use to build clients for Integration Server (including clients that use the guaranteed-delivery facility).
  • The com.wm.data package contains classes that you use create and manipulate IData objects.

Documentation for these classes is available in the online help in the Integration Server_directory\doc\api\Java directory.

Running the Sample EJB

About this task

Use the sample EJB application to see how to implement the logic in your code to invoke IS services from an EJB.

To run the sample EJB, follow the instructions in the ReadMeappserver.txt file in the EJBToWebmSamples folder that tells you how to find the client.jar and how to build and deploy the sample EJB code on your application server.

Basic Flow of Events

About this task

Note: The EJB must have access to the client jar file containing classes needed to engage in a request-response dialogue with Integration Server.

At a high level, the steps to invoking an IS service from an EJB are as follows:

Procedure

  1. On the application server, create and deploy an EJB that uses the webMethods APIs in client.jar for the purpose of executing a service on Integration Server.
  2. The EJB creates a context (connection) with Integration Server, providing a URL, user name, and password.
  3. The EJB constructs an IData pipeline, if necessary, inserting appropriate service input values.
  4. The EJB posts to Integration Server a request containing a valid service name and the pipeline constructed in step 3.
  5. The EJB receives a response from Integration Server and uses the provided APIs to access and process the values contained in the returned IData pipeline.
  6. The EJB successfully receives and processes the desired results from the service it executed.