ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » unable to get connection using JNDI

Post new topic  Reply to topic
 unable to get connection using JNDI « View previous topic :: View next topic » 
Author Message
hi.riyazkhan
PostPosted: Fri Aug 24, 2012 5:38 am    Post subject: unable to get connection using JNDI Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Fri Aug 24, 2012 5:53 am    Post subject: Reply with quote

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
View user's profile Send private message
hi.riyazkhan
PostPosted: Fri Aug 24, 2012 6:08 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Fri Aug 24, 2012 6:14 am    Post subject: Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Fri Aug 24, 2012 6:14 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Grand Master just means "posts way too much".

Otherwise, yes.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » unable to get connection using JNDI
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.