An enterprise bean hosted by WebSphere Application Server can act
as a client to a CORBA server on a third-party ORB. The enterprise bean itself
is written like any other enterprise bean. It must implement the required
methods in the usual home and remote interfaces so that its clients can contact
it. The remote interface defines the business methods of the bean, and all
of the work related to using the CORBA server occurs in the implementation
of those methods. The use of a CORBA server does not change the usual programming
tasks associated with enterprise beans, but the code in the remote methods
must include code for communicating with the server. This includes code for
the following:
- Getting a reference to the client-side ORB, which is needed for communicating
with the servant objects
- Looking up the servant objects
- Calling the methods in the CORBA IDL interface betwen the enterprise bean
and the server
In the sample application, the enterprise bean that acts as a client
of the CORBA server is written as a stateless session bean. The writing such
an enterprise bean can be divided logically into two pieces:
- Writing the usual parts of an enterprise bean:
- The home interface: In the enterprise bean described here, this interface
consists of a single create method.
- The remote interface: In the bean described here, this interface consists
of methods that initiate the interoperability tests. These methods are called
by the client of the enterprise bean to run a suite of interoperability tests.
Of primary interest are the following methods:
- setOrbProperties: This method obtains a reference to the client-side ORB
and sets necessary properties.
- testNameService: This method attempts to locate the servant objects either
by contacting the name service directoy and looking up the server, by re-creating
the name-service IOR from the file that the server writes and looking up the
servant objects, or by re-creating the servant-object IORs from the files
that the server writes and contacting the objects directly. (The specific
test that is run is determined by a mode variable.)
- testPrimitive: This method connects to the servant object, starts a loop,
and runs through the methods in the Primitive interface.
- testComplex: This method connects to the servant object, starts a loop,
and runs through the methods in the Complex interface. (This method is structurally
identical to the testPrimitive method and is not discussed in detail.)
These methods make use of other methods designed to support the interaction
with the CORBA server.
- The bean class: This is the class in which the methods required by the
home and remote interfaces are implemented. It can also contain methods used
internally by the home and remote methods.
- Writing the code to support the interaction with the CORBA server. This
code is called from the methods in the remote interface and is the primary
object of this discussion. In general, the types of things this code must
do include: