Connecting to the server
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.
Class path requirements
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”.
Setting the initial context
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 |
Example
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.
IIOPS IIOPS connections are not currently supported.
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:
1 |
ejbconnection conn<br />string properties[]<br /><br />properties[1]="javax.naming.Context.INITIAL_CONTEXT_FACTORY= com.sybase.ejb.InitialContextFactory"<br />properties[2]="javax.naming.Context.PROVIDER_URL=iiop://myejbserver:9000"<br />properties[3]="javax.naming.Context.SECURITY_PRINCIPAL=jagadmin"<br />properties[4]="javax.naming.Context.SECURITY_CREDENTIALS="<br /><br />conn = CREATE ejbconnection<br />TRY<br /> conn.connectToServer(properties)<br />CATCH (exception e)<br /> MessageBox("exception", e.getmessage())<br />END TRY |
Disconnecting from the server
When your application has finished using the EJB server, it
should disconnect from the server:
1 |
conn.disconnectserver() |