InfoCenter Home >
4: Developing applications >
4.7: Java Clients >
4.7.1: Applet client programming model >
4.7.1.1: Developing an Applet client

4.7.1.1: Developing an Applet client

Unlike typical applets that reside on either Web servers or WebSphere Application Servers and can only communicate using the HTTP protocol, the WebSphere Applet clients are capable of communciating over the HTTP protocol and the RMI-IIOP protocol. This additional capability gives the Applet direct access to enterprise java beans. As such, Applet clients have the following setup requirements:

  • These clients are currently available on the Windows NT or Windows 2000 platforms.
    Support for additional platforms will be added in the near future.
    Check the prerequisites page for information on new platform support.
  • They require one of these browsers:
    • Internet Explorer version 5.0+
    • Netscape Navigator 4.7+
  • The browser must be installed before the client code is installed.
  • The Applet client is installed from the WebSphere Clients for Windows CD by selecting option, "Java Application/Applet Thin Client."
  • You must install the WebSphere Application Server Plug-in for the browser. Select option, "Java Application/Applet Thin Client," from the WebSphere Clients for Windows CD.
  • From the WebSphere Application Server Java Plug-in Control, enter:
    -Djava.ext.dirs=\WebSphere\AppClient\lib
    
      
    1. The Java Run Time Parameters field is similar to the command prompt when using command line options. Therefore, most options available from the command prompt (for example, -cp, classpath, and others), can be entered in this field as well.
    2. The control panel can be accessed from the Start menu.
      Click start > control panel > WebSphere Java Plug-in Control.
    3. The applet container is the Web browser and the Java Plug-in combination. You must first install the WebSphere Application Server Applet client so that the browser recognizes the IBM Java Plug-in.

Tag requirements

Standard applets require the HTML <APPLET> tag to identify the applet to the browser. The <APPLET> tag invokes the browser's Java Virtual Machine (JVM). So an applet running on Internet Explorer will use Microsoft's JVM.

For applets to communicate with EJBs in the WebSphere Application Server environment, the <APPLET> tag must be replaced with these two new tags:
    <OBJECT>
    <EMBED>
Additionally, the classid and type attributes cannot be modified, and must be entered as described in the applet client example. Finally, the codebase attribute on the <OBJECT> tag must be excluded.
  Do not confuse the codebase attribute on the <OBJECT> tag with the codebase attribute on the <PARAM> tag. Although both are called codebase, they are separate entities.

The following code snippet illustrates the applet code. In this example, MyApplet.class is the applet code, applet.jar is the file that contains the applet code, and EJB.jar is the file that contains the EJB code:

    <OBJECT classid="clsid:8AE2D840-EC04-11D4-AC77-006094334AA9"
    width="600" height="500">
    <PARAM NAME=CODE VALUE=MyAppletClass.class>
    <PARAM NAME="archive" VALUE='Applet.jar, EJB.jar'>
    <PARAM TYPE="application/x-java-applet;version=1.3">
    <PARAM NAME="scriptable" VALUE="false">
    <PARAM NAME="cache-option" VALUE="Plugin">
    <PARAM NAME="cache-archive" VALUE="Applet.jar, EJB.jar">
    <COMMENT>
    <EMBED type="application/x-websphere-client" CODE=MyAppletClass.class
    ARCHIVE="Applet.jar, EJB.jar" WIDTH="600" HEIGHT="500"
    scriptable="false">
    <NOEMBED>
    </COMMENT>
    </NOEMBED>WebSphere Java Application/Applet Thin Client for
    Windows is required.
    </EMBED>
    </OBJECT>

  The value of the type attribute on the <EMBED> tag can also be:
<EMBED type="application/x-websphere-client, version=4.0" ...

Code requirements

The code used by an applet to talk to an EJB is the same as that used by a standalone Java program or a servlet, except for one additional property called java.naming.applet. This property informs the InitialContext and the ORB that this client is an applet rather than a standalone Java application or servlet.

When initializing an instance of the InitialContext class, the first two lines in this code snippet illustrate what both a standalone Java program and a servlet issue to specify the computer name, domain, and port. In this example, <yourserver.yourdomain.com> is the computer name and domain where WebSphere Application Server resides, and 900 is the configured port. After the bootstrap values (<yourserver.yourdomain.com>:900) are defined, the client to server communications occur within the underlying infrastructure. In addition to the first two lines, for applets, you must add the highlighted third line to your code. That line identifies this program as an applet:

    prop.put(Context.INITIAL_CONTEXT_FACTORY,      "com.ibm.websphere.naming.WsnInitialContextFactory");
    prop.put(Context.PROVIDER_URL, "iiop://<yourserver.yourdomain.com>:900");
    prop.put("java.naming.applet", this);

Security requirements

When code is loaded, it is assigned "permissions" based on the security policy in effect. This policy, specifying which permissions are available for code from various locations, can be initialized from an external policy file. For each client, the java.policy file should be updated with the classes that the applet client needs to access, and with the ports on the host machines where it needs different permissions.

The following lines of code must be added to existing java.policy files. This code allows access to the required ports so that the applet client can communicate with an EJB.

In the example below, the java.net.SocketPermission "localhost:1024--", "listen" entry grants permision for Applets to open sockets for listening on the localhost for any port from 1024 to 65535. Port can be specified as a range of port numbers or a specific port. A port range specification of the form "N-", where N is a port number, signifies all ports numbered N and above. A specification of the form "-N" indicates all ports numbered N and below.

The first SocketPermission statement grants permission to the client to have ports opened for listening. The second grants permission to open a port and make a connection to a host machine, which is your WebSphere Application Server. In this example, yourserver.yourcompany.com is the complete hostname of your WebSphere Application Server:


    permission java.util.PropertyPermission "server.root", "read";
    permission java.util.PropertyPermission "*", "read,write";
    permission java.io.FilePermission "traceSettingsFile", "read,write";
    permission java.util.PropertyPermission "traceSettingsFile", "read,write";
    permission java.lang.RuntimePermission "modifyThread";
    permission java.net.SocketPermission "localhost:1024-", "listen";
    permission java.net.SocketPermission "yourserver.yourcompany.com", connect";

  For more information on security relating to user authentication and signed jars, read the official documentation for Java security architecture

Learn more about the WebSphere Applet client by running the Applet sample. You can install the Applet client sample from the WebSphere Application Client CD. This sample is called HelloEJB and is installed in the product_installation/WSsamples/Client subdirectory on the client machine.

Go to previous article: Applet client programming model Go to next article: J2EE application client programming model

 

 
Go to previous article: Applet client programming model Go to next article: J2EE application client programming model