InfoCenter Home > 4.7.1.1: Developing an Applet clientUnlike 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:
Tag requirementsStandard 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:
<EMBED>
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:
Code requirementsThe 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:
Security requirementsWhen 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:
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.
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
|