• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Help in MDB with javax.jms

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MessageBean.java

//Required Imports
@MessageDriven(activationConfig =
{ @ActivationConfigProperty(propertyName="destinationType",
propertyValue="javax.jms.Queue"),
@ActivationConfigProperty(propertyName="destination",
propertyValue="jms/queue")})
public class MessageBean implements MessageListener {


public void onMessage(Message msg) {
TextMessage tmsg = null;

try {
tmsg = (TextMessage) msg;
System.out.println(tmsg);

System.out.println("The onMessage() is called");
} catch (Exception e) {
e.printStackTrace();
}


}
}

MsgClient.java
//Required Imports

public class MsgClient {
Queue jmsQueue = null;
QueueConnectionFactory factory = null;
QueueConnection connection = null;
QueueSession session = null;
QueueSender sender = null;
TextMessage message=null;
public void createConnection(){

try{

InitialContext ctx = new InitialContext();
jmsQueue = (Queue) ctx.lookup("jms/Queue");
factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
connection=factory.createQueueConnection();
session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
sender=session.createSender(jmsQueue);

}catch(Exception e){
e.printStackTrace();
}


}
public void sendMessage() {

try {
message = session.createTextMessage();
message.setText("***HI***");
System.out.println(message);
sender.send(message);
System.out.println("Sending message");
session.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

MessageClient.java

import javax.annotation.Resource;
@Resource(mappedName = "jms/Queue")
public class MessageClient {


public static void main(String[] args) {
MsgClient msgcon = new MsgClient();
System.out.println(msgcon.connection);
System.out.println(msgcon.session);
System.out.println(msgcon.sender);
msgcon.createConnection();
msgcon.sendMessage();
}
}


Hi friends the above are my code i am trying to send a simple message to the receiver through jms queue. i am using jboss4.0 version. the error i am getting is

null
null
null
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.cts.msg.MsgClient.createConnection(MsgClient.java:23)
at com.cts.msg.MessageClient.main(MessageClient.java:15)
java.lang.NullPointerException
at com.cts.msg.MsgClient.sendMessage(MsgClient.java:38)
at com.cts.msg.MessageClient.main(MessageClient.java:16)



Please Help Me........Thanks in Advance
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The MDB is not accessible outside the container unless you deploy the stand alone client in an EAR or you access the JNDI context by specifying the ORB host and port which varies on application server implementation.

You could try packaging the app client in an EAR so that it can deployed within the container and have access to the context of the MDB.

Regards.
reply
    Bookmark Topic Watch Topic
  • New Topic