![]() |
|
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.jarThe 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.
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:
policytoolfile:/c:/jms/samples/applet/-java.lang.RuntimePermission to all code base for accessClassInPackage.sun.rmi.serverjava.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.JavaPluginControlPaneljaas.jar that comes with the Message Server installaton, to the lib/ext directory JRE in the installation directory of the plug-in.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 |