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 How to send message from Web Component 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 "How to send message from Web Component" Watch "How to send message from Web Component" New topic

How to send message from Web Component

L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
I want to know how to send message to a Message Driven Bean residing in EJB container from
1. Web Component
2. Application Client
3. Another Entity Bean
4. Non J2EE client.
If you provide me any tutorial link on this it would be really helpful.
Thanks for the time.

Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
No matter from where you want to send JMS messages, the code is pretty much like in the following client. I have copied a simple client, hope you can figure out from this.
package j2eepatterns.tests;
* <p>Title: </p>
* <p>Description: This is the client class for the MessageFacade</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author Sergiu Truta
* @version 1.0
import j2eepatterns.businessdelegate.dto.*;
import javax.naming.*;
import javax.jms.*;
import java.util.*;
import java.text.*;
import java.math.BigDecimal;
public class TestPostMessageMDB {
public static void main(String[] args){
QueueConnectionFactory queueConFactory = null;
QueueConnection queueCon = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender qsend = null;
ObjectMessage objectMessage = null;
java.util.Properties p = new java.util.Properties();
p.put("java.naming.factory.url.pkgs","org.jboss.naming rg.jnp.interfaces");
InitialContext iContext = new InitialContext(p);
queueConFactory = (QueueConnectionFactory)iContext.lookup( "ConnectionFactory" );
queue = (Queue)iContext.lookup("queue/DLQ");
}catch(NamingException e){
System.out.println("JNDI look up failed: " + e.toString());
queueCon = queueConFactory.createQueueConnection();
queueSession = queueCon.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
qsend = queueSession.createSender(queue);
MessageDTO messageDTO = new MessageDTO();
messageDTO.setTitle("What can you guys say about CMP versus BMP?");
messageDTO.setDescription("Read Ed Roman's EJB 2nd edition.You can find it on");
messageDTO.setOwner(new UserDTO(new BigDecimal(29)));
messageDTO.setRootMessage(new Double(97));
//this is an object message that should not get to our PostMessageMDB
objectMessage = queueSession.createObjectMessage("this object message should not reach the repository!");
//this is an object message that should get to our PostMessageMDB
objectMessage = queueSession.createObjectMessage(messageDTO);
//this is a text message that should not get to our PostMessageMDB
TextMessage tm = null;
tm = queueSession.createTextMessage();
tm.setText("This is a text");
}catch(JMSException e){
System.out.println("JMS exception occurrred : " + e.toString());
if(queueCon != null){
}catch (JMSException e){

Cheers I'm walking the path...
I agree. Here's the link:
subject: How to send message from Web Component
It's not a secret anymore!