Link to home
Start Free TrialLog in
Avatar of GTsafas
GTsafas

asked on

Java Applet - Javascript Function

Hello, I am trying to create an applet to talk to activeMQ. I have tested the applet at compile time and it connects successfully and produces the messages. However when I try to embed it on a html page and have it call a JS function it is failing and not giving me a warning. Can someone take a look? Code below. This also requires two JAR files
--Java Applet--

import java.applet.*;
import java.net.*;
import javax.jms.*;
import org.apache.activemq.ActiveMQConnectionFactory;

@SuppressWarnings("serial")
public class Producer extends Applet{
  public void init(){
  
      try {
      	ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://gt-pc1.rsi.com:61616");
      	Connection connection = factory.createConnection(); 
      	Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      	Topic topic = session.createTopic("TestTopic");
      	MessageProducer publisher = session.createProducer(topic);
      	publisher.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      	
      	connection.start();

	  
	  
    	for(int x=0;x<5;x++){
    		TextMessage message = session.createTextMessage("Test message "+x);
    		 
    		String msg = message.getText();
    		try {
    				getAppletContext().showDocument(new URL("javascript:doAlert(\"" + msg +"\")"));
    		}
    			catch (MalformedURLException me) {}
    		
    		publisher.send(message);
    	}
    	
    	connection.stop();
    	connection.close();
      } catch (JMSException e) {
    	  
      }
  
  }
}

------------

--HTML with JS--

<HTML><HEAD></HEAD><BODY>
<SCRIPT>
function doAlert(s) {
   alert(s);
   }

</SCRIPT>
<APPLET CODE="Producer.class"
        NAME="ProducerApp"  MAYSCRIPT codebase="." archive="activemq-all-5.1.0.jar,javaee.jar"
        HEIGHT=100 WIDTH=100>
</APPLET>
</BODY>
</HTML>

Open in new window

Avatar of contactkarthi
contactkarthi
Flag of United States of America image

Avatar of GTsafas
GTsafas

ASKER

The problem isnt hitting the function. When I disable the activeMQ stuff and jms so I dont need the JAR's it hits the JS function fine. I tested this on Chrome/IE.

When I run it from eclipse or linux shell it connects to activeMQ Fine. Im stumped
Have a look in the Java Applet console and post the debug trace
Avatar of GTsafas

ASKER

There is no output. Its not complaining at all once I include the JAR's
Avatar of GTsafas

ASKER

here when I dont include jars
Exception in thread "thread applet-Consumer.class-1" java.lang.ExceptionInInitializerError
	at org.apache.activemq.ActiveMQPrefetchPolicy.<clinit>(ActiveMQPrefetchPolicy.java:30)
	at org.apache.activemq.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:89)
	at org.apache.activemq.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:123)
	at Consumer.init(Consumer.java:11)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission org.apache.commons.logging.LogFactory.HashtableImpl read)
	at java.security.AccessControlContext.checkPermission(Unknown Source)
	at java.security.AccessController.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
	at java.lang.System.getProperty(Unknown Source)
	at org.apache.commons.logging.LogFactory.createFactoryStore(LogFactory.java:320)
	at org.apache.commons.logging.LogFactory.<clinit>(LogFactory.java:1725)
	... 6 more
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/jms/JMSException
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/jms/JMSException
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
	at java.lang.Class.getConstructor0(Unknown Source)
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.jms.JMSException
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 14 more
Caused by: java.io.IOException: open HTTP connection failed:http://gt-pc1.rsi.com/applet/javax/jms/JMSException.class
	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 17 more
Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/jms/JMSException

Open in new window

Avatar of GTsafas

ASKER

Sorry I was able to produce a log.


basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@df1832
cache: Skip blacklist check as cached value is ok.
network: Cache entry found [url: http://gt-pc1.rsi.com/applet/activemq-all-5.1.0.jar, version: null] prevalidated=false/0
network: Connecting http://gt-pc1.rsi.com/applet/activemq-all-5.1.0.jar with proxy=DIRECT
network: Connecting http://gt-pc1.rsi.com:80/ with proxy=DIRECT
network: ResponseCode for http://gt-pc1.rsi.com/applet/activemq-all-5.1.0.jar : 304
network: Encoding for http://gt-pc1.rsi.com/applet/activemq-all-5.1.0.jar : null
network: Disconnect connection to http://gt-pc1.rsi.com/applet/activemq-all-5.1.0.jar
cache:  Read manifest for http://gt-pc1.rsi.com/applet/activemq-all-5.1.0.jar: read=121 full=121
cache: Skip blacklist check as cached value is ok.
network: Cache entry found [url: http://gt-pc1.rsi.com/applet/javaee.jar, version: null] prevalidated=false/0
network: Connecting http://gt-pc1.rsi.com/applet/javaee.jar with proxy=DIRECT
network: Connecting http://gt-pc1.rsi.com:80/ with proxy=DIRECT
network: ResponseCode for http://gt-pc1.rsi.com/applet/javaee.jar : 304
network: Encoding for http://gt-pc1.rsi.com/applet/javaee.jar : null
network: Disconnect connection to http://gt-pc1.rsi.com/applet/javaee.jar
cache:  Read manifest for http://gt-pc1.rsi.com/applet/javaee.jar: read=210 full=210
network: CleanupThread used 2 us
network: CleanupThread used 1 us
network: Cache entry found [url: http://gt-pc1.rsi.com/applet/Consumer.class, version: null] prevalidated=false/0
network: Connecting http://gt-pc1.rsi.com/applet/Consumer.class with proxy=DIRECT
network: Connecting http://gt-pc1.rsi.com:80/ with proxy=DIRECT
network: ResponseCode for http://gt-pc1.rsi.com/applet/Consumer.class : 304
network: Encoding for http://gt-pc1.rsi.com/applet/Consumer.class : null
network: Disconnect connection to http://gt-pc1.rsi.com/applet/Consumer.class
network: Cache entry not found [url: http://gt-pc1.rsi.com/applet/, version: null]
network: No certificate info for unsigned JAR file: http://gt-pc1.rsi.com/applet/activemq-all-5.1.0.jar
basic: Applet loaded.
basic: Applet resized and added to parent container
basic: PERF: AppletExecutionRunnable - applet.init() BEGIN ; jvmLaunch dt 473200 us, pluginInit dt 133648612 us, TotalTime: 134121812 us
basic: Removed progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@df1832
Exception in thread "thread applet-Consumer.class-3" java.lang.ExceptionInInitializerError
	at org.apache.activemq.ActiveMQPrefetchPolicy.<clinit>(ActiveMQPrefetchPolicy.java:30)
	at org.apache.activemq.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:89)
	at org.apache.activemq.ActiveMQConnectionFactory.<init>(ActiveMQConnectionFactory.java:123)
	at Consumer.init(Consumer.java:11)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission org.apache.commons.logging.LogFactory.HashtableImpl read)
	at java.security.AccessControlContext.checkPermission(Unknown Source)
	at java.security.AccessController.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPermission(Unknown Source)
	at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
	at java.lang.System.getProperty(Unknown Source)
	at org.apache.commons.logging.LogFactory.createFactoryStore(LogFactory.java:320)
	at org.apache.commons.logging.LogFactory.<clinit>(LogFactory.java:1725)
	... 6 more

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of contactkarthi
contactkarthi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you'll find you need to sign all code (including every jar)
contactkarthi is correct, ActiveMQ needs to be signed to run in an applet

The following has instructions to self sign a jar. Bear in mind that a self signed jar may not be trusted in the wild and you may need to purchase a certifcate in that case
http://helpdesk.objects.com.au/java/how-to-self-sign-a-jar

Another option instead of signing would be to change the security policyy file, thats discussed here and shows you what to do
http://it.toolbox.com/blogs/enterprise-web-solutions/applet-and-jms-using-glassfish-and-jdk-6-34816

You may also need to use a privileged block once you get past that error
http://helpdesk.objects.com.au/java/my-signed-applet-is-throwing-an-accesscontrolexception
Avatar of GTsafas

ASKER

Sorry was away. Came to this same conclusion on my own
ActiveMQ needs to be signed to run in an applet

I think I'm having the same issue. Confused about what specifically needs to be signed -- activemq-all-5.7.0.jar ?