WebLogic jCOM Zero Client Example, BEA Systems, Inc.

Zero Client Installation Example:

Excel VBA to WebLogic EJB

This example demonstrates how to access an EJB deployed on WebLogic Server from an Excel VBA client using the zero client installation.

This example is based on the WebLogic Enterprise JavaBean bean-managed persistence example, which is included in the standard WebLogic kit. (For more information on the bean-managed persistence example see the samples\examples\ejb20\basic\beanManaged\package-summary.html file located under the WebLogic installation directory.) This example assumes you have previously successfully run the WebLogic bean-managed persistence example.

The bean-managed persistence example has a Java client which accesses a bank account, creates some accounts, and queries for the largest ones. In the WebLogic jCOM Zero Client Installation example, an Excel VBA client simulates the bean-managed client persistence example. The EJB itself remains unchanged, and has no knowledge that it is being accessed as a COM object.

The most significant feature about this example is the fact that the client side (the Excel worksheet) requires no WebLogic jCOM files in order to be able to access the EJB on the server.

Note that this example requires Excel 2000 or later.

The following sections describe how to build and run the example:

Prerequisites

Verify that your configuration meets these prerequisites before continuing. In this example, the WebLogic Server can run on a Java™ 2 Platform, Enterprise Edition 1.3. The COM client must run on a Microsoft Windows platform.

This example requires that the following be installed:

On the WLS system:

On the Windows VB client machine (which may be the same as the 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 for zero client COM-to-WLS communication:

  1. Start the WebLogic Examples Server
  2. Verify the WebLogic Examples Server Configuration
  3. If Necessary, Modify the Excel VBA Client Source Code
  4. Run the Excel VBA Client Example
  5. Verify the Output

Start the WebLogic Examples Server

Start the WebLogic Examples Server. Click these links for details on starting the server on a Windows Machine, or on a UNIX Machine.

Verify the WebLogic Examples Server Configuration

Verify that the WebLogic Examples Server is configured properly to run this example.

Verify that the Bean-Managed Persistence Example Is Deployed

In the lefthand pane of the WebLogic Server Console, click Deployments and then EJB.

"ejb20_basic_beanManaged" should be one of the bullet items displayed.

Verify that the Server Port is Listening for COM Calls

  1. In the lefthand pane of the WebLogic Server Console, click Servers and then exampleServer.
  2. In the right hand pane, select the jCOM tab.
  3. 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:

Verifying Access to java.util.Collection and java.util.Iterator
  1. In the lefthand pane of the WebLogic Server Console, click the Services node and then click the JCOM node underneath it.
  2. In the righthand pane, enter the following:
  3. java.util.*

  4. Click Define Policy.
  5. Verify that the Policy Statement box contains the statement "Caller is a member of the group everyone".
  6. If the statement is there, access to java.util.Collection and java.util.Iterator is granted to everyone; your COM client application can successfully access these classes.

  7. If the Policy Statement box does not contain this statement, you must add it.
  8. To do that:

    1. In the Policy Condition box, double-click "Caller is a member of the group".
    2. In the box that is displayed, enter "everyone" in the "Enter group name:" field.
    3. Click Add.
    4. Click OK.
    5. In the bottom righthand corner of the window, click Apply.
Verifying Access to ejb20.basic.beanManaged
  1. In the lefthand pane of the WebLogic Server Console, click the Services node and then click the JCOM node underneath it.
  2. In the righthand pane, enter the following:
  3. ejb20.basic.beanManaged.*

  4. Click Define Policy.
  5. Verify that the Policy Statement box contains the statement "Caller is a member of the group everyone".
  6. If the statement is there, access to the ejb20.basic.beanManaged.* package is granted to everyone; your COM client application can successfully access these classes.

  7. If the Policy Statement box does not contain this statement, you must add it.
  8. To do that:

    1. In the Policy Condition box, double-click "Caller is a member of the group".
    2. In the box that is displayed, enter "everyone" in the "Enter group name:" field.
    3. Click Add.
    4. Click OK.
    5. 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.beanManaged package.

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

If Necessary, Modify the Excel VBA Client Source Code

We will take a look at the source code for the Excel spreadsheet beanManaged.xls to see how the zero client installation COM-to-Java communication is accomplished.

Open the Excel spreadsheet beanManaged.xls and press ALT-F11 to look at the source code:

  1. The most important line of code in this example is the following:

    Set objBridge = GetObject("objref:TUVPVwEAAAAABAIAAAAAAMAAAAAAAABGABAAAAAAAABKaW50ZWdyYV
    RhbGtUb01lV2hhdHNBbGxUaGlzVGhlbhkAEgAHADEAMgA3AC4AMAAuADAALgAxAFsANwAwADUAMABdAAAAAAAKAP//AAAAAAAAAAAAAA==:")

This is how the COM client accesses the WebLogic Server jCOM functionality without having any WebLogic jCOM knowledge; however the object reference moniker ("objref") value must be hard coded. As a result, the destination server and port are fixed. In this example, the objref value is hard coded to access localhost on port 7001.

NOTE: If the WebLogic Examples Server is not running on localhost:7001, you will need to modify the Excel VBA code to provide the correct object reference for the server's actual location. See Generating an Object Reference Moniker for details.

  1. Once the WebLogic Examples Server has been accessed, the Excel VBA client can bind the EJB AccountHome object via JNDI.

    Set mobjHome = objTemp.get("examplesServer:jndi:ejb20-beanManaged-AccountHome")

Here a reference is obtained to "get" AccountHome by accessing the WebLogic Examples Server.

Generating an Object Reference Moniker

The hard coded object reference moniker (or "objref") value allows access to the WebLogic Server, but at the same time it fixes the destination server and port number. By default, the Excel VBA code shipped with this example is hardcoded to communicate with a server running on localhost:7001.

If the Examples Server is not running on localhost:7001, you must obtain the object reference moniker for your code.

There are two ways to obtain an object reference moniker for hardcoding into your Excel VBA client code. In both cases, replace the objref value in the source code provided with the value you obtain.

  1. Obtain it via a servlet running on WebLogic Server. Open a web browser on WebLogic Server to this http://[wlshost]:[wlsport]/bea_wls_internal/com and paste the moniker value into your code.
  2. Run the com.bea.jcom.GetJvmMoniker Java class, specifying as parameters the full name or TCP/IP address of the WebLogic Examples Server machine and port number:

    java com.bea.jcom.GetJvmMoniker [wlshost] [wlsport]

A long message is displayed which shows the objref moniker and explains how to use it. The text displayed is also automatically copied to the clipboard, so it can be pasted directly into your source. The objref moniker returned can be used to access WebLogic Server on the machine and port you have specified.

Run the Excel VBA Client Example

To access the EJB from Excel:

  1. Open the Excel "beanManaged.xls" file. You may be prompted to enable or disable macros. Be certain you click "Enable Macros" for this example to work.
  2. When the form loads, click the "Start Sample" button. The VBA code will begin accessing the EJB and providing feedback.

Any problems encountered connecting with the WebLogic Server EJB will be reported in pop-up message boxes.

To access the source code, use the menu item Tools->Macro->Visual Basic Editor, or simply use the shortcut ALT-F11.

Verify the Output

The output should look like this:

Trying to find account with ID '0'.
Trying to find account with ID '1'.
Trying to find account with ID '2'.
Trying to find account with ID '3'.
Trying to find account with ID '4'.
Trying to find account with ID '5'.
Trying to find account with ID '6'.
Trying to find account with ID '7'.
Trying to find account with ID '8'.
Trying to find account with ID '9'.
Trying to find account with ID '10'.
Trying to find account with ID '11'.
Trying to find account with ID '12'.
Trying to find account with ID '13'.
Trying to find account with ID '14'.
Trying to find account with ID '15'.
Trying to find account with ID '16'.
Trying to find account with ID '17'.
Trying to find account with ID '18'.
Trying to find account with ID '19'.
Account '0' has a balance of $0.00.
Account '1' has a balance of $1,000.00.
Account '2' has a balance of $2,000.00.
Account '3' has a balance of $3,000.00.
Account '4' has a balance of $4,000.00.
Account '5' has a balance of $5,000.00.
Account '6' has a balance of $6,000.00.
Account '7' has a balance of $7,000.00.
Account '8' has a balance of $8,000.00.
Account '9' has a balance of $9,000.00.
Account '10' has a balance of $10,000.00.
Account '11' has a balance of $11,000.00.
Account '12' has a balance of $12,000.00.
Account '13' has a balance of $13,000.00.
Account '14' has a balance of $14,000.00.
Account '15' has a balance of $15,000.00.
Account '16' has a balance of $16,000.00.
Account '17' has a balance of $17,000.00.
Account '18' has a balance of $18,000.00.
Account '19' has a balance of $19,000.00.

Querying for accounts with a balance greater than 5000...
Account '6' has a balance of $6,000.00.
Account '7' has a balance of $7,000.00.
Account '8' has a balance of $8,000.00.
Account '9' has a balance of $9,000.00.
Account '10' has a balance of $10,000.00.
Account '11' has a balance of $11,000.00.
Account '12' has a balance of $12,000.00.
Account '13' has a balance of $13,000.00.
Account '14' has a balance of $14,000.00.
Account '15' has a balance of $15,000.00.
Account '16' has a balance of $16,000.00.
Account '17' has a balance of $17,000.00.
Account '18' has a balance of $18,000.00.
Account '19' has a balance of $19,000.00.


Documentation is available at http://e-docs.bea.com/wls/docs70/jcom/index.html

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