Show TOC Start of Content Area

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

Use

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

Procedure

Binding the Implementation from a J2EE Engine Component

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

Syntax

try  {

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

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

} catch (NamingException ne) {

  ne.printStackTrace();

}

Binding the Implementation from a Remote Client

...

       1.      Instantiate the remote object’s implementation class.

       2.      Bind it to the J2EE Engine’s Naming System from the client JVM.

Example

The BankServer class below is a remote client that binds the AccountImpl class to the J2EE Engine’s Naming System.

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 InitialContext properties.

      Properties p = new Properties();

      // Specify the type of the InitialContext 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 using the InitialContext.

      Context initialContext = new InitialContext(p);

      initialContext.rebind("Bank", obj);

 

    } catch (Exception e) {

      e.printStackTrace();

    }

  }

}

 

 

End of Content Area