All Examples  RMI over IIOP Examples

package examples.rmi_iiop.simplified_idl.ejb

EJB with Corba/C++ Client example package

Enterprise JavaBean stateless session
example package and classes

about this example

This example illustrates: This example demonstrates connectivity between an EJB and a Corba/C++ client. It uses VisiBroker 4.0 with Microsoft VC++ 6.0 compiler. It uses a stateless session EJBean called MyBean and presumes some knowledge of EJBean deployment. For examples pertaining stricly to EJBeans, 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 look at Client.java to see how the application works.

The following steps summarize the crucial steps in establishing connectivity between an EJB and a Corba/C++ client:

    1. Build the ejb jar file and run the wellogic.ejbc with the option:

       -idl -iiop -idlNoValueTypes -idlOverwrite

    2. Copy the jar file to the weblogic server deployment directory.

    3. Generate the c++ stubs using idl2cpp compiler.

    4. Compile the c++ stubs and client source file.

    5. Link the objects file created by step 4 and create the executable.

    6. Run the client:   Client <Server IOR>   (where the <Server IOR> is acquired from the utils.host2ior)

how to use this example

Build the example:

Adjust your environment

First, set up your environment. Adjust the following variables:

JAVA_HOME=c:/java/java130
WL_HOME=c:/weblogic
MYSERVER=c:/weblogic/myserver
CLASSPATH=$(JAVA_HOME)/jre/lib/rt.jar\;$(JAVA_HOME)/lib/tools.jar\;.\;$(WL_HOME)\;$(WL_HOME)/classes/boot\;\
$(WL_HOME)/lib/weblogic510sp6.jar\;$(WL_HOME)/classes\;$(WL_HOME)/tools\;$(WL_HOME)/license\;\
$(WL_HOME)/dev/src51/3rdparty/weblogicaux.jar\;./build
JAVAC=$(JAVA_HOME)/bin/javac -classpath $(CLASSPATH)
IDL2CPP=c:/Inprise/vbroker/bin/idl2cpp -no_servant -idl_strict

If you need more information on setting up your environment see the WebLogic document Setting your development environment.

Build the EJB deployment jar file

Notice the useNote the use of -idl, specifically -idlNoValueTypes, -idlOverwrite and -idlDirectory idl

EJB: build_dir
	$(JAVAC) -d build $(BEAN_API) $(BEAN_IMPL)
	$(JAVAC) -d $(MYSERVER)/clientclasses $(BEAN_API)
	cd build && jar cv0f std_$(BEAN_JAR) META-INF examples
# running weblogic.ejbc to generate the idl files
	$(JAVA_HOME)/bin/java -classpath $(CLASSPATH) -Dweblogic.home=$(WL_HOME) weblogic.ejbc -iiop -idl -idlNoValueTypes \
	-idlOverwrite -idlDirectory idl build/std_$(BEAN_JAR) build/$(BEAN_JAR)

Deploy the jar file on the server

build_dir: 
	mkdir -p build build/META-INF idl cpp/javax/ejb
	mkdir -p $(WL.HOME)/clientclasses
	mkdir -p $(WLHOME)/clientclasses/jidlclasses
	cp -f ejb-jar.xml weblogic-ejb-jar.xml build/META-INF

Build the C++ client

Use the idl2c++ compiler. Notice the use of -namespace.
cppclient:
	$(IDL2CPP) -Ic:/Inprise/vbroker/idl -namespace -Iidl -src_suffix cpp idl/examples/rmi_iiop/ejb/simplified_idl/MyBean.idl
	$(IDL2CPP) -Ic:/Inprise/vbroker/idl -namespace -Iidl -src_suffix cpp idl/examples/rmi_iiop/ejb/simplified_idl/MyBeanHome.idl
	$(IDL2CPP) -Ic:/Inprise/vbroker/idl -namespace -Iidl -src_suffix cpp -root_dir cpp/javax/ejb idl/javax/ejb/EJBObject.idl
	$(IDL2CPP) -Ic:/Inprise/vbroker/idl -namespace -Iidl -src_suffix cpp -root_dir cpp/javax/ejb idl/javax/ejb/EJBHome.idl
	$(IDL2CPP) -Ic:/Inprise/vbroker/idl -namespace -Iidl -src_suffix cpp -root_dir cpp/javax/ejb idl/javax/ejb/RemoveEx.idl
	$(IDL2CPP) -Ic:/Inprise/vbroker/idl -namespace -Iidl -src_suffix cpp -root_dir cpp/javax/ejb idl/javax/ejb/CreateEx.idl
	$(IDL2CPP) -Ic:/Inprise/vbroker/idl -namespace -Iidl -src_suffix cpp -root_dir cpp/java/lang idl/java/lang/_Object.idl
	$(IDL2CPP) -Ic:/Inprise/vbroker/idl -namespace -Iidl -src_suffix cpp -root_dir cpp/java/rmi idl/java/rmi/Remote.idl

Compile the c++ stubs and client file

	 CL /MD /DTHREAD /nologo -DWIN32 /GX /DSTRICT /DALIGNED /DVISIBROKER  /DMSVCUSING_BUG /DMSVCNESTEDUSING_BUG -Icpp \
	 -Ic:/Inprise/vbroker/include -Ic:/Inprise/vbroker/include/stubs -Ic:/weblogic/dev/src51 -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

Generate the client executable

	 LINK /nologo /out:Client.exe /LIBPATH:c:/Inprise/vbroker/lib MyBean_c.obj MyBeanHome_c.obj EJBObject_c.obj EJBHome_c.obj \
	 RemoveEx_c.obj _Object_c.obj Remote_c.obj Client.obj

Configure the server

Deploy the EJBean by adding the path to the .jar file to the "weblogic.ejb.deploy" property.

To the weblogic.properties file, add the following: weblogic.ejb.deploy=$(WL-Home)/myserver/examples.rmi_iiop.ejb.simple.jar. You'll need to adjust this property depending on which EJBeans you're building and are deploying, or if the location of the files differs from the installed location.

Note: If you're running under the Microsoft SDK for Java, you'll also need to add the path to the .jar to the CLASSPATH for your WebLogic Server.

Run the example

  1. Start the WebLogic Server using JDK 1.3. You can check that the EJBean has been deployed correctly either by checking the server command line window, or by opening the Console and examining "EJB" under the "Distributed objects"; you should see simplified_idl.MyBeanHome deployed, and can monitor its activity.

  2. Set up a command shell for your client to use JDK 1.3 as described in Setting your development environment and add the jar file to the CLASSPATH as shown in this example for Windows NT:
    $ set CLASSPATH=%CLASSPATH%;weblogic\myserver\ejb_basic_statelessSession.jar
    where weblogic is the installation directory for WebLogic Server.

  3. Get the server IOR by using java utils.host2ior host port.

  4. Run the client by entering:
    Client <IOR>
    
    Parameters are optional, but if any are supplied,
    they are interpreted in this order:
    
         url - URL such as "iiop://localhost:7001"
         user - User name, default null
         password - User password, default null
      

  5. If you're running the Client example, you should get output similar to the following:
    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.

Copyright © 2000 BEA Systems, Inc. All rights reserved.