File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Error deserializing Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Error deserializing Object" Watch "Error deserializing Object" New topic
Author

Error deserializing Object

Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
Hi all,

I am posting a serializable object as message to MDB Queue and trying to deserialize it in onMessage() method. But, getting below error

"Exception in onMessage weblogic.jms.common.JMSException: Error deserializing object"

Here is my onMessage method. Please help me !!!

public void onMessage(Message msg) {
ProcessQuery prQuery = null;
try {
ObjectMessage message = (ObjectMessage) msg;
ProcessQuery pQ = (ProcessQuery) message.getObject();
prQuery = pQ.execute();
}
catch(JMSException ex) {
System.out.println("Exception in onMessage " + ex);
ex.printStackTrace();
}
}

ProcessQuery is a serializable object.

Thanks in advance,
Anitha
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

Are the objects contained in the ProcessQuery(member variables) serializable?


[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

The following code might help you in finding out the exact object that is NOT serializable. Pass the ProcessQuery object as a parameter to this method. If there are any contained objects which are NOT serializable then exception is thrown and the stacktrace will mention the object which is NOT serializable.

Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
Hi,

Thanks for your reply. I didnot get any error when i tested my object with the method you gave. My class is here

public class ProcessQuery implements java.io.Serializable
{
public ProcessQuery()
{
}

public void printMessage()
{
System.out.println("Inside printMessage() in ProcessQuery");
}
}

Here is my onMessage method

public void onMessage(Message msg)
{
ProcessQuery prQuery = null;
try {
ObjectMessage mesage = (ObjectMessage) msg;
System.out.println("Getting Object using getObject ...");
Object pqObj = mesage.getObject();
System.out.println("Type Casting Object to ProcessQuery");
ProcessQuery pQ = (ProcessQuery) pqObj;
System.out.println("Invoking method printMessage in ProcessQuery");
pQ.printMessage();
}
catch(JMSException ex) {
System.out.println("Error in onMessage 1 : "+ex);
ex.printStackTrace();
}
}

Please advice

Thanks in Advance,
Anitha
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

Can you post the stack trace of the exception that you are seeing the onMessage method. That might help in identifying the exact issue
Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
I think am nearing the solution. My MDB jar file structure is as below.
META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/lib/
ejb-jar.xml
weblogic-ejb-jar.xml
ejbgen-build.xml
META-INF/ejbgen-build.xml
META-INF/ejb-jar.xml
META-INF/weblogic-ejb-jar.xml
WEB-INF/lib/webapputils.jar
QueueMessageBean.java
QueueMessageBean.class

Iam new to MDB. I have made ProcessQuery.class as a jar and placed it under WEB-INF/lib/webapputils.jar but am getting below error.

Please advice me on where should i have my ProcessQuery.class and how should this be set to classpath. Hope my problem will get resolved if i have ProcessQuery.class in classpath.

java.lang.NoClassDefFoundError: com/lehman/cot/dom/ProcessQuery
at QueueMessageBean.$BIP$onMessage(Ljavax/jms/Message V(QueueMessageBean.java:116)
at QueueMessageBean.onMessage(Ljavax/jms/Message V(QueueMessageBean.java:???)
at weblogic.ejb20.internal.MDListener.execute(Lweblogic/kernel/ExecuteThread V(MDListener.java:370)
at weblogic.ejb20.internal.MDListener.onMessage(Ljavax/jms/Message V(MDListener.java:262)
at weblogic.jms.client.JMSSession.onMessage(Ljavax/jms/MessageListener;Lweblogic/jms/common/MessageImpl V(JMSSession.java:2678)
at weblogic.jms.client.JMSSession.execute(Lweblogic/kernel/ExecuteThread V(JMSSession.java:2598)
at weblogic.kernel.ExecuteThread.execute(Lweblogic/kernel/ExecuteRequest V(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:178)
at java.lang.Thread.startThreadFromVM(Ljava/lang/Thread V(Unknown Source)

Thanks,
Anitha.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

java.lang.NoClassDefFoundError: com/lehman/cot/dom/ProcessQuery


This exception is seen if the classes referenced by the ProcessQuery class(through its import statements or some other way) are NOT found in the classpath. If the server had NOT found the ProcessQuery class in the classpath it would have thrown ClassNotFoundException instead of NoClassDefFoundError. Place any jars/classes that are referenced by this ProcessQuery classs in the classpath
Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
Hi,

Thanks. This probelm is resolved. I had made the all necessary classes available in classpath. The flow is like this
1. Call a servlet that posts a ProcessQuery object to RequestQueue
2. Have a MDB for RequestQueue which takes the object and process the data in onMessage
3. Post the result object to ResponseQueue
4. Have another servlet that keeps listening the response queue for messages (this servlet will print waiting message till the result is ready. Assume it will take two minutes for the process to get completed and to post the result in response queue)
5. Once the result is avaiable in ResponseQueue the servlet will display this result.

Till point 4 its working fine am able to post the results to ResponseQueue. I can see the increase in message count on response queue. But, having problem in retreiving the message from ResponseQueue in the servlet. Here is my code

Queue responseQueue = (Queue) ic.lookup(this.RESPONSE_QUEUE);
QueueReceiver rcvr = qsession.createReceiver(responseQueue);
Message receivedMsg = rcvr.receiveNoWait();
if (receivedMsg == null) {
System.out.println("Waiting For Message");
} else {
ObjectMessage inMsg = (ObjectMessage) receivedMsg;
ProcessQuery resultsObj = (ProcessQuery) inMsg.getObject();
// display result
}

Iam always getting receivedMsg as null in spite of having the message in response queue.

Please advice.

Thanks in Advance,
Anitha
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

Try using the receive() method on the QueueReceiver instead of using the receiveNoWait method, since as per the javadocs of the receiveNoWait method:

Receives the next message if one is immediately available

[ February 21, 2006: Message edited by: jaikiran pai ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

Try this out:

Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
But receive will wait for the message on server side until it is available on Queue.

My browser will get timed out in 90 secods. So, am using META REFRESH to refresh the screen until the message is available. On each refresh the servlet will check for message using receiveNoWait().

Please advice

Thanks,
Anitha.
Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
the process will take more than 90 seconds to get completed so using receive() will result in browser time out problem.

This is the reason i opted receiveNoWait()
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

So, am using META REFRESH to refresh the screen until the message is available. On each refresh the servlet will check for message using receiveNoWait().


I am not aware how the META REFRESH works. But, going by what you are saying, ideally you should see the "Waiting For Message" message more than once in the server log. Is this the case, or are you seeing it just once in the server log?
Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
i ping the server every 15 seconds to check for message. If message is there display it or else ping again after 15 seconds.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

On second thoughts, you might consider using a MDB instead of the second servlet waiting for the message. Using the MDB has a advantage that the MDB will be invoked when the message is available so you need not wait for the message. Having said this, i am not aware of your exact requirements.
Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
Hi,

Thanks for your response. My requirement is the page has to be interactive to user that is the reason i refresh the please wait screen until the result is ready. In this case i think another MDB for listening message will not suit.

Anyway i have resolved the problem by adding connection.start() method. Now, am able to receive the message from ResponseQueue.

But then got into another problem. I am able to receive the messages if i use this code QueueReceiver rcvr = qsession.createReceiver(responseQueue);

Its not working if i use below code
QueueReceiver rcvr = qsession.createReceiver(responseQueue, selector);
where selector will be like "JMSMessageID20211" 20211 is unique for each user

I need the use the second code as i need to serve the user with the request he had raised. I identify his request by this selector field.
Otherwise wrong messages are getting served.

Please advice.

Thanks and Regards,
Anitha.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9329
    
110

I believe this is how you are setting the message selector in the message that is put in the queue:



Then when QueueReceiver is created, the selector will be as follows:



Note the single quotes in the selector. This is important since, as per the docs:
A message selector is a String whose syntax is based on a subset of the SQL92 conditional expression syntax


These links might help you with message selectors:

http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html

http://www.onjava.com/pub/a/onjava/2003/01/29/ejbinherit4.html
Anitha Krishnamurthi
Greenhorn

Joined: Nov 29, 2004
Posts: 26
Hi,

After so many hurdles am done with my requirement. I was setting the selector as String selector = "JMSMessageID = '"+msgId+"'";
But, it has to be set as String selector = "JMSCorrelationID= '"+msgId+"'";

Now, am able to get the responses. Being brand new to MDB stuff i struggled a lot to finish this requirement.

Thanks a lot for all your help !!!

I learned a lot in this assignment

Thanks a bunch .....
Anitha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error deserializing Object
 
Similar Threads
JMSException Error deserializing object
weblogic.jms. common.JMSException: Error deserializing object
Exception in receiving ObjectMessage in JMS
Getting very strange exception: JMS in EJB3, JBoss
sending org.jdom.Document object over JMS