-
1. Re: Applet getting ClassCastException on lookup
cholliday Jan 29, 2002 8:50 AM (in response to cholliday)Nevermind I got to work with Netscape browser.
-
2. Re: Applet getting ClassCastException on lookup
mtags Mar 11, 2002 6:30 PM (in response to cholliday)I am having the same problem
import java.applet.Applet;
import java.awt.Graphics;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicConnection;
import javax.jms.Session;
import javax.jms.Topic;
import javax.jms.TopicSubscriber;
import javax.jms.TopicSession;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;
import javax.jms.MessageListener;
public class LatencyApplet extends Applet
{
Graphics g = null;
String error = "er ";
public void init()
{
Hashtable props = new Hashtable();
try
{
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL, "localhost:1099");
props.put("java.naming.rmi.security.manager", "yes");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
Context context = new InitialContext(props);
error += "created context\r\n";
TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup("UILConnectionFactory");
error += "created topic factory\15\12";
TopicConnection topicConnection = topicFactory.createTopicConnection();
error += "created topic connection\15\12";
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)context.lookup("topic/heartbeat");
TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);
topicSubscriber.setMessageListener(new MsgListener());
topicConnection.start();
}
catch(NamingException eNAM)
{
error += eNAM.getMessage();
}
catch(JMSException eJMS)
{
error += "JMS ERROR ";
//error += eJMS.getLocalizedMessage();
}
}
public void paint(Graphics g)
{
try
{
g.drawString(error, 100, 100);
for(int i = 0; i < 100; i++)
{
g.drawString(String.valueOf(Latency.getLatency()), 25, 25);
Thread.sleep(1000);
}
}
catch(Exception e)
{
}
}
}
Help -
3. Re: Applet getting ClassCastException on lookup
cholliday Mar 12, 2002 8:41 AM (in response to cholliday)I am not sure what I had to do to get that working. My code now looks like this though.
Properties jndiProps = new Properties() ;
jndiProps.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory" ) ;
jndiProps.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces" ) ;
jndiProps.setProperty("java.naming.provider.url", "myhostname.mynetwork.com:1099" ) ;
Context context = new InitialContext(jndiProps);
TopicConnectionFactory topicFactory =
(TopicConnectionFactory)context.lookup("RMIConnectionFactory");
topicConnection = topicFactory.createTopicConnection();
topicSession = topicConnection.createTopicSession(
false, Session.AUTO_ACKNOWLEDGE);
topic = (Topic)context.lookup("topic/application");
topicSubscriber = topicSession.createSubscriber(topic);
topicSubscriber.setMessageListener(msgListener);
topicConnection.start();
And I have a jndi.properties file in my applet directory that looks like this
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jnp.interfaces
java.naming.provider.url=localhost
You also have to make sure your applet includes the archive jar's in your html file.
<APPLET CODE = "YourApplet.class" CODEBASE="/prdjar/" ARCHIVE = "./jbossmq-client.jar,
./jboss-client.jar, ./sl2.jar, ./jboss-j2ee.jar, ./jbosssx-client.jar, ./jnp-client.jar, ./jndi.jar,
./jaas.jar, ./log4j.jar" WIDTH = 800 HEIGHT = 400>
Let me know if this helps
Christian -
4. Re: Applet getting ClassCastException on lookup
mtags Mar 12, 2002 10:34 AM (in response to cholliday)I figured out my problem. I mistyped the file name of one of the .jar files that I needed in the applet tag in my html.