Announcement Announcement Module
Collapse
No announcement yet.
InvocationTargetException in jmsTemplate.send & createConnection is NoSuchMethodError Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • InvocationTargetException in jmsTemplate.send & createConnection is NoSuchMethodError

    Hi, I've been trying to send a message using JMS but I keep encountering an error once it gets to jmsTemplate.send(...)
    I've tried tracing it and it seems to me it triggers the createConnection() method and receives a NoSuchMethod exception. Can anyone provide an explanation on why is that? I'm using a JNDI binding file, ibm mq, jms, spring 2.0.x, struts 1,3 and java 1.4.

    Edit: I know that jmsTemplate.send keeps automatically using .createConnection when called and that produces the NoSuchMethod exception since the targetConnectionFactory pretty much is a QueueConnectionFactory. Anyone has any idea how do I make jmsTemplate.send use createQueueConnection instead?
    Thank You.

    error trace:
    Code:
    13:49:57,515 ERROR | [DispatchAction] | Dispatch[/myaction] to method 'send' returned an exception
    java.lang.reflect.InvocationTargetException
    	at jrockit.reflect.NativeMethodInvoker.invoke0(Ljava.lang.Object;ILjava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
    	at jrockit.reflect.NativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
    	at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
    	at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
    	at org.apache.struts.actions.DispatchAction.dispatchMethod(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;Ljava.lang.String;)Lorg.apache.struts.action.ActionForward;(DispatchAction.java:274)
    	at com.my.core.web.BaseDispatchAction.dispatchMethod(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;Ljava.lang.String;)Lorg.apache.struts.action.ActionForward;(BaseDispatchAction.java:107)
    	at org.apache.struts.actions.DispatchAction.execute(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)Lorg.apache.struts.action.ActionForward;(DispatchAction.java:194)
    	at com.my.core.web.BaseDispatchAction.execute(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)Lorg.apache.struts.action.ActionForward;(BaseDispatchAction.java:243)
    	at com.my.core.web.BaseDispatchAction$$FastClassByCGLIB$$78de1cd6.invoke(ILjava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(<generated>:0)
    	at net.sf.cglib.proxy.MethodProxy.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(MethodProxy.java:149)
    	at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint()Ljava.lang.Object;(Cglib2AopProxy.java:698)
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed()Ljava.lang.Object;(ReflectiveMethodInvocation.java:148)
    	at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(Lorg.aopalliance.intercept.MethodInvocation;)Ljava.lang.Object;(AfterReturningAdviceInterceptor.java:51)
    	.......
    	
    	Caused by: java.lang.NoSuchMethodError: createConnection
    	at org.springframework.jms.core.JmsTemplate.createConnection()Ljavax.jms.Connection;(JmsTemplate.java:760)
    	at org.springframework.jms.core.JmsTemplate.execute(Lorg.springframework.jms.core.SessionCallback;Z)Ljava.lang.Object;(JmsTemplate.java:420)
    	at org.springframework.jms.core.JmsTemplate.send(Ljava.lang.String;Lorg.springframework.jms.core.MessageCreator;)V(JmsTemplate.java:486)
    	at com.my.sender.QueueSender.sendMessage(Ljava.lang.String;Lcom.my.sender.MsgToXMLStringConverter;)V(QueueSender.java:53)
    	at com.my.MyAction.sendMessage(Ljava.lang.String;Ljava.lang.String;Lcom.my.sender.MsgToXMLStringConverter;)V(MyAction.java:126)
    	at com.my.MyAction.send(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)Lorg.apache.struts.action.ActionForward;(MyAction.java:100)
    	at jrockit.reflect.NativeMethodInvoker.invoke0(Ljava.lang.Object;ILjava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
    	at jrockit.reflect.NativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
    	at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
    	at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
    	at org.apache.struts.actions.DispatchAction.dispatchMethod(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;Ljava.lang.String;)Lorg.apache.struts.action.ActionForward;(DispatchAction.java:274)
    	at com.my.core.web.BaseDispatchAction.dispatchMethod(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;Ljava.lang.String;)Lorg.apache.struts.action.ActionForward;(BaseDispatchAction.java:107)
    	at org.apache.struts.actions.DispatchAction.execute(Lorg.apache.struts.action.ActionMapping;Lorg.apache.struts.action.ActionForm;Ljavax.servlet.http.HttpServletRequest;Ljavax.servlet.http.HttpServletResponse;)Lorg.apache.struts.action.ActionForward;(DispatchAction.java:194)
    ...
    applicationContextSender.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans default-lazy-init="true">
        <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
            <property name="environment">
                <props>
                    <prop key="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</prop>
                    <prop key="java.naming.provider.url">file:Sender/</prop>
                </props>
            </property>
        </bean>
    
        <bean id="qConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiTemplate" ref="jndiTemplate"/>
            <property name="jndiName" value="someNameHere" />
        </bean>
    
    
        <bean id="secureQConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
            <property name="targetConnectionFactory" ref="qConnectionFactory"/>
            <property name="username" value="${sender.username}"/>
            <property name="password" value="${sender.password}"/>
        </bean>
    
    
        <bean id="destResolver"  class="org.springframework.jms.support.destination.JndiDestinationResolver">
            <property name="jndiTemplate" ref="jndiTemplate"/>
            <property name="cache" value="true" />
        </bean>
    
        <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
            <property name="connectionFactory" ref="secureQConnectionFactory" />
            <property name="pubSubDomain" value="false" />
            <property name="destinationResolver" ref="destResolver" />
        </bean>
    
    
        <bean id="queueSender" class="com.my.sender.QueueSender" lazy-init="true">
            <property name="jmsTemplate" ref="jmsTemplate" />
        </bean>
    
    </beans>
    QueueSender.java
    Code:
    package com.my.sender;
    
    import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter;
    import org.springframework.jms.core.JmsTemplate;
    import org.springframework.jms.core.MessageCreator;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    import javax.jms.Message;
    import javax.jms.Session;
    import javax.jms.JMSException;
    import com.my.sender.MsgToXMLStringConverter;
    
    
    public class QueueSender {
        private static Log log = LogFactory.getLog(QueueSender.class);
    
        private JmsTemplate jmsTemplate;
    
    
        public JmsTemplate getJmsTemplate() {
            return jmsTemplate;
        }
    
        public void setJmsTemplate(JmsTemplate jmsTemplate) {
            this.jmsTemplate = jmsTemplate;
        }
    
        public void sendMessage(String qName, MsgToXMLStringConverter message) {
    
    
            final String strMsg = message.getMessage();
    
            this.jmsTemplate.send(qName,new MessageCreator() {
        	    public Message createMessage(Session session) throws JMSException {
        	        return session.createTextMessage(strMsg);
        	    }});
        }
    }
    Last edited by megitsune; Apr 29th, 2010, 09:10 PM.

  • #2
    In case anyone's wondering on the solution, there was a conflict between the weblogic.jar and jms.jar. Made the jms.jar run first before the weblogic.jar and all's well in the world.

    Comment

    Working...
    X