Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Message Service (JMS) - How to sent the MDB onMessage() method's message to HttpServlet  RSS feed

 
ved dixit
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a web chat application using JMS and MDB as a Message Listener.

I am sending a TextMessage to a QUEUE from a HttpServlet
I have one Message Driven Bean listening to the Queue.When I send the message MDB automatically recieves the message in onMessage() method and getting printed.. so far good.

BUT now i need to display the message in an jsp page when ever the onMessage() method triggers.

Here is my MDB Class

package com.chat.mdb;

import java.io.IOException;
import javax.jms.JMSException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;

public class ChatBean implements javax.ejb.MessageDrivenBean,
javax.jms.MessageListener {

private javax.ejb.MessageDrivenContext messageContext = null;

public ChatBean() {
}

public void setMessageDrivenContext(
javax.ejb.MessageDrivenContext messageContext)
throws javax.ejb.EJBException {
this.messageContext = messageContext;
}

public void ejbCreate() {
//no specific action required for message-driven beans
}

public void ejbRemove() {
messageContext = null;
}

public void onMessage(javax.jms.Message message) {
System.out.println("Message Driven Bean - Message : \n" + message);
}}


In the above highlighted code i need to take this message to the servlet
to display the message in jsp.

Any help is appreciated.
Regards,
ved
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36393
453
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ved,
That doesn't make sense. A servlet needs to get a request from the user in order to return a response.

It sounds like you want a user with a browser open to know when a message is processed. You could have onMessage set a flag that the servlet can read. Then the web page can poll to see if onMessage has happened yet.
 
ved dixit
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Basically what i want to do is, i want to get the message which is received on OnMessage method of MDB.

I have One servlet which takes the message from JSP page, forwards to a servlet, servlet is the message producer
which sends the Message to the JMS queue.

I want some kind of mechanism in which My bean will forward the message to the Servlet so that i can display that message
on my JSP page for the web-based chat application.

Actually i have tried to solve this issue and have spent almost 1 week, but no luck so far

If anyone can provide that exactly how can i achieve my goal, that would be really awesome !!

Looking for your help desperately !!!

Thanks in advance.
ved
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!