Announcement Announcement Module
Collapse
No announcement yet.
Using Templates exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Templates exception

    Hi,
    I am using Spring3.1 in a standalone env.

    Recently I success integrate my env with Hornetq2.2.

    I am trying to work with jms template but I get this exception. I think the exception is less concerned to jms but more to using of templates in the container.


    Code:
    INFO: HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [b214b899-c50b-11e1-82a9-000ffe939094] started
    
    org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is javax.jms.JMSException: Failed to create session factory; nested exception is java.lang.IllegalArgumentException: Error instantiating connector factory "org.hornetq.integration.transports.netty.NettyConnectorFactory"
    	at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316)
    	at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168)
    	at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469)
    	at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:543)
    	at com.fixgw.server.utils.NotificationsProducer.sendNotification(NotificationsProducer.java:28)
    	at com.fixgw.beans.FeedListenerBean.listen(FeedListenerBean.java:28)
    	at com.fixgw.test.TriggerBean.doTheListen(TriggerBean.java:52)
    	at com.fixgw.test.TriggerBean.start(TriggerBean.java:39)
    	at com.fixgw.daemon.FeedDaemon.start(FeedDaemon.java:80)
    	at com.fixgw.daemon.FeedDaemon.main(FeedDaemon.java:97)
    Caused by: javax.jms.JMSException: Failed to create session factory
    	at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:615)
    	at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:121)
    	at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:116)
    	at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)
    	at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:456)
    	... 7 more
    Caused by: java.lang.IllegalArgumentException: Error instantiating connector factory "org.hornetq.integration.transports.netty.NettyConnectorFactory"
    	at org.hornetq.utils.ClassloadingUtil$1.run(ClassloadingUtil.java:31)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.hornetq.utils.ClassloadingUtil.safeInitNewInstance(ClassloadingUtil.java:15)
    	at org.hornetq.core.client.impl.ClientSessionFactoryImpl.instantiateConnectorFactory(ClientSessionFactoryImpl.java:1192)
    	at org.hornetq.core.client.impl.ClientSessionFactoryImpl.<init>(ClientSessionFactoryImpl.java:179)
    	at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:590)
    	at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:611)
    	... 11 more
    Caused by: java.lang.ClassNotFoundException: org.hornetq.integration.transports.netty.NettyConnectorFactory
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at org.hornetq.utils.ClassloadingUtil$1.run(ClassloadingUtil.java:26)
    	... 17 more

    With this class I am producing message and this is where I am getting the exception.

    Code:
    package com.fixgw.server.utils;
    @Service("notificationsProducer")
    public class NotificationsProducer
    {
    	@Autowired
    	JmsTemplate jmsTemplate;
    
    	public void sendNotification(final String message)
    	{
    		jmsTemplate.send("queue.Notification", new MessageCreator()
    		{
    			@Override
    			public Message createMessage(Session session) throws JMSException
    			{
    				return session.createObjectMessage(message);
    			}
    		});
    
    	}
    }
    and this is my applicationContext.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    
    
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    
    
    
    	<context:annotation-config />
    
    
    	<context:component-scan base-package="com.fixgw">
    	</context:component-scan>
    
    
    
    	<!--	start a JMX Server 	-->
    	<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" />
    
    
    	<bean id="FeedListenerBean" class="com.fixgw.beans.FeedListenerBean">
    	</bean>
    
    	<bean id="TriggerBean" class="com.fixgw.test.TriggerBean">
    	</bean>
    
    
    
    
    	<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    		<property name="beans">
    			<map>
    				<entry key="Server:name=HttpAdaptor">
    					<bean class="mx4j.tools.adaptor.http.HttpAdaptor">
    						<property name="port" value="8000" />
    						<property name="host" value="0.0.0.0" />
    						<property name="processor">
    							<bean class="mx4j.tools.adaptor.http.XSLTProcessor" />
    						</property>
    					</bean>
    				</entry>
    				<entry key="bean:name=TriggerBean" value-ref="TriggerBean" />
    
    			</map>
    		</property>
    		<property name="listeners">
    			<list>
    				<!--
    					let the HttpAdapter be started after it is registered in the
    					MBeanServer
    				-->
    				<bean class="com.fixgw.jmx.HttpAdaptorMgr">
    					<property name="mbeanServer" ref="mbeanServer" />
    				</bean>
    			</list>
    		</property>
    	</bean>
    
    	<bean name="namingServerImpl" class="org.jnp.server.NamingBeanImpl"
    		init-method="start" destroy-method="stop" />
    
    	<bean name="namingServer" class="org.jnp.server.Main" init-method="start"
    		destroy-method="stop">
    		<property name="namingInfo" ref="namingServerImpl" />
    		<property name="port" value="1099" />
    		<property name="bindAddress" value="localhost" />
    		<property name="rmiPort" value="1098" />
    		<property name="rmiBindAddress" value="localhost" />
    	</bean>
    
    
    
    	<bean name="fileConfiguration" class="org.hornetq.core.config.impl.FileConfiguration"
    		init-method="start" destroy-method="stop" />
    
    	<bean name="hornetQSecurityManagerImpl"
    		class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl" />
    
    	<!-- The core server -->
    	<bean name="hornetQServerImpl" class="org.hornetq.core.server.impl.HornetQServerImpl">
    		<constructor-arg ref="fileConfiguration" />
    		<constructor-arg ref="mbeanServer" />
    		<constructor-arg ref="hornetQSecurityManagerImpl" />
    	</bean>
    
    	<!-- The JMS server -->
    	<bean name="jmsServerManagerImpl" class="org.hornetq.jms.server.impl.JMSServerManagerImpl"
    		init-method="start" destroy-method="stop" depends-on="namingServer">
    		<constructor-arg ref="hornetQServerImpl" />
    	</bean>
    
    
    
    
    	<bean name="connectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
    		<constructor-arg name="ha" value="false" />
    		<constructor-arg>
    			<bean class="org.hornetq.api.core.TransportConfiguration">
    				<constructor-arg
    					value="org.hornetq.integration.transports.netty.NettyConnectorFactory" />
    				<constructor-arg>
    					<map key-type="java.lang.String" value-type="java.lang.Object">
    						<entry key="port" value="5445"></entry>
    					</map>
    				</constructor-arg>
    			</bean>
    		</constructor-arg>
    	</bean>
    
    
    
    
    	<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    		<property name="connectionFactory" ref="connectionFactory"></property>
    		<property name="defaultDestinationName" value="queue.Notifications" />
    	</bean>
    
    
    
    	<bean id="notificationsQueue" class="org.springframework.jndi.JndiObjectFactoryBean"
    		depends-on="jmsServerManagerImpl">
    		<property name="jndiName">
    			<value>/queue/Notifications</value>
    		</property>
    	</bean>
    
    
    	<bean id="inVMConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean"
    		depends-on="jmsServerManagerImpl">
    		<property name="jndiName">
    			<value>java:/ConnectionFactory</value>
    		</property>
    	</bean>
    
    </beans>
    Thanks again,
    ray.

  • #2
    Have you read the stackrace?

    Code:
    Caused by: java.lang.ClassNotFoundException: org.hornetq.integration.transports.netty.NettyConnectorFactory
    Clearly indicates that you probably forgot to include a required dependency...

    Comment


    • #3
      1. How you could understand that?

      2. Do you have exprience with JMSTemplates? I read in couple of HORNETQ forums that using jmstemplates might lead to problems(ref: https://community.jboss.org/wiki/Can...ateWithHornetQ)

      Comment


      • #4
        The stacktrace is clear that there is a missing class hence the ClassNotFoundException. That is a pretty clear signal in my book and has nothing to do with the fact that you are using HornetQ. If I was to use ActiveMQ and forgot to include the client libraries it wouldn't work either...

        And yes I have experience in using JmsTemplate (There is no JMSTemplate!) but not specifically with HornetQ. Also the references and problems you describe aren't HornetQ specific but more or less JMS specific.

        Comment


        • #5
          Hi,

          How come that you saying I miss this dependency? if I switch my java bean code not to use templates this way:


          Code:
          package com.fixgw.mdb;
          
          import javax.annotation.PostConstruct;
          import javax.annotation.PreDestroy;
          import javax.jms.Connection;
          import javax.jms.ConnectionFactory;
          import javax.jms.JMSException;
          import javax.jms.Message;
          import javax.jms.MessageConsumer;
          import javax.jms.MessageListener;
          import javax.jms.Queue;
          import javax.jms.Session;
          import javax.jms.TextMessage;
          
          import org.springframework.beans.factory.annotation.Autowired;
          import org.springframework.stereotype.Service;
          
          @Service("FeedListenerMDB")
          public class FeedListenerMDB implements MessageListener
          {
          
          	@Autowired
          	Queue notificationsQueue;
          
          	@Autowired
          	ConnectionFactory inVMConnectionFactory;
          
          	private Connection notificationsQueueConnection;
          
          	@PostConstruct
          	public void init() throws Exception
          	{
          		notificationsQueueConnection = inVMConnectionFactory.createConnection();
          		Session notificationsQueueSession = notificationsQueueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
          		MessageConsumer notificationsQueueConsumer = notificationsQueueSession.createConsumer(notificationsQueue);
          		notificationsQueueConsumer.setMessageListener(this);
          		notificationsQueueConnection.start();
          	}
          
          	@PreDestroy
          	public void destroy() throws Exception
          	{
          		if (notificationsQueueConnection != null)
          			notificationsQueueConnection.close();
          	}
          
          	@Override
          	public void onMessage(Message message)
          	{
          		if (message instanceof TextMessage)
          		{
          			try
          			{
          				String text = ((TextMessage) message).getText();
          				System.out.println("The Notification Messageeee is : \n" + text);
          			}
          			catch (JMSException ex)
          			{
          				throw new RuntimeException(ex);
          			}
          		}
          		else
          		{
          			throw new IllegalArgumentException("Message must be of type TextMessage");
          		}
          	}
          
          }



          Everything worked great.

          Comment


          • #6
            I give up... Apparently you refuse to read stacktraces and think that a ClassNotFoundException has nothing to do with missing classes..

            The code that works isn't using the same classes (it does a JNDI lookup instead of a locally created server) as the JmsTemplate.

            Comment


            • #7
              Hi Marent,

              Sorry for upsetting you.

              "The code that works isn't using the same classes (it does a JNDI lookup instead of a locally created server) as the JmsTemplate"

              Didnt understand that. now I do. thanks!

              Comment


              • #8
                you are right - with the JNDI everything works great =)

                Comment


                • #9
                  floww,

                  so what would be the criterion of doing JNDI of JmsTemplate ?

                  Comment


                  • #10
                    I don't get your question jndi is just a way of getting your connectionfactory etc. you can still use JmsTemplate with that. What you tried to do in your example is construct a server etc. yourself instead of obtaining those from jndi.

                    Your working sample would still work if you would use JmsTemplate...

                    Comment

                    Working...
                    X