File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes return value to the calling servlet from messageDrivenBean 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 "return value to the calling servlet from messageDrivenBean" Watch "return value to the calling servlet from messageDrivenBean" New topic

return value to the calling servlet from messageDrivenBean

Joe qiang

Joined: Mar 27, 2003
Posts: 9
I have a servlet to process the login request. The user name and password are passed to one MessageDrivenBean from the servlet. And from onMessage() method in the MessageDrivenBean I call Login BMP bean to verify the login information. If Login information exists in the database, return true, otherwise return false. Now this return value is in onMessage() method in the MessageDrivenBean. However, onMessage() has return type void, how can I return a value from here to the original servlet or I can directly call sentRedirect inside onMessage() and go to the main page?
Please do not question this design. This is assignment from the instructor. Thanks in advance for your help.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
This is really a misuse of the technology. You are being asked to use an asynchronous process to mimic a synchronous call. Personally, I think the assignment is contrived but I understand that you have no control of this.
What you are going to want to do is actually fairly simple. Have your servlet create a temporary Queue and set this as the replyTo Destination on the JMS Message. After sending the JMS message your servlet will need to block for a message on this temporary Queue. Your MDB will then process the message and dump its reponse, in the form of another JMS Message, in the replyTo queue specified in the original message. The servlet will then pick up the response.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
Just back tracking for one moment, are you sure that you have to use a message-driven bean and not a session bean?
Joe qiang

Joined: Mar 27, 2003
Posts: 9
Hi Chris,
Now I have temporary queue in the servlet like the following:
// 1: Lookup ConnectionFactory via JNDI
QueueConnectionFactory queueConnectionFactory =
// 2: Use ConnectionFactory to create JMS connection
QueueConnection queueConnection =
// 3: Use Connection to create session
QueueSession qSession = queueConnection.createQueueSession(
false, Session.AUTO_ACKNOWLEDGE);
Queue replyQueue = qSession.createTemporaryQueue();
QueueReceiver qReceiver = qSession.createReceiver(replyQueue);
qReceiver.setMessageListener(new LogBean());
MapMessage m = null;
m = tsession.createMapMessage();
Here LogBean is the messageDrivenBean. I have to return one interger value from onMessage() to the servlet. There are two questions:
How can I send back the interger value from onMessage() method?
How can I pick it up in the servlet?
Many thanks.
I agree. Here's the link:
subject: return value to the calling servlet from messageDrivenBean
It's not a secret anymore!