The EJBConnection class is used to connect to an EJB server and locate an EJB. It has four methods: ConnectToServer, DisconnectServer, Lookup, and GetEJBTransaction.
To establish a connection to the server, you need to execute the PowerScript statements required to perform these operations:
Declare an instance of the EJBConnection class.
Set properties for the EJBConnection object.
Use the CREATE statement to instantiate the EJBConnection object.
Invoke the ConnectToServer method to establish a connection to the server.
Check for errors.
To connect to the application server and create an EJB object, the system CLASSPATH environment variable or the classpath argument of createJavaVM must contain the location of the EJB stub files, either a directory or a JAR file. The application server you are using might also require that some classes or JAR files be available on the client computer and added to the class path. For more information, see “The Java VM classpath in the development environment”.
The string used to establish the initial context depends on the EJB server. The following table shows sample string values. See the documentation for your server for more information.
Server |
INITIAL_CONTEXT_FACTORY value |
---|---|
EAServer |
com.sybase.ejb.InitialContextFactory |
WebLogic |
weblogic.jndi.WLInitialContextFactory |
WebSphere |
com.ibm.websphere.naming.WsnInitialContextFactory |
The following script shows a connection to EAServer. It sets connection properties to create an initial context, to identify the host name and port number of the server, and to identify the user ID and password.
Then, the script creates an instance of the EJBConnection object, invokes the ConnectToServer method to establish a connection to the server, and checks for errors:
ejbconnection conn string properties[] properties[1]="javax.naming.Context.INITIAL_CONTEXT_FACTORY= com.sybase.ejb.InitialContextFactory" properties[2]="javax.naming.Context.PROVIDER_URL=iiop://myejbserver:9000" properties[3]="javax.naming.Context.SECURITY_PRINCIPAL=jagadmin" properties[4]="javax.naming.Context.SECURITY_CREDENTIALS=" conn = CREATE ejbconnection TRY conn.connectToServer(properties) CATCH (exception e) MessageBox("exception", e.getmessage()) END TRY
When your application has finished using the EJB server, it should disconnect from the server:
conn.disconnectserver()