|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
getting classcast exception in JMS |
« View previous topic :: View next topic » |
Author |
Message
|
aninair |
Posted: Mon Jan 17, 2005 10:11 pm Post subject: getting classcast exception in JMS |
|
|
 Novice
Joined: 30 Oct 2002 Posts: 10
|
Hello,
We are using Websphere 5.1 for developing J2EE application which uses JMS for one of its module. We configured TopicConnectionFactory and Topic in WebSphere JMS Provider. The attached JSP (test.jsp,testRec.jsp)files are used to test the basic operations of Publishing and Subscribing and it works fine.
But when we try to subscribe it from standalone Java program we get ClassCastException. Please find the attached path-classpath.txt which contains the classpath/path set for the environment from which we are executing standalone JMS client.
The sample program which is used to test the subscription is attached.(SimpleTopicSubscriber.java).
CLASSPATH:
CLASSPATH=D:\Program Files\IBM\WebSphere MQ\Java\lib\providerutil.jar;D:\Program Files\IBM\WebSphere
MQ\Java\lib\com.ibm.mqjms.jar;D:\Program Files\IBM\WebSphere MQ\Java\lib\ldap.jar;D:\Program Files\
IBM\WebSphere MQ\Java\lib\jta.jar;D:\Program Files\IBM\WebSphere MQ\Java\lib\jndi.jar;D:\Program Fil
es\IBM\WebSphere MQ\Java\lib\jms.jar;D:\Program Files\IBM\WebSphere MQ\Java\lib\connector.jar;D:\Pro
gram Files\IBM\WebSphere MQ\Java\lib\fscontext.jar;D:\Program Files\IBM\WebSphere MQ\Java\lib\com.ib
m.mq.jar;D:\Program Files\WebSphere\App;D:\Program Files\WebSphere\AppServer\lib\namingclient.jar;D:
\Program Files\WebSphere\AppServer\properties;.;D:\Program Files\WebSphere\AppServer\lib\naming.jar
ERROR:
76 61 78 2e 6e 61 6d 69 6e 67 2e 52 65 66 65
72 65 6e 63 65 ffffffe8 ffffffc6 ...
JNDI API lookup failed: java.lang.ClassCastException: javax.naming.Reference
java.lang.ClassCastException: javax.naming.Reference
at com.ibm.rmi.javax.rmi.PortableRemoteObject.getObjectImpl(PortableRemoteObject.java:626)
at com.ibm.rmi.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:371)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:156)
at SimpleTopicSubscriber.main(SimpleTopicSubscriber.java:61)
Exception in thread "P=820047:O=0:CT" java.lang.NullPointerException
at SimpleTopicSubscriber.main(SimpleTopicSubscriber.java:8
SimpleTopicSubscriber.java:
import javax.jms.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.io.*;
import java.util.Hashtable;
//import com.ibm.websphere.naming.WsnInitialContextFactory;
public class SimpleTopicSubscriber
{
/**
* Main method.
*
* @param args the topic used by the example
*/
public static void main(String[] args)
{
String topicName = null;
Context jndiContext = null;
TopicConnectionFactory topicConnectionFactory = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicSubscriber topicSubscriber = null;
TextMessage message = null;
//TextListener topicListener = null;
try {
Hashtable h = new Hashtable();
h.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
h.put(Context.PROVIDER_URL,"iiop://localhost:2809");
jndiContext = new InitialContext(h);
} catch (NamingException e) {
System.out.println("Could not create JNDI API " +
"context: " + e.toString());
e.printStackTrace();
}
/*
* Look up connection factory and topic. If either does
* not exist, exit.
*/
try {
Object o = (Object)jndiContext.lookup("JMS/ETFC");
System.out.println("got topicI"+o);
PortableRemoteObject.narrow(o,javax.jms.TopicConnectionFactory.class);
topicConnectionFactory = (javax.jms.TopicConnectionFactory)o;
//PortableRemoteObject.narrow(o,TopicConnectionFactory.class);
topicConnectionFactory = (TopicConnectionFactory)
jndiContext.lookup("JMS/ETFC");
topic = (Topic) jndiContext.lookup("JMS/enkiDes");
System.out.println("got topic");
} catch (Exception e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
e.printStackTrace();
}
/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create subscriber.
* Register message listener (TextListener).
* Receive text messages from topic.
* When all messages have been received, enter Q to quit.
* Close connection.
*/
try {
topicConnection =
topicConnectionFactory.createTopicConnection();
System.out.println("got topicConnection");
topicSession =
topicConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
System.out.println("got topicSession");
topicSubscriber =
topicSession.createSubscriber(topic);
System.out.println("got topicSubscriber");
topicConnection.start();
//topicListener = new TextListener();
// topicSubscriber.setMessageListener(topicListener);
//System.out.println("Message is "+topicSubscriber.receive().toString());
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
if (topicConnection != null) {
try {
topicConnection.close();
} catch (JMSException e) {}
}
}
}} _________________ anita nair |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jan 18, 2005 4:30 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
you are missing a few jars from the MQ classpath like rmm.jar etc...
The problem you are hitting has to do with the definition of your initial context and the jars from the apps server as defined on your classpath.
Do your context lookup JMS/ETFC and printout the class
Code: |
Object obj = jndiContext.lookup("JMS/ETFC");
System.out.println(obj.getClass().getName()); |
This way you will know a little bit more about what you got.
Enjoy |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|