![]() |
RMI_IIOP_C++_CLIENT Sample Application |
RMI IIOP C++ Client Sample Application
This document describes how to utilize the RMI IIOP C++ Client sample application in conjunction with Sun ONE Application Server version 7.This sample application document contains the following sections:
Overview
Compiling and Assembling the Application
Deploying the Sample Application
Overview
This application is a simplified version of a Shopping Cart to demonstrate how a C++ IIOP client can access a Stateful Session Bean such as a Shopping Cart. The Shopping Cart Bean defined in this sample is a Shopping Cart for Books. A client can create the cart, and then add books to the cart, remove books from the cart and list the contents of the cart. For simplicity, other typical cart operations such as checkout etc., have been omitted in the Cart interface.This sample works with ORBacus 4.1.1 ORB from IONA technologies. The installation of ORBacus 4.1.1 on the machine where the client is intended to run is a prerequisite for running this sample.
Refer to iAS 70 Programmers guide for details on how to develop C++ clients accessing EJBs.
Compiling and Assembling the Application
Note that these steps only build the J2EE application. The actual building of C++ client is described under Running the Sample Application.To easily recompile, assemble and deploy the application, see the Sample Application Build Facility document for details on using a build facility to quickly perform these tasks.
For example, to rebuild the entire application from scratch, follow these steps:
Compile and Assemble Web Application. For example:
Deploy the application.
- Execute asant under APPSERV_INSTALDIR/samples/rmi-iiop/cpp/src/
- The default target core will be executed to rebuild the EAR file.
- This step builds the BookCartApp.ear which can be found under APPSERV_INSTALDIR/samples/rmi-iiop/cpp/assemble/ear.
To clean the web application project area, execute asant clean.
- Once you have re-created the sample application from scratch proceed to Deploying the Sample Application.
Deploying the Sample Application
Deploy the Web Application. For example:
The default target core will be executed to rebuild the EAR file.
- Execute asant deploy under APPSERV_INSTALDIR/samples/rmi-iiop/cpp/src/
Re-start the application server instance.
The deployment process involves the following operations:
Authenticates against the local application server's administrative server
If you would like to verify the registration of the application, proceed to Verifying Registration. Otherwise, you're ready to exercise the application by Running the Sample Application.
Verifying Registration
As an optional step, you can use the Sun ONE Application Server Administration Tool to verify that the application has been registered. If you do not want to verify that the application has been registered, proceed directly to Running the Sample Application.To verify the registration of the application, execute asadmin to look at applications deployed with a server instance. For example:
asadmin list-components -u <username> -w <password> -H <host> - <admin-port> <server instance name>
You will see the cppcart app as one of the listed applications.
Running the Sample Application
This sample demonstrates a C++ IIOP client that accesses the Cart EJB. The C++ client has to be built separately. The steps are listed below. The pre-requisite for this step is to Build and Deploy the BookCartApp EAR file in AppServer and start AppServer Instance.
Please download and Install ORBacus 4.1.1 from the orbacus website at http://www.orbacus.com or from the ORBacus Installation CD.
If you are having trouble in setting up ORBacus, please read the detailed instructions in ORBacus Instructions section and for further help go to http://www.orbacus.com or contact ORBacus Support.
Edit APPSERV_INSTALDIR/samples/rmi-iiop/cpp/src/client/make/cpp_def.mk.
Set the environment variable OB_INSTDIR to the root directory of ORBacus installation and please make sure that the idl compiler is available in $(OB_INSTDIR)/bin/.
Include path to the gmake tool in the PATH environment variable. For example: export PATH=<path to gmake>:$PATH.
Execute gmake from APPSERV_INSTALDIR/samples/rmi-iiop/cpp/src/client/. This will build all the c++ files and generate the binary client in APPSERV_INSTALDIR/samples/rmi-iiop/cpp/src/client/samples/rmi_iiop/cpp/ejb/SunOS5.8_DBG.OBJ directory. If the build is an optimized build (gmake BUILD_DEBUG=optimize all), then the client executable will be created in the directory APPSERV_INSTALDIR/samples/rmi-iiop/cpp/src/client/samples/rmi_iiop/cpp/ejb/SunOS5.8_OPT.OBJ/.
- Set the macro SUNWSPRO_DIR_61 to the WorkShop installation directory in the file APPSERV_INSTALDIR/samples/rmi-iiop/cpp/src/client/make/defines_SPARC_SOLARIS.mk.
- For example: SUNWSPRO_DIR_61 = /usr/dist/share/forte_dev/SUNWspro.
Set the path to libraries of ORBacus in LD_LIBRARY_PATH. For example:
Run the client using the following the command client:
- export LD_LIBRARY_PATH=<orbacus_install_dir>/lib.
You will see the following Output.
- -ORBInitRef NameService=corbaloc:iiop:<hostname>:<port number>/NameService (The Default Port is 3700).
Output
> client -ORBInitRef NameService=corbaloc:iiop:lego1:3700/NameServiceCart Client: Registering ValueFactories with ORB
Cart Client: Obtaining Reference to NameService of IAS
Cart Client: Looking up the Cart Home reference "ejb/CartEJB"
Cart Client: Narrowing the received object to CartHome
Cart Client: Narrowed CartHome...
Cart Client: Calling Create on Cart Home
Cart Client: Cart Created .....
Cart Client: Adding Book Titles to the Cart
Cart Client: Added Book Title 1: The Martian Chronicles
Cart Client: Added Book Title 2: 2001 A Space Odyssey
Cart Client: Added Book Title 3: The Left Hand of Darkness
Cart Client: Listing the Cart Contents
------------------------------------
Title[1]: The Martian Chronicles
Title[2]: 2001 A Space Odyssey
Title[3]: The Left Hand of Darkness
------------------------------------
Cart Client: Calling cart->removeBook(title) with invalid Title
Cart Client: This should result in a BookException being Thrown
Cart Client: Caught BookException: User exception `samples::rmi_iiop::cpp::ejb::
Possible Cause : Invalid BookName given to Cart->remove()
---------------------------------------------------
Starting Here, the sample demonstrates passing IDL-valuetypes (i.e java serializable objects)
Dummy methods added to Cart interface will be used to demonstrate passing ValueTypes
Cart Client: Sending ComplexObject Valuetype
Cart Client: Receiving ComplexObject Valuetype
data in the InterfaceTest object is 10000678
---------------------------------------------------
Cart Client: Calling cart->remove(), (i.e remove() on EJBObject) indicating we are done with the cart
Cart Client: cart->remove() successful, exiting program
Please download and Install ORBacus 4.1.1 from the orbacus website at http://www.orbacus.com or from the ORBacus Installation CD.
If you are having trouble in setting up ORBacus, please read the detailed instructions in ORBacus Instructions section and for further help go to http://www.orbacus.com or contact ORBacus Support.
Edit APPSERV_INSTALDIR\samples\rmi-iiop\cpp\src\client\make\cpp_def.mk and set OB_INSTDIR to the root directory of ORBacus installation.
Install Cygwin from http://www.cygwin.com/download.html (containing gmake, cvs, sh, perl, etc.).
- For example, if Orbacus is installed in D:\opt\OB, then set the following in the file : OB_INSTDIR = D:/opt/OB.
- Be warned that you'll need to use forward slashes ("/") instead of back slashes ("\") in this path and please make sure that the idl compiler is available in $(OB_INSTDIR)/bin/.
The makefiles check the TOOL_ROOT environment variable for the root of some required executables. The makefiles expect to find these executables in %TOOL_ROOT%/bin, so set the TOOL_ROOT environment variable appropriately (e.g. TOOL_ROOT=c:).
Make sure your path environment variable is "Path" and not "path" or "PATH".
- Be warned that you'll need to use forward slashes ("/") instead of back slashes ("\") in this path. For example, if cygwin is installed in C:\cygwin , then do the following: C:> set TOOL_ROOT=C:/cygwin.
Add %TOOL_ROOT%\bin to the beginning of your path. It should be before winnt\system32 and before any other tools you have in your path.
Install MS Visual C++ 6.0 and associated Service Packs.
Set the environment variable MSVC_DIR to the installation directory (e.g. MSVC_DIR=c:/VC98). The makefiles are expecting to find cl.exe in %MSVC_DIR%\bin.
- Note: When installing, do not install in c:\Program Files (or any other directory with white space in it).
Execute gmake.
- Be warned that you'll need to use forward slashes ("/") instead of back slashes ("\") in this path. For example, if VisualStudio is installed in C:\VisualStudio\Vc98, then set the following: C:>set MSVC_DIR=C:/VisualStudio/Vc98.
Run the client using the following the command client:
- This will build all the c++ files and generate the binary client.exe in the APPSERV_INSTALDIR\samples\rmi-iiop\cpp\src\client\samples\cpp\WINNT4.0_DBG.OBJ.
- If the build is an optimized build (gmake BUILD_DEBUG=optimize all), then the executable client.exe will be created in the directory APPSERV_INSTALDIR\samples\rmi-iiop\cpp\src\client\samples\cpp\WINNT4.0_OPT.OBJ\.
You will see the above mentioned Output.
- -ORBInitRef NameService=corbaloc:iiop:<hostname>:<port number>/NameService.
Download ORBacus 4.1.1 from http://www.orbacus.com.
Download ORBacus4.1.1 IDL Compiler from http://www.orbacus.com. OB-4.1.1-eval-bin-solaris.tar.gz and unzip into any directory, fro example: IDL_DIR.
- This is provided in the form of source files. The product may be found in the name of OB-4.1.1-eval.tar.gz or OB-4.1.1-eval.zip.
Get the license.txt from the ORBacus Support team in the email and save it in a directory, for example: LICENSE_DIR.
Set the environment variable ORBACUS_LICENSE to LICENSE_DIE/license.txt.
- This is required for the Evaluation Versions.
Include the following in your path variable:
The location of your Workshop/VC++ bin Directory. For example: /usr/dist/share/forte_dev/SUNWspro/bin.
Now unzip the Source bundle (OB-4.1.1-eval.tar.gz or OB-4.1.1-eval.zip) and follow the instructions in the INSTALL file.
The location of your make executable. For example: /usr/local/tools/1.0/bin.
- This is required for the C++ Compiler and requires Sun Workshop 6.2 Install or MS Visual C++ 6.0.
The location of your gmake executable. For example: /tools/ns/bin/.
The location of your IDL compiler you just downloaded. For example: IDL_DIR/bin.
After successful install of ORBacus, copy your IDL compiler tThe executable idl found in IDL_DIR/bin) to your ORBacus bin directory, ORBACUS_INSTDIR/bin.
- You need to run config, make and make install to install the product. You can install the product anywhere, for example ORBACUS_INSTDIR. If you are installing in /usr/local (which is the default), you need to run make install as root user.
Now, set the following environment variables:
Now go back and compile and run your client Program.
Troubleshooting
On Unix, if the path to the shared libraries of ORBacus 4.1 are not set or are incorrectly set, the client will fail. Set the path to the shared libraries correctly.
If the portnumber of IIOP listener is not correct, the client will fail to contact iAS70. Check portnumber of IIOP listener given while running the client. The same thing applies for the hostname.
If you encounter problems when running the application, review the log files at APPSERV_INSTALDIR/domains/domain1/<server-instance>/logs/server.log to learn what exactly went wrong.
On Unix, if you are having build problems try changing the defines for TOOL_ROOT and NSTOOL_ROOT in the file APPSERV_INSTALDIR//samples/rmi-iiop/cpp/src/client/make/defines_UNIX.mk
For additional details on compilation process refer to Readme.
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated August 14, 2002