Entering content frame

Procedure documentation Binding the Implementation to the Naming System Locate the document in its SAP Library structure

The implementation of the remote object can be bound to the naming system by a component that runs on the SAP J2EE Engine (either a service, or an application), or bind it from a client residing in a different JVM.

Binding the Implementation from an SAP J2EE Engine Component

To do this for the AccountImpl class, you must add the following try clause after the implementation of its methods:

This graphic is explained in the accompanying text

try   {

  javax.naming.Context ctx = new InitialContext();

  ctx.rebind(“Bank”, new AccountImpl());

} catch (NamingException ne) {

  ne.printStackTrace();

}

Binding the Implementation from a Remote Client

The BankServer class is an example of a client that first instantiates the AccountImplclass, and then binds it to the SAP J2EE Engine Naming System from the client JVM.

This graphic is explained in the accompanying text

package exapmles.rmi_p4;

 

import javax.naming.Context;

import javax.naming.InitialContext;

import java.util.Properties;

 

public class BankServer {

  public static void main(String[] args) {

    try {

      if (args.length < 4) {

        System.out.println(" Use: BankClient <hostName> <port> <user> <pass>");

        return;

      }

      AccountImpl obj = new AccountImpl();

      // Create the initial context properties.

      Properties p = new Properties();

      // Specify the type of the initial context factory.

      p.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");

      // Specify the provider URL.

      p.put(Context.PROVIDER_URL, args[0] + ":" + args[1]);

      // Specify the security principal (user).

      p.put(Context.SECURITY_PRINCIPAL, args[2]);

      // Specify the security credentials (password).

      p.put(Context.SECURITY_CREDENTIALS, args[3]);

 

      // Connect to the server by the initial context.

      Context initialContext = new InitialContext(p);

      initialContext.rebind("Bank", obj);

 

    } catch (Exception e) {

      e.printStackTrace();

    }

  }

}

 

 

Leaving content frame