Write the applet application client

The code used by an applet to communicate to an enterprise bean is the same as that used by a Java thin application client or a servlet.

No tooling support exists to develop, assemble or deploy this type of client. You are responsible for developing the applet, generating the necessary client bindings for the enterprise beans and CORBA objects, and bundling these pieces together to install or download to the client machine. The Java applet client provides the necessary run time to support communication between the client and the server.

Client side bindings are generated with the application assembly tool. An applet can utilize these bindings, or you can generate client side bindings using the rmic command that is part of the IBM Developer Kit for Java.

This code snippet illustrates how Java thin client applications, servlets, and applets specify the provider URL when they initialize an instance of the InitialContext class. The provider URL and naming factory are passed into the applet as parameters from the HTML page that embeds the applet.

  // Get the parameter for java.naming.provider.url from the HTML
  // For example: java.naming.provider.url = iiop://myhost:bootstrap-port
  providerUrl = getParameter( "java.naming.provider.url" );

  // Get the parameter for java.naming.factory.initial from the HTML. For example:
  // java.naming.factory.initial = com.ibm.websphere.naming.WsnInitialCOntextFactory
  namingFactory = getParameter( "java.naming.factory.initial" );
    
  // Get the JNDI context for our EJB Server
  Properties p = new Properties();

  // Supply the provider url of the server
  p.put( javax.naming.Context.PROVIDER_URL, providerUrl );
    
  // Supply the initial context factory
  p.put( javax.naming.Context.INITIAL_CONTEXT_FACTORY, namingFactory );
  
  initialContext = new javax.naming.InitialContext( p );

Because the Applet client does not provide for a deployment descriptor, the applet code cannot make use of the Java Naming and Directory Interface (JNDI) java:/comp lookup. The applet must know the fully qualified location of the enterprise bean in the JNDI namespace.

  java.lang.Object ejbHome = initialContext.lookup
    ("the/fully/qualified/path/to/actual/home/in/namespace/MyEJBHome");

  MyEJBHome = (MyEJBHome)javax.rmi.PortableRemoteObject.narrow(ejbHome,
    MyEJBHome.class);

To determine the fully qualified path name, look at the JNDI name field on the Binding tab for the enterprise beans in the application assembly tool.

The applet environment restricts access to external resources from the browser runtime environment. You can make some of these resources available to the applet by setting the correct security policy settings in the WAS client.policy file. If given the correct set of permissions, the applet client must explicitly create the connection to the resource using the appropriate API. This client does not perform initialization of any service that the client applet can need. For example, the client application is responsible for the initialization of the naming service, either through CosNaming or Java Naming and Directory Interface (JNDI) APIs.

See the Writing Applets Tutorial Link outside Information Center from Sun Microsystems for more information on writing Java applets.