Running the adapter to invoke sample business objects

The following topics describe running the sample files delivered with the product and provide examples that illustrate how the connector invokes the services of a JAR file to create business objects.

Running the sample files

The sample files are located in the ProductDir\connectors\EJB\samples directory, where ProductDir represents the directory where the connector is installed.

It is a requirement that the WebSphere Application Server Thin Client must be installed for the adapter to remotely access the beans deployed on the server.

Note:
The Application Server Thin client cannot be installed to a directory that has spaces in its name.

The sample files illustrate a simple session bean, MusicCart, that provides a home interface, remote interface, bean and two helper classes, RecordingHelper and CustomerHelper. The sample files also include two connector configuration files: BIA_EJBConnector.cfg, which contains the connector properties settings for the example to run properly; and BIA_PortConnector.cfg, which contains the connector properties for the test connector.

The MusicCart sample bean has methods that take a Java object as an input parameter and return an object as output. It also has methods that take an object array as an input, illustrating how the adapter handles array management. The sample also demonstrates how the adapter performs data handler processing.

Included in the sample files is a business object file (BIA_SampleMusicCartBO.bo) and EJB source files (in ProductDir\connectors\EJB\samples\SampleMusicCartEJB\src), which show how EJB remote and home classes are mapped to business objects using the ODA for EJB. By sending BIA_SampleMusicCartBO.bo from the test connector to the application server, you can see how the addRecording, getFirstRecordInfo, modifyMusicRequestUsingDataHandler, and getAllRecordInfo methods are executed and how the connector handles request processing.

The following steps assume that you are running the connector to exchange business objects with enterprise beans deployed on WebSphere Application Server 5.0.

  1. Install the adapter for EJB as described in Installing the adapter.
  2. Deploy the EJB JAR file ProductDir\connectors\EJB\samples\ SampleMusicCartEJB\BIA_MusicBeanSample.jar to your instance of WebSphere Application Server 5.0.
  3. Load the two connector configuration files in the ProductDir\connectors\EJB\samples\ directory (BIA_EJBConnector.cfg and BIA_PortConnector.cfg) into the repository of your integration broker, for example InterChange Server.
  4. Load the sample business objects from the ProductDir\connectors\EJB\samples\SampleBOs directory into the broker repository.
  5. Modify the connector startup file to point to the location of the JAR file (BIA_MusicBeanSample.jar) you deployed in Step 2. For information about editing the startup file, see Configuring the startup file.
  6. In the startup file, uncomment the commands for your application server settings. For this sample, you must uncomment the commands for WebSphere Application Server, since this sample assumes you are running the connector to exchange business objects with enterprise beans deployed on WebSphere Application Server 5.0.
  7. Start the WebSphere Application Server instance.
  8. Start running the connector, as described in Starting the connector.
  9. Send the file BIA_SampleMusicCartBO.bo from the test connector to the application server.

As the connector runs, you can observe how the enterprise bean methods defined in the sample files are executed from the adapter to invoke services provided by the remote WebSphere Application Server.

EJB JAR file code

The following sample code is an excerpt from the EJB JAR file that defines the methods of the EJB class called MusicCartBean. Notice the method defined at the end of the code sample: getCustomer.

Note:
Not all of the methods for this class are defined in the code sample provided here. The sample is a section of a larger file described in Running the sample files.

The business object that corresponds to this code is illustrated in Figure 4.

public class MusicCartBean implements SessionBean {
  CustomerHelper customerHelper;
  ArrayList shoppingList;
  RecordingHelper[] recordHelperArr;


   // EJB Methods
   public void ejbRemove() {}
   public void ejbActivate() {}
   public void ejbPassivate() {}
   public void setSessionContext (SessionContext ctx) {}

  public void ejbCreate(String person,String password, String email)
      throws CreateException {
           if (person == null || person.equals("")) {
             throw new CreateException(
               "Name cannot be null or empty.");
           }
           else {
             customerHelper = new
               CustomerHelper(person, password, email);
             customerHelper.setName(person);
             customerHelper.setEmail(email);
             customerHelper.setPassword(password);
           }
           shoppingList = new ArrayList();
  }

   public void ejbCreate(CustomerHelper customerHelper)
      throws CreateException {
          customerHelper.setName(customerHelper.name);
          customerHelper.setEmail(customerHelper.email);
          customerHelper.setPassword(customerHelper.password);
          shoppingList = new ArrayList();
  }
   // Business methods implementation

  public CustomerHelper getCustomer() {
      return customerHelper;
  }

Business object sample

The following sample screen illustrates the business object structure that corresponds to the source code presented in EJB JAR file code. This business object is created by the ODA, which discovers the objects and constructs defined in the original EJB JAR file and generates corresponding business objects. For information about how to use the ODA to generate this example, see Creating and modifying business objects.

Notice the fourth attribute, getCustomer. This attribute contains a complex method object that corresponds to the getCustomer method defined at the end of the sample code for the MusicCartBean class, presented in EJB JAR file code.

Figure 4. Business object level ASI and supported verbs

Copyright IBM Corporation 2003, 2005. All Rights Reserved.