Author |
Message
|
hi.riyazkhan |
Posted: Fri Aug 24, 2012 5:38 am Post subject: unable to get connection using JNDI |
|
|
Newbie
Joined: 18 Jul 2012 Posts: 7
|
Hi I am new to MQ and trying to get the connection using JNDI object present in WMQ 7.
the jndi object is obtained using spring as follows
type of jndi object for mqConnectionFactory defined in web.xml is javax.jms.ConnectionFactory
Code: |
<bean id="mqConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jms/xyz" />
<property name="resourceRef" value="true" />
</bean>
|
the problem occurs when I call createConnection method on the obtained connectionfactory in following code
Code: |
LOGGER.debug("*****Insie get Empty Message");
JMSTextMessage message = null;
MQQueueConnection connection = (MQQueueConnection) mqConnectionFactory.createConnection();
LOGGER.debug("*****Connection for MQ obtained for Empty Message");
MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
message = (JMSTextMessage) session.createTextMessage();
connection.close();
return message;
|
I get the following error
Code: |
com.ibm.ejs.jms.JMSConnectionHandle incompatible with com.ibm.mq.jms.MQQueueConnection
java.lang.ClassCastException: com.ibm.ejs.jms.JMSConnectionHandle incompatible with com.ibm.mq.jms.MQQueueConnection
at xyz.abc.Efgh.getEmptyMQMessage(Efgh.java:162)
at xyz.abc.Jklm.createTransformedMessage(Jklm.java:160)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
|
please let me know if I am missing out something or doing something wrong. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Aug 24, 2012 5:53 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You should be using generic JMS objects - not the MQ specific forms.
So your session should just be a session and not an MQQueueSession.
You'll get back an MQQueueSession under the covers, but you need to ask for a generic session. |
|
Back to top |
|
 |
hi.riyazkhan |
Posted: Fri Aug 24, 2012 6:08 am Post subject: |
|
|
Newbie
Joined: 18 Jul 2012 Posts: 7
|
Thanks a lot for the replay Grand master
I believe same is true in case of MQQueueConnection, which means I should use generic Connection object and not WMQ specific so that I dont get the ClassCastException. Am I correct?? |
|
Back to top |
|
 |
Vitor |
Posted: Fri Aug 24, 2012 6:14 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
hi.riyazkhan wrote: |
I believe same is true in case of MQQueueConnection, which means I should use generic Connection object and not WMQ specific so that I dont get the ClassCastException. |
Why do you just believe this when you were told:
mqjeff wrote: |
You should be using generic JMS objects - not the MQ specific forms |
 _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Aug 24, 2012 6:14 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Grand Master just means "posts way too much".
Otherwise, yes. |
|
Back to top |
|
 |
|