aspose file tools*
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


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
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
Author

How to send message from Web Component

L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi,
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.


SCJP, SCWCD
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();
try{
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL,"localhost:1099");
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());
}
try{
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 theserverside.com");
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!");
qsend.send(objectMessage);
//this is an object message that should get to our PostMessageMDB
objectMessage = queueSession.createObjectMessage(messageDTO);
qsend.send(objectMessage);
//this is a text message that should not get to our PostMessageMDB
TextMessage tm = null;
tm = queueSession.createTextMessage();
tm.setText("This is a text");
qsend.send(tm);
}catch(JMSException e){
System.out.println("JMS exception occurrred : " + e.toString());
}finally{
if(queueCon != null){
try{
queueCon.close();
}catch (JMSException e){
}
}
}
}
}

Cheers


...watch me...as I'm walking the path...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to send message from Web Component