WebLogic Server 6.0 Code Examples, BEA Systems, Inc.

Package examples.rmi_iiop.ejb.simplified_idl

This example demonstrates support for the connectivity between an EJB without valuetpes and a C++ client.

See:
          Description

Interface Summary
MyBean  
MyBeanHome  
 

Class Summary
MyBeanImpl  
 

Package examples.rmi_iiop.ejb.simplified_idl Description

This example demonstrates support for the connectivity between an EJB without valuetpes and a C++ client.

This example illustrates:

This example demonstrates connectivity between an EJB and a Corba/C++ client. It uses VisiBroker 4.0 for C++ with Microsoft VC++ 6.0 compiler. It uses a stateless session EJB called MyBean and presumes some knowledge of EJB deployment. For examples pertaining stricly to EJBs, please see our EJB examples page. Included there is a stateless session bean similar to MyBean.

To get the most out of this example, first read through the source code files to see what is happening. Start with the XML deployment files to find the general structure of the EJBean, i.e. which classes are used for the different objects and interfaces, then examine the other files to see how the application works.

The following section describes how to build and run the example:

  1. Build the example
  2. Configure the server
  3. Run the example

Build the example

  1. Set up your development shell as described in Setting up your environment.

  2. Note: Edit the variable VISIBROKER_HOME in the build script provided for this example in the samples\examples\rmi_iiop\ejb\simplified_idl directory for your VisiBroker for C++ installation.

  3. Execute the build script provided for this example in the samples\examples\rmi_iiop\ejb\simplified_idl directory of your WebLogic Server installation. The script will perform the following steps:

    1. Set the variables as shown in this example for Windows NT/2000:

      $ set VISIBROKER_HOME=c:\Inprise\vbroker

      $ set IDL2CPP=%VISIBROKER_HOME%\bin\idl2cpp -no_servant -idl_strict
      where:
      c:\Inprise\vbroker
      Visibroker for C++ installation directory.

    2. Create the build directory, and copy the deployment descriptors into it as shown in this example for Windows NT/2000:

      $ mkdir build build\META-INF build\images cpp\javax cpp\javax\ejb

      $ copy *.xml build\META-INF

      $ copy *.gif build\images

    3. Compile EJB classes into the build directory (jar preparation) as shown in this example for Windows NT/2000:

      $ javac -d build MyBean.java MyBeanHome.java MyBeanImpl.java

    4. Make a EJB jar file, including XML deployment descriptors as shown in this example for Windows NT/2000:

      $ cd build

      $ jar cv0f std_simple_ejb_idl.jar META-INF examples images

      $ cd ..

    5. Run EJBc to create the deployable jar file as shown in this example for Windows NT/2000:

      $ java weblogic.ejbc -compiler javac -idl -idlNoValueTypes -idlOverwrite -idlDirectory idlSources -iiop build\std_simple_ejb_idl.jar %APPLICATIONS%\simple_ejb_idl.jar

    6. Run idl2cpp to create C++ sources as shown in this example for Windows NT/2000:

      $ %IDL2CPP% -I%VISIBROKER_HOME%\idl -IidlSources -namespace -Iidl -src_suffix cpp -root_dir . idlSources\examples\rmi_iiop\ejb\simplified_idl\MyBean.idl

      $ %IDL2CPP% -I%VISIBROKER_HOME%\idl -IidlSources -namespace -Iidl -src_suffix cpp -root_dir . idlSources\examples\rmi_iiop\ejb\simplified_idl\MyBeanHome.idl

      $ %IDL2CPP% -I%VISIBROKER_HOME%\idl -IidlSources -namespace -Iidl -src_suffix cpp -root_dir cpp\javax\ejb idlSources\javax\ejb\EJBObject.idl

      $ %IDL2CPP% -I%VISIBROKER_HOME%\idl -IidlSources -namespace -Iidl -src_suffix cpp -root_dir cpp\javax\ejb idlSources\javax\ejb\EJBHome.idl

      $ %IDL2CPP% -I%VISIBROKER_HOME%\idl -IidlSources -namespace -Iidl -src_suffix cpp -root_dir cpp\javax\ejb idlSources\javax\ejb\RemoveEx.idl

      $ %IDL2CPP% -I%VISIBROKER_HOME%\idl -IidlSources -namespace -Iidl -src_suffix cpp -root_dir cpp\javax\ejb idlSources\javax\ejb\CreateEx.idl

      $ %IDL2CPP% -I%VISIBROKER_HOME%\idl -IidlSources -namespace -Iidl -src_suffix cpp -root_dir cpp\java\lang idlSources\java\lang\_Object.idl

      $ %IDL2CPP% -I%VISIBROKER_HOME%\idl -IidlSources -namespace -Iidl -src_suffix cpp -root_dir cpp\java\rmi idlSources\java\rmi\Remote.idl

    7. Compile the c++ stubs and client file as shown in this example for Windows NT/2000:

      $ CL /MD /DTHREAD /nologo -DWIN32 /GX /DSTRICT /DALIGNED /DVISIBROKER /DMSVCUSING_BUG /DMSVCNESTEDUSING_BUG
              -Icpp -I%VISIBROKER_HOME%\include -I%VISIBROKER_HOME%\include\stubs -I%WL_HOME%\samples -c MyBean_c.cpp  MyBeanHome_c.cpp cpp\Client.cpp
              cpp\javax\ejb\EJBObject_c.cpp cpp\javax\ejb\EJBHome_c.cpp cpp\javax\ejb\RemoveEx_c.cpp cpp\java\lang\_Object_c.cpp cpp\java\rmi\Remote_c.cpp

    8. Generate the client executable as shown in this example for Windows NT/2000:

      $ LINK /nologo /out:Client.exe /LIBPATH:%VISIBROKER_HOME%\lib MyBean_c.obj MyBeanHome_c.obj EJBObject_c.obj EJBHome_c.obj
              RemoveEx_c.obj _Object_c.obj Remote_c.obj Client.obj

  4. Note: Running the build script places the EJB in %WL_HOME%\config\examples\applications directory, where it automatically deploys once the server is started. If you are already running the server and build another EJB, it is automatically placed in this directory and instantly deployed.

    Additional information on using the build scripts is found in Building Enterprise JavaBean examples

Configure the server

  1. Start the server with the examples configuration.

  2. Make sure that the EJB has been deployed on your examplesServer.

  3. Bring up the Administration Console in your browser.

    1. Click to expand the Deployments node in the left-hand pane.
    2. Click to expand the EJB node in the left-hand pane.
    3. Select the simple_ejb_idl node.
    4. Select the Targets tab in the right-hand pane to display the Available and Chosen targets.
    5. Deploy the simple_ejb_idl on the examplesServer.

Run the example

  1. Open a new command shell.

  2. Set the CLASSPATH as shown in this example for Windows NT/2000:

    $ set CLASSPATH=%CLASSPATH%;%WL_HOME%\config\examples\applications\simple_ejb_idl.jar
    where WL_HOME is the installation directory for WebLogic Server.

    Obtain the WebLogic Server Inter-operable Object Reference (IOR) by running the host2ior utility in the command shell as shown in this example for Windows NT/2000:

    $ java utils.host2ior hostname port
    where:
    hostname
    Host name of the WebLogic Server
    port
    Port where the WebLogic Server is listening for connections (weblogic.system.ListenPort).

  3. Run the client by entering the following command as shown in this example for Windows NT/2000:

    $ Client ServerIOR
    where ServerIOR is the IOR you obtained by running the host2ior utility.

  4. You should get output similar to this from the client application:

    Client output:
    
    Buying 100 shares
    Buying 200 shares
    Buying 300 shares
    Buying 400 shares
    Buying 500 shares
    Buying 600 shares
    Buying 700 shares
    Buying 800 shares
    Buying 900 shares
    Buying 1000 shares
    
    This is the server output:
    
    Buying 100 shares
    Attempt to buy 200 is greater than limit of 100
    Buying 100 shares
    Attempt to buy 300 is greater than limit of 100
    Buying 100 shares
    Attempt to buy 400 is greater than limit of 100
    Buying 100 shares
    Attempt to buy 500 is greater than limit of 100
    Buying 100 shares
    Attempt to buy 600 is greater than limit of 100
    Buying 100 shares
    Attempt to buy 700 is greater than limit of 100
    Buying 100 shares
    Attempt to buy 800 is greater than limit of 100
    Buying 100 shares
    Attempt to buy 900 is greater than limit of 100
    Buying 100 shares
    Attempt to buy 1000 is greater than limit of 100
    Buying 100 shares

    Notice that when the trading limit of 100 shares was exceeded in Transaction 2, the actual sale was reduced to the limit. The change in the cash account must be maintained across all the transactions by the Client.

There's more...

Read more about WebLogic RMI over IIOP in the Developer Guide, Using WebLogic RMI over IIOP.

Read more about WebLogic EJB in the Developer Guide, BEA WebLogic Server Enterprise JavaBeans.

Read more about WebLogic RMI in the Developer Guide, Using WebLogic RMI.


Documentation is available at
http://e-docs.bea.com/wls/docs60

Copyright © 2000 BEA Systems, Inc. All Rights Reserved.