• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

return value to the calling servlet from messageDrivenBean

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just back tracking for one moment, are you sure that you have to use a message-driven bean and not a session bean?
Simon
 
Joe qiang
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chris,
Now I have temporary queue in the servlet like the following:
// 1: Lookup ConnectionFactory via JNDI
QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)
ctx.lookup("javax.jms.QueueConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
// 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());
queueConnection.start();
MapMessage m = null;
m = tsession.createMapMessage();
m.setJMSReplyTo(replyQueue);
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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic