DevPortal

How do I access Embedded Message Servers from Applets?


Table of Contents


How do I access Embedded Message Servers from Applets?

To access the Message Server from an applet your browsers should have a Java plug-in version j2sdk1.4.2_10 or higher. The plug-in can be found at the plug-in home page of java.sun.com. If the plug-in is not installed, go to the plug-in home page of the site java.sun.com and download and install the plug-in for your browser. The plug-in is required for security related implementations within the .jar files.

Add the following jar files from the lib/std folder, lib/pramati, and lib/client folder to the directory in which the applet is kept:

jms.jar, jmxri.jar, jta.jar, pramati_jta.jar, pramati_jms_client.jar, pramati_jms_xa.jar,
pramati_naming.jar, pramati_security.jar, pramati_spi.jar, pramati_util.jar, xml.jar
The html file has the <object> and <embed> tags as described in the Java plug-in homepage on java.sun.com. The following tag snippet is from the source code of the html file:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="200" height="200" align="baseline"
 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
<param name="comIPersistStreamData" value>
<embed type="application/x-java-applet;version=1.3" width="200" height="200" align="baseline" code="AppletClientReceiver.class" pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"  archive="jms.jar,jmxri.jar,xml.jar,pramati_jms_client.jar,pramati_naming.jar, pramati_util.jar,pramati_jta.jar,jaas.jar,jta.jar,pramati_security.jar,pramati_spi.jar">
<noembed>
</COMMENT>No Java 2 SDK, Standard Edition v 1.3 support for APPLET!!
</noembed>
</OBJECT>

This tag loads the appropriate plug-in depending on the browser. The class files and jar files have been mentioned under the corresponding tags.

The critical sections of code in the applet class are:

java.util.Properties env = new java.util.Properties();
env.put("java.naming.factory.initial",
  "com.pramati.naming.client.PramatiClientContextFactory");
env.put("java.naming.provider.url","rmi://<IP>:<port>");
ic = new InitialContext(env);

This code gets the Initial Context.

queueConnectionFactory= (QueueConnectionFactory)ic.lookup("JMSQueueConnectionFactory");
queue= (Queue)ic.lookup("JMSQueue");
queueConnection= queueConnectionFactory.createQueueConnection();
queueConnection.start();
queueSession= queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
queueSender= queueSession.createSender(queue);
TextMessage txtMsg= queueSession.createTextMessage();
txtMsg.setText("This message is coming from an Applet");
queueSender.send(txtMsg, DeliveryMode.NON_PERSISTENT, 4, 0);
System.out.println("Message sent is : This message is coming from an Applet");
queueSession.close();
queueConnection.close();

This is the sample code used in all the samples for getting a connection to the QueueConnectionFactory, creating a QueueSession, creating a text message, sending the message and closing the session and connection objects. This code is a part of the init() method of the Applet class.

How do I deploy Applets?

The assumption in deployment of applets is that all the files will be placed anywhere on the same machine in the same directory. If the server is on a different machine, modify the JNDI look up string in applet class. The codebase from where the applet is being loaded in the browser has to be given all security permissions to be accessed from the browser.

To deploy applets:

  1. Go to the bin directory of the browser plug-in root directory. This can be found from the registry entry under JavaSoft in Windows NT/2000/98 operating systems. The plug-in, by default, will be stored in the directory C:\program files\javasoft
  2. On a new DOS window, go to the Plugin directory, and start the policy tool from the command line by giving the command: policytool
  3. select File > Open > New. Select Add Policy Entry.
  4. In the codebase text field, add the file path of the applet folder after file:/ and add /- after the path. Make sure that all the File.separators are '/' in case of Windows NT or 2000. If your code base is in the directory c:/jms/samples/applet, your entry in the text field would be: file:/c:/jms/samples/applet/-
  5. Click Add Permissions.
  6. Select All Permissions and click OK.
  7. Click Done. This closes the window and brings up another window.
  8. Select File > Save and save file to the hard disk as, say, c:/jms/my.policy. Similarly grant java.lang.RuntimePermission to all code base for accessClassInPackage.sun.rmi.server
  9. Open the java.security file of the plugin, generally available in lib/security directory of the installation directory of your Java plugin. Go to: policy.url.1=file:${java.home}/lib/security/java.policy policy.url.2=file:${user.home}/.java.policy and add the following line: policy.url.3=file:c:/jms/my.policy. This assumes that my.policy has been saved in the above directory. Save the file.
  10. Open the Plugins control panel. The panel can be launched by selecting Start > Settings > ControlPanel on Windows. On Solaris/Unix/Linux machines, the panel can be launched by using the command JavaPluginControlPanel
  11. On the plug-ins property panel, select the Show Java Console check-box (if not already selected) and click Apply.
  12. Copy the file jaas.jar that comes with the Message Server installaton, to the lib/ext directory JRE in the installation directory of the plug-in.
The Applet Client is ready to run.

How do I access Applets?

Start the Message Server. Go to your browser and load the receiver html file, and then the sender HTML file. The Java console of the browser opens up, and displays the message sent by the sender and received by the receiver.

Pramati Message Server can also be accessed by the following clients:


© Pramati Technologies 2007 Runs on Pramati Server | Feedback | Legal