In WebSphere® Application Server, the following exception might occur when an application attempts to do a Java™ Naming and Directory Interface (JNDI) lookup of a queue connection factory that is defined under the WebSphere MQ Java Message Service (JMS) provider:
java.lang.ClassCastException: com/ibm/ejs/jms/JMSConnectionFactoryHandle incompatible with javax/jms/QueueConnectionFactory
The ClassCastException occurs when a queue connection factory is defined as a WebSphere MQ Connection Factory instead of a WebSphere MQ Queue Connection Factory.
The application code is similar to the following example:
javax.jms.QueueConnectionFactory myQCF = null;
InitialContext ic = null;
//... setup InitialContext here ...
myQCF = (QueueConnectionFactory)ic.lookup("jms/myQCF");
Resolving The Problem
You can resolve the problem using one of the following methods:
- Define the queue connection factory as a WebSphere MQ Queue Connection Factory.
- Use a javax.jms.ConnectionFactory object in the application code rather than a javax.jms.QueueConnectionFactory object.
15 June 2018