my first JMS Bean
krishkumar May 1, 2003 10:16 AMI have written my first JMS Bean, I did not have any problem deploying the bean, but, when I try to run it I am getting the following error. Please help
Got context
javax.naming.NameNotFoundException: javax.jms.TopicConnectionFactory not bound
Source CODE:
------------------
package com.DS.JMS;
import javax.ejb.*;
import javax.jms.*;
/**
* @author bthirnr
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class JMS_Bean implements MessageDrivenBean, MessageListener {
protected MessageDrivenContext context = null;
public void setMessageDrivenContext(MessageDrivenContext ctx) {
context = ctx;
}
public void ejbCreate() {
System.out.println( "ejbCreate Method Called ");
}
public void onMessage(Message msg) {
if (msg instanceof TextMessage) {
TextMessage message = (TextMessage) msg;
try {
System.out.println("MESSAGE : " + message.getText() );
}
catch (JMSException e) {
e.printStackTrace();
}
}
}
public void ejbRemove() {
System.out.println("ejbRemove Method called");
}
}
Client Code
---------------
import javax.naming.*;
import javax.ejb.*;
import javax.jms.*;
import javax.rmi.*;
import java.util.*;
import java.sql.*;
import com.DS.JMS.*;
//import com.javapro.ejb.*;
/**
* @author bthirnr
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class JMS_Client {
public static void main (String args[]) {
// preparing properties for constructing an InitialContext object
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "localhost:1099");
try {
// Get an initial context
InitialContext jndiContext = new InitialContext(properties);
System.out.println("Got context");
TopicConnectionFactory factory = (TopicConnectionFactory)jndiContext.lookup("javax.jms.TopicConnectionFactory");
TopicConnection connection = factory.createTopicConnection();
TopicSession session = connection.createTopicSession(false,TopicSession.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)jndiContext.lookup("testtopic");
TopicPublisher publisher = session.createPublisher(topic);
TextMessage message = session.createTextMessage();
message.setText(" THIS IS TEST MESSAGE FROM CLIENT");
publisher.publish(message);
}
catch(Exception e) {
System.out.println(e.toString());
}
}
}