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.

NoteDeprecated for most uses The EJBConnection object is deprecated for use with EAServer and the PowerBuilder Application Server Plug-in. Use the connection object instead.

To establish a connection to the server, you need to execute the PowerScript statements required to perform these operations:

  1. Declare an instance of the EJBConnection class.

  2. Set properties for the EJBConnection object.

  3. Use the CREATE statement to instantiate the EJBConnection object.

  4. Invoke the ConnectToServer method to establish a connection to the server.

  5. 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.

NoteIIOPS 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:

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=admin"
properties[4]="javax.naming.Context.SECURITY_CREDENTIALS="

conn = CREATE ejbconnection
TRY
  conn.connectToServer(properties)
CATCH (exception e)
  MessageBox("exception", e.getmessage())
END TRY

Disconnecting from the server

When your application has finished using the EJB server, it should disconnect from the server:

conn.disconnectserver()