This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sending org.jdom.Document object over JMS

 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am getting following error while trying to receive a ObjectMessage.

Exception in thread "main" weblogic.jms.common.JMSException: Error deserializing
object
at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.jav
a:140)
at JMSReceiver.main(JMSReceiver.java:65)
----------- Linked Exception -----------
java.io.InvalidClassException: org.jdom.Document; local class incompatible: stre
am classdesc serialVersionUID = 607431889463202798, local class serialVersionUID
= -3468405884372921646
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.jav
a:128)
at JMSReceiver.main(JMSReceiver.java:65)
----------- Linked Exception -----------
java.io.InvalidClassException: org.jdom.Document; local class incompatible: stre
am classdesc serialVersionUID = 607431889463202798, local class serialVersionUID
= -3468405884372921646
at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at weblogic.jms.common.ObjectMessageImpl.getObject(ObjectMessageImpl.jav
a:128)
at JMSReceiver.main(JMSReceiver.java:65)



This is the code where I am sending Document object


// locating connection factory
QueueConnectionFactory connectionFactory = (QueueConnectionFactory)context.lookup("ALConnectionFactory");
//locating queue
Queue queue= (Queue) context.lookup("Queue");

// create the connection
QueueConnection connection = connectionFactory.createQueueConnection();
// establishing the session
QueueSession session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
// creating sender
QueueSender sender = session.createSender(queue);
// create the message
//TextMessage msg = session.createTextMessage("this is sample queue from the JPO");
ObjectMessage msg = session.createObjectMessage((Serializable)doc);
// sends the message
sender.send(msg,DeliveryMode.NON_PERSISTENT, 4, 0);
//System.out.println(connectionFactory);
//System.out.println(queue);
connection.close();
session.close();

And this the code where I am trying to receive the Document object

QueueConnectionFactory connectionFactory = (QueueConnectionFactory)context.lookup("ALConnectionFactory");
//locating queue
Queue queue= (Queue) context.lookup("Queue");

// create the connection
QueueConnection connection = connectionFactory.createQueueConnection();
// establishing the session
QueueSession session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
// creating receiver
QueueReceiver receiver = session.createReceiver(queue);
// start the connection this is different b/n sender and receiver
connection.start();
//TextMessage msg = (TextMessage)receiver.receive();

// start
ObjectMessage msg = (ObjectMessage)receiver.receive();
Document doc = (Document) msg.getObject();


Please help me resolving this problem

Thanks
Nuthan
 
H Gokulam
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nuthan,

Only Serializable objects can be used in method 'createObjectMessage'. Just by typecasting a non-serializable object, you will not achieve this. The following statement just avoids the compilation error. But if 'doc' is not serializable, you will get runtime error.

ObjectMessage msg = session.createObjectMessage((Serializable)doc);

Regards,
 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hari,
Thanks for your reply .. but doc object is of type org.jdom.Document which implements Serializable.I think that may not be the reason for this error, because the same code is just working fine in my personal system with same JDK version.

Thanks
Nuthan
 
H Gokulam
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nuthan,

Sorry for sending a reply without reading your question properly. You are right, org.jdom.Document implements Serializable. So, that is not the reason.

Reason for the error could be different versions of org.jdom.Document in the Client and Server. Try to use the same jar file (which contains org.jdom.Document) for server and for client.

Regards
 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hari,
I tried with same jar file in client and server.. and still getting same error.

Nuthan
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could add this to the server class.
 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still it is not working after adding the following statement also

static final long serialVersionUID = -3468405884372921646L;
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the same JVM version for running both the client and server code. If you are using JRockit, then your client must be an Intel box.
 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried with same JVM and still facing same problem .. and it is working fine if I use org.dom4j.dom.DOMDocument instead of org.jdom.Document.

Is there any problem with jdom Document object ..?

Thanks
Nuthan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic