|
WebLogic jCOM Late Bound Example, BEA Systems, Inc. | |||||
In this example we will access an EJB deployed on WebLogic Server from a Visual Basic client using late binding.
There are two ways of accessing COM objects from Visual Basic: early bound and late bound access. In late bound access, no information about the object being accessed is available at compile time; the objects being accessed are dynamically evaluated at runtime. This means that it is not until you run the program that you find out if the methods and properties you are accessing actually exist. Late bound access is slower than early bound access, since every reference to an object has to be reevaluated at runtime. Since there is no information available about the objects being accessed, it is also more prone to user errors. However, it does provide a great deal of flexibility, and is extremely easy to set up, as this example will show.
This example is based on the WebLogic Enterprise JavaBean container-managed persistence example, which is included in the standard WebLogic kit. (For more information on this WebLogic Enterprise JavaBean example see the samples\examples\ejb20\basic\containerManaged\package-summary.html file located under the WebLogic installation directory.) This example assumes you have previously successfully run the WebLogic container-managed example.
The container-managed persistence example has a Java client which accesses a bank account and performs account transactions. In this WebLogic jCOM example, a VB client is created which simulates the container-managed persistence client example. The EJB itself remains unchanged, and has no knowledge that it is being accessed as a COM object.
The following sections describe how to build and run this example:
In this example, the server can run on a Java™ 2 Platform, Enterprise Edition 1.3. The COM client has to run on a Microsoft Windows platform.
This example requires that the following be installed:
On the WLS server machine:
- WebLogic Server 7.0
On the Windows VB client machine (which may be the same as the server machine):
- Visual Basic 6.0
- WebLogic jCOM 7.0 tools
To load the tools on your client machine, copy them from the
WL_HOME\bindirectory on the WLS server machine.
This example and all the pre-made files referred to can be found (assuming you have installed WLS to the default directory) in the installed WebLogic Examples jCOM directory under SAMPLES_HOME\server\src\examples\jcom.
Steps to Build and Run this Example
The following steps are required to implement late-bound COM-to-Java communication:
Start the WebLogic Examples Server. Click these links for details on starting the server on a Windows Machine, or on a UNIX Machine.
Verify that the WebLogic Examples Server is configured properly to run this example.
Verify that the Container-Managed Persistence Example Is Deployed
In the lefthand pane of the WebLogic Server Console, click Deployments and then EJB.
"ejb20_basic_containerManaged" should be one of the bullet items displayed.
Verify that the Container-Managed Persistence Example Is Targeted to the Examples Server
- In the lefthand pane of the WebLogic Server Console, click Deployments and then EJB.
- Click "ejb20_basic_containerManaged.
- In the righthand pane, select the "Targets" tab.
Verify that "examplesServer" is listed under "Chosen".
Verify that the Server Port is Listening for COM Calls
- In the lefthand pane of the WebLogic Server Console, click Servers and then exampleServer.
- In the right hand pane, select the jCOM tab.
The "COMEnabled" box should be checked. If not, do so now.
Verify that the Security Settings Are Correct
In this section, you verify that access is granted to the WebLogic Server classes that the COM client application needs to access.
For this example, the COM client needs access to the following three classes:
java.util.Collectionjava.util.Iteratorejb20.basic.containerManagedVerifying Access to java.util.Collection and java.util.Iterator
- In the lefthand pane of the WebLogic Server Console, click the Services node and then click the JCOM node underneath it.
- In the righthand pane, enter the following:
java.util.*
- Click Define Policy.
- Verify that the Policy Statement box contains the statement "Caller is a member of the group everyone".
If the statement is there, access to
java.util.Collectionandjava.util.Iteratoris granted to everyone; your COM client application can successfully access these classes.- If the Policy Statement box does not contain this statement, you must add it.
To do that:
- In the Policy Condition box, double-click "Caller is a member of the group".
- In the box that is displayed, enter "everyone" in the "Enter group name:" field.
- Click Add.
- Click OK.
- In the bottom righthand corner of the window, click Apply.
Verifying Access to ejb20.basic.containerManaged
- In the lefthand pane of the WebLogic Server Console, click the Services node and then click the JCOM node underneath it.
- In the righthand pane, enter the following:
ejb20.basic.containerManaged.*
- Click Define Policy.
- Verify that the Policy Statement box contains the statement "Caller is a member of the group everyone".
If the statement is there, access to the
ejb20.basic.containerManaged.*package is granted to everyone; your COM client application can successfully access these classes.- If the Policy Statement box does not contain this statement, you must add it.
To do that:
- In the Policy Condition box, double-click "Caller is a member of the group".
- In the box that is displayed, enter "everyone" in the "Enter group name:" field.
- Click Add.
- Click OK.
- In the bottom righthand corner of the window, click Apply.
Note that because of the final asterisk, you're granting access to the entire
ejb20.basic.containerManagedpackage.For more information on granting and revoking access to classes, point your web browser here:
http://edocs.bea.com/wls/docs70/ConsoleHelp/security_7x.html
On the client machine, register with the local Java Virtual Machine by adding the name "examplesServer" to the Windows registry and associating it with the TCP/IP address and client-to-server communications port where WebLogic will listen for incoming COM requests. By default, this is localhost:7001.
regjvmcmd examplesServer localhost[7001]
If the Examples Server is running on something other than localhost and listening on a port other than 7001, then pass that hostname (or IP address) and port number to regjvmcmd.
Note: The regjvmcmd.exe tool does not overwrite old entries when new entries with identical
names are entered. This means that if you ever need to change the hostname
or port of the machine with which you wish to communicate, you have to unregister
the old entry. You can do this using the command line tool regjvmcmd.exe,
or by using the GUI tool regjvm.exe. To use the command line tool, simply execute
this statement:
regjvmcmd /unregister examplesServer
This will unregister the JVM
ejbso that it can later be re-registered with a new destination hostname and port. If you prefer to work in a graphical environment, execute theregjvm.exefile.
If you haven't already loaded the regjvmcmd.exe and the regjvm.exe tools on your client machine, you can find them in the
WL_HOME\bin directory) on your WLS server machine.
The source code for the VB client has to first link a COM object to an interface of the EJB. Any further references to this object appear to be referring to a COM object, but in fact are using the Java methods as if they are COM methods.
In this extract from the VB client source code frmMain.frm notice the declaration of the COM version of the Account EJB's home interface mobjHome. This COM object is linked to an instance of the AccountHome interface on the server side.
Dim mobjHome As Object Private Sub Form_Load() 'Handle errors On Error GoTo ErrOut 'Bind the EJB AccountHome object via JNDI Set mobjHome = CreateObject("examplesServer:jndi:ejb20-containerManaged-AccountHome") Here, CreateObject is instanciating an object called containerManaged.AccountHome on the EJB server.
Later on in the source, the COM object objList is linked to a Java enumeration
created by invoking findBigAccounts on the server.
Set objList = mobjHome.findBigAccounts(0)
To access the EJB from Visual Basic:
- On the client machine, load the VB source code, containerManaged.vbp, and press F5 to run the sample.
- Enter an "Account Name" and an "Amount" and click "Create". You can then deposit and withdraw from the newly created account, remove the account, or create more accounts.
Error messages will be displayed in the light-gray textbox at the bottom of the form. You will be notified when the example starts if there have been any problems connecting with the WebLogic Server EJB.
|
Documentation is available at http://e-docs.bea.com/wls/docs70/jcom/index.html
|
|||||