![]() |
The following code extracts can be used to access Enterprise JavaBeans through the ActiveX to EJB bridge without using a J2EE client container. This code is taken from the samples included with the ActiveX to EJB Client provided with WebSphere Application Server. For information about the samples, see the related samples information.
Visual Basic
In this example, the Visual Basic code extract performs the following actions:
These actions are performed using the example Visual Basic helper functions defined in Examples: Visual Basic helper functions.
' Some Globals: Dim oXJB as Object Sub Main() ' Initialize the ActiveX to EJB bridge using our Helper function above. ' Store it in a global variable. In this example, it is initialized once only ' and uses values from our environment that was initialized by launchClientXJB.bat ' or setupCmdLineXJB.bat If oXJB Is Nothing Then Set oXJB = XJBInit(Environ("WAS_HOME"), Environ("JAVA_HOME"), Environ("NAMING_FACTORY")) End If ' Create the initial context ' - This creates a J2EE initial context. ' - We pass a Hashtable via the use of a JMethodArgs object to NewInstance Dim oArgs as Object Set oArgs = oXJB.GetArgsContainer ' Build our properties using the normal naming string constants. Here they are ' static Fields of the javax.naming.Context object Dim Context_PROVIDER_URL As String Dim Context_INITIAL_CONTEXT_FACTORY As String Context_PROVIDER_URL = oXJB.FindClass("javax.naming.Context").PROVIDER_URL Context_INITIAL_CONTEXT_FACTORY = oXJB.FindClass("javax.naming.Context").INITIAL_CONTEXT_FACTORY ' We connect to MyServer.com and pull the Initial Context Factory out ' of an environment variable which was set in launchClientXJB.bat. Dim oHT As Object Set oHT = oXJB.NewInstance(oXJB.FindClass("java.util.Hashtable")) XJBPutProperty oXJB, oHT, Context_PROVIDER_URL, "iiop://MyServer.com" XJBPutProperty oXJB, oHT, Context_INITIAL_CONTEXT_FACTORY, Environ("NAMING_FACTORY") Dim initialContext As Object Set initialContext = oXJB.NewInstance(oXJB.FindClass("javax.naming.InitialContext"), oHT) ' Get EJB Home ' We specify the following: ' - InitialContext: Our J2EE InitialContext ' - JNDIName: The JNDI Name of our EJB using ' - HomeClassName: Name of the home class. This is pulled out of the ' appropriate EJB jar file within our EAR. Dim hello As Object Dim helloHome As Object Set helloHome = XJBGetEJBHome(oXJB, initialContext, "WSsamples/HelloEJBHome", _ "WebSphereSamples.HelloEJB.HelloHome") ' Create the EJB Home ' Note: We use CallByName() because Visual Basic likes to 'Capitalize the "create" method as Create, which ' doesn't really exist set hello = CallByName(helloHome, "create", vbMethod) ' Execute a method on our EJB. MsgBox hello.getMessage() End Sub
Active Server Pages
In this example, the Active Server Pages code extract performs the following actions:
These actions are performed using the example ASP helper functions defined in Examples: ASP helper functions.
<-- #include virtual ="/WSASPIncludes/setupASPXJB.inc" --> <% Sub Main() ' Initialize the ActiveX to EJB bridge using our Helper function above. ' Store it in a global variable. In this example, it is initialized once only ' and uses values from our environment that was initialized in our ' setupASPXJB.inc include file Application.lock If IsEmpty(Application("oXJB")) Then Set Application("oXJB") = XJBInit(com_ibm_websphere_washome, com_ibm_websphere_javahome,com_ibm_websphere_namingfactory) End If Application.unlock ' Create the initial context ' - This creates a J2EE initial context. ' - We pass a Hashtable via the use of a JMethodArgs object to NewInstance Dim oArgs Set oArgs = Application("oXJB").GetArgsContainer ' Build our properties using the normal naming string constants. Here they are ' static Fields of the javax.naming.Context object Dim Context_PROVIDER_URL Dim Context_INITIAL_CONTEXT_FACTORY Context_PROVIDER_URL = Application("oXJB").FindClass("javax.naming.Context").PROVIDER_URL Context_INITIAL_CONTEXT_FACTORY = Application("oXJB").FindClass("javax.naming.Context").INITIAL_CONTEXT_FACTORY ' We connect to MyServer.com and pull the Initial Context Factory out ' of an environment variable which was set in launchClientXJB.bat. Dim oHT Set oHT = Application("oXJB").NewInstance(Application("oXJB").FindClass("java.util.Hashtable")) XJBPutProperty Application("oXJB"), oHT, Context_PROVIDER_URL, "iiop://MyServer.com" XJBPutProperty Application("oXJB"), oHT, Context_INITIAL_CONTEXT_FACTORY, com_ibm_websphere_namingfactory Dim initialContext Set initialContext = Application("oXJB").NewInstance(Application("oXJB").FindClass("javax.naming.InitialContext"), oHT) ' Get EJB Home ' We specify the following: ' - InitialContext: Our J2EE InitialContext ' - JNDIName: The JNDI Name of our EJB using ' - HomeClassName: Name of the home class. This is pulled out of the ' appropriate EJB jar file within our EAR. Dim hello Dim helloHome Set helloHome = XJBGetEJBHome(Application("oXJB"), initialContext, "WSsamples/HelloEJBHome", _ "WebSphereSamples.HelloEJB.HelloHome") ' Create the EJB Home set hello = helloHome.create ' Execute a method on our EJB. Response.Write(hello.getMessage()) End Sub %>
Related concepts... | |
An overview of the WebSphere ActiveX to EJB bridge | |
How ActiveX programs use the ActiveX to EJB bridge | |