Question

I have successfully configured Jms queue in jboss.After configured i have got below jboss console message like this

[org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.0.0.Final "Neo"] Started in 1m:2s:271ms
[org.hornetq.ra.inflow.HornetQActivation] Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@e2b54 destination=queue/MyQueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)
INFO  [org.hornetq.ra.inflow.HornetQActivation] Reconnected with HornetQ

After that i have run sample client program to send message to that queue using below code

import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.NamingException;
import com.theopentutorials.mdb.to.Employee;
import com.theopentutorials.utility.ClientUtility;

    public class QueueSenderDemo{
        private static final String QUEUE_LOOKUP = "queue/MyQueue";
        private static final String CONNECTION_FACTORY = "ConnectionFactory";

        public static void main(String[] args) {
            sendMessageToQueue();
            sendObjectMessageToQueue();
        }

        public static void sendMessageToQueue() {
            try {
                Context context = ClientUtility.getInitialContextForClient();
                QueueConnectionFactory factory = (QueueConnectionFactory) context
                        .lookup(CONNECTION_FACTORY);
                QueueConnection connection = factory.createQueueConnection();
                QueueSession session = connection.createQueueSession(false,
                        QueueSession.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue) context.lookup(QUEUE_LOOKUP);

                QueueSender sender = session.createSender(queue);
                TextMessage message = session.createTextMessage();
                message.setText("Welcome to EJB3");
                sender.send(message);
                session.close();
            } catch (NamingException e) {
                e.printStackTrace();
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }

        public static void sendObjectMessageToQueue() {
            try {
                Context context = ClientUtility.getInitialContextForClient();
                QueueConnectionFactory factory = (QueueConnectionFactory) context
                        .lookup(CONNECTION_FACTORY);
                QueueConnection connection = factory.createQueueConnection();
                QueueSession session = connection.createQueueSession(false,
                        QueueSession.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue) context.lookup(QUEUE_LOOKUP);

                QueueSender sender = session.createSender(queue);
                ObjectMessage message = session.createObjectMessage();
                Employee emp = new Employee();
                emp.setDesignation("Developer");
                emp.setSalary(25000);
                emp.setName("ABC");
                emp.setId(1);
                message.setObject(emp);
                sender.send(message);
                session.close();
            } catch (Exception e) {
                e.printStackTrace();
            } /*catch (JMSException e) {
                e.printStackTrace();
            }*/
        }
    }

Finally i have got below error message

javax.naming.NamingException: Could not dereference object [Root exception is java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization]
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1135)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:690)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.theopentutorials.client.QueueSenderDemo.sendMessageToQueue(QueueSenderDemo.java:33)
    at com.theopentutorials.client.QueueSenderDemo.main(QueueSenderDemo.java:25)
Caused by: java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization
    at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:713)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    at java.io.Objpackage com.theopentutorials.client;ectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at org.hornetq.jms.referenceable.SerializableObjectRefAddr.deserialize(SerializableObjectRefAddr.java:79)
    at org.hornetq.jms.referenceable.ConnectionFactoryObjectFactory.getObjectInstance(ConnectionFactoryObjectFactory.java:43)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
    at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1110)
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1127)
    ... 5 more
Caused by: java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization
    at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:587)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1582)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
    ... 16 more
javax.naming.NamingException: Could not dereference object [Root exception is java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization]
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1135)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:690)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.theopentutorials.client.QueueSenderDemo.sendObjectMessageToQueue(QueueSenderDemo.java:55)
    at com.theopentutorials.client.QueueSenderDemo.main(QueueSenderDemo.java:26)
Caused by: java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization
    at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:713)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at org.hornetq.jms.referenceable.SerializableObjectRefAddr.deserialize(SerializableObjectRefAddr.java:79)
    at org.hornetq.jms.referenceable.ConnectionFactoryObjectFactory.getObjectInstance(ConnectionFactoryObjectFactory.java:43)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
    at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1110)
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1127)
    ... 5 more
Caused by: java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization
    at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:587)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1582)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
    ... 16 more

I have included following jar files in the classpath jbossall-client.jar,hornetq-bootsrap.jar,hotnetq-jms.jar,hornetq-logging.jar,netty.jar,hornetq-common-client.jar,hornetq-jboss-as-integration.jar,jboss-as-hornetq-int.jar,hornetq-core.jar

Please help me.I have tried this for last two days.

Was it helpful?

Solution

Finally i have solved this error.I have used jboss 6.x.So it have their own hornetq configurations and corresponding jar files in jboss/common/lib folder.I have included different jar files in classpath. So either use any one jar files.It should resolve above errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top