Using WebLogic COM
Introduction
WebLogic, an open, standards-based enterprise application server, provides several means of access for clients in a heterogeneous networked application environment -- including Java clients, VB clients, COM integration on the client and server side, and CORBA invoking directly on EJBs. Using the Microsoft SDK for Java, it is possible to export Java business objects as COM objects. Enterprise JavaBeans and other Java objects can be automatically wrapped as COM components for easy importation into Visual Basic, Visual C++, Active Server Pages, and any other environment that supports COM. To the Microsoft developer, access to a remote Java component is programmed like any other COM invocation. In this way, the integration barriers between server-side Java and the broad array of client environments can be eliminated. The reverse mapping works as well. With WebLogic COM, users can wrap their COM business components with Java objects that can be remotely accessed as WebLogic RMI objects within the WebLogic framework. To the Java developer, COM business components are then called like any other remote Java object--except that they must be instantiated within a COM runtime environment, e.g. the Windows operating system. When using Microsoft SDK for Java, it must to be used to run both the client application and WebLogic Server. The combination of Microsoft SDK for Java running on one side with a Sun Java Virtual Machine (JVM) running on the other side is not supported. This document details how to set up your environment and use the WebLogic COM compiler to generate RMI-usable objects from your COM objects. Additional instructions describe how these generated objects are then deployed and invoked. This document also contains some general instructions for building non-Java clients capable of invoking RMI-usable objects. Converting COM objects to RMI-usable objects
To convert COM objects into RMI-usable objects, you need to compile the COM object (typically a .tlb, .olb, .ocx, .dll, or .exe) using the WebLogic COM compiler. The compiler will generate Java wrappers for the COM objects and RMI wrappers for the Java classes. To use the generated class, the implementation class must be deployed as a startup class of your WebLogic Server. Once the COM object is compiled and deployed, it becomes accessible from the network to any client via any of WebLogic's supported protocols. Using the WebLogic COM compilerSetting up your environmentCheck these setup requirements before you run the WebLogic COM compiler.
Running the compilerRunning the compiler will generate Java wrappers for the COM objects and RMI wrappers for the Java classes. The package names of the generated classes will be mapped as follows:
In addition, each set of generated remote objects will have a Utilities class that assigns return types for the remote objects. In some cases, you may want to edit the Utilities class. Select a server-side COM object (typically a .tlb, .olb, .ocx, .dll, or .exe). Determine whether the COM object is multithreaded; you should compile COM objects with the -nothreads flag if the object is not multithreaded. Syntax for the compiler is detailed below. Syntaxc:\>jview weblogic.comc -d dest options object
Examplesc:\>jview weblogic.comc -d \weblogic\classes -nothreads -register \winnt\ODA.dll Using the generated classesDeploymentYou can use any VM that supports the use of WebLogic RMI to access your COM object from a client. Once the COM object is compiled and deployed, it becomes accessible from the network to any client via any of WebLogic's supported protocols, including SSL and HTTP tunneling.
DevelopmentTo invoke on the resulting classes, just import the generated weblogic.com.remote.* package and use the same interfaces you would use for the COM object. Here is an example that invokes on the IConnection object from ODA.dll, which we ran through the compiler to create the generated packages weblogic.com.oda.* and weblogic.com.remote.oda.*. (ODA.dll allows you to directly access an Oracle7 database via the Oracle Call Interface (OCI). It is available from http://www.download.com; search on "ODA".) import weblogic.com.Variant; import weblogic.com.remote.oda.*; import weblogic.rmi.*; public class ODATest { public static void main(String[] args) throws Exception { String url = args.length == 0 ? "t3://localhost:7001" : args[0]; String name = "oda"; IConnection conn = (IConnection) Naming.lookup(url + "/" + name); conn.Open("alpha", "scott", "tiger"); IRecordSet rs = conn.getRecordset(); rs.Execute("SELECT * FROM EMP"); rs.Fetch(); int numcols = rs.getCount(); for(int col = 0; col < numcols; col++) { IField f = rs.getItem(new Variant(col)); System.out.println(f.getName() + ": " + f.getValue()); } conn.Close(); System.exit(0); } } You can also use a DLL that references COM objects with WebLogic COM. Note that if your DLL references COM objects that are not present in the DLL, WebLogic COM will not know what type to cast return values to. The Utilities class (located with the generated objects) tries to determine what type of object your are returning and cast it to the appropriate type. There are two potential solutions to this problem:
Connecting to WebLogic from a COM clientSetting up your clientYou can write a client application in Visual Basic (or any other environment that supports COM) that uses Java objects installed in the WebLogic Server, for example Enterprise JavaBeans (EJBeans) and RMI (Remote Method Invocation) objects. Being able to access Java server-side objects from your Visual Basic clients makes it easy to integrate very complex and sophisticated business logic with client-building GUI tools that many Windows developers are already familiar with. To use this feature of WebLogic COM, you must have several sets of Java classes available on your client:
Next, compile the classes you want to use with your client. For example, if you plan to invoke the EJB examples shipped with the WebLogic release, you will need to compile the EJB examples. There are Windows bat/cmd files shipped in the examples/ejb directory that help you compile these files. If you are compiling your own classes outside a directory that you have already added to your CLASSPATH, you will need to add those classes to your trusted classpath in the next step. You will need to register the WebLogic classes as trusted classes. Here is an example that works if you have installed the WebLogic classes on your C drive: $ jview weblogic.com.Export c:\weblogic\classes;c:\weblogic\lib\weblogicaux.jar If you are compiling other classes that your client will use in another directory, you must add that directory to the export process as well (in beta 4, all the classes must be exported at the same time). Here is an example. Note that this is a single command that should be typed on one command line. We have divided the lines here to make it readable. $ jview weblogic.com.Export c:\weblogic\classes;c:\weblogic\lib\weblogicaux.jar;c:\myclasses Finally, you will need to run WebLogic Server using the Microsoft SDK for Java. COM clients are not support when running WebLogic Server under a Sun JVM.
Here is a Visual Basic code example of how to connect to a WebLogic Server and create a handle to an EJB object "TraderHome" through a JNDI initial context. (If you use this example, be sure to compile and export the necessary classes, as described above.) The VB objects that we instantiate and use in this example provide access to the following:
In this example, we call the Create() method on the EJBean home, which returns an EJBean instance, trader. Dim server As Object Dim brok As Object Dim ic As Object Dim trader As Object Set server = GetObject("java:weblogic.com.Server") Set ic = server.getInitialContext("t3://beale:7001") Set brok = ic.lookup("statelessSession.TraderHome") Set trader = brok.Create() From here, you operate on the trader bean just as you would any other EJBean. (For more on WebLogic EJB, read BEA WebLogic Server Enterprise JavaBeans.) When you have finished your WebLogic operations, it is good programming practice to call close() on the context (in this example ic) to clean up server-side resources. Finally, compile your VB client. Start the WebLogic Server on the server host, and test your client application. Registering interest in WebLogic EventsYou can have your clients (for example, VB or PowerBuilder clients) register an interest in WebLogic Events. For more information on what you can do with events, read the Developers Guide, Using WebLogic Events. To use WebLogic's Events service from your COM clients, you must register the COM EventProxy as a COM object. Here is an example; it includes the steps necessary to export the WebLogic classes for use with VB, which you must do before the EventProxy class is available for registering. $ jview weblogic.com.Export c:\weblogic\classes;c:\weblogic\lib\weblogicaux.jar $ javareg /control /codebase:c:\weblogic\classes /class:weblogic.com.EventProxy /register /typelib:c:\weblogic\lib\EventProxy.tlbThe javareg command above does two things: 1) it registers the weblogic.com.EventProxy class as an ActiveX Control within the Windows registry assigning it a class identifier (clsid), and 2) it creates a type library file. When you run the javareg command, a window will appear displaying the alphanumeric clsid created for the registration. You should write this identifier down. The clsid and type library file are very important, if you plan to distribute your VB application for use on other machines. To run your VB application on another machine, you need to install the weblogic classes on the other machine and export them using command above. You also need to install a copy of the original type library file and register the weblogic.com.EventProxy class using the same clsid and type library file. An example is included below. $ javareg /control /codebase:c:\weblogic\classes /class:weblogic.com.EventProxy /register /typelib:c:\weblogic\lib\EventProxy.tlb /clsid:{45B24280-1EB0- 11D3-B6DB-0000861F705F} /nomktyplib There are two important options in the command above. First, the clsid option specifies the class identifier to be registered with the class. Secondly, the nomktyplib option tells the utility that it should not create a new type library. Instead, it registers the existing type library specified in the argument of the /typelib option. See the Microsoft SDK for Java documentation for more information on the javareg utility. Once you have registered the COM EventPoxy as an ActiveX Control, you need to add an EventProxy component to the VB form. Select the Components command from the Project menu in Visual Basic. Select the weblogic.com.EventProxy checkbox and hit OK. An EventPoxy component will now appear on the component pallet. Drag an EventProxy component onto the VB from. Here is some sample code from a VB client: Private i As Integer Private ic As Object Private Sub EventProxy1_tengahEventOccurred(ByVal Parameter0 As Object) i = i + 1 Label1.Caption = "WEBLOGIC.TIME Events: " & i Label2.Caption = Parameter0.topic Set paramSet = Parameter0.paramSet Label3.Caption = paramSet.toString End Sub Private Sub Form_Load() Set server = GetObject("java:weblogic.com.Server") Set ic = server.getInitialContext("t3://localhost:7001") Set t3Services = ic.lookup("weblogic.services") Set events = t3Services.events Set eventTopic = events.getEventTopic("WEBLOGIC.TIME") Set er = eventTopic.register(EventProxy1.getEvaluate( "weblogic.event.evaluators.EvaluateTrue"), EventProxy1.getAction) End Sub Registering Java Beans for Visual Basic useYou can register the Java Beans from a .jar file as COM controls so that they are usable from Visual Basic. This means that you can use Java Beans to build Visual Basic programs, just as if they were a COM component.You will need to have the SDK installed, and then you will export the WebLogic classes to your SDK classpath and run the Register program against the .jar file that contains the Beans. Here are detailed instructions:
Converting COM objects for server-side useIf you want to use COM objects from Java servlets -- that is, server-side use of a COM object, rather than client-side use -- you can do so with the Microsoft SDK 3.1 (or later) and the Microsoft JVM. This feature allows you to integrate legacy COM-based application business logic into the full power of the WebLogic framework -- a quick way to make limited-scale applications Internet- or intranet-ready.
|
|
Copyright © 2000 BEA Systems, Inc. All rights reserved.
|