hi
i am getting the exception while excuting the following JMS programs
SimpleTopicPublisher.java
********************************************************************
import java.util.Properties;
import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicPublisher;
import javax.jms.TopicSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class SimpleTopicPublisher {
/**
* Main method.
*
* @param args the topic used by the example and,
* optionally, the number of messages to send
*/
private static final
String USER = "rrawal";
private static final String PASSWORD = "test123";
private static final String SAP_NAMING_PROVIDER_URL = "bwserver:50004";
private static final String SAP_INITIAL_CONTEXT_FACTORY_IMPL =
"com.sap.engine.services.jndi.InitialContextFactoryImpl";
public static void main(String[] args) {
String topicName = null;
InitialContext jndiContext = null;
TopicConnectionFactory topicConnectionFactory = null;
TopicConnection topicConnection = null;
TopicSession topicSession = null;
Topic topic = null;
TopicPublisher topicPublisher = null;
TextMessage message = null;
final int NUM_MSGS;
if ((args.length < 1) || (args.length > 2)) {
System.out.println(
"Usage:
java "
+ "SimpleTopicPublisher <topic-name> "
+ "[<number-of-messages>]");
//System.exit(1);
}
topicName = "jmstopics/TestTopic/MyTestTopic";
System.out.println("Topic name publisher is " + topicName);
if (args.length == 2) {
NUM_MSGS = (new Integer(args[1])).intValue();
} else {
NUM_MSGS = 1;
}
/*
* Create a JNDI API InitialContext object if none exists
* yet.
*/
try {
Properties ctxProp = new Properties();
ctxProp.put(
Context.INITIAL_CONTEXT_FACTORY,
SAP_INITIAL_CONTEXT_FACTORY_IMPL);
ctxProp.put(Context.PROVIDER_URL, SAP_NAMING_PROVIDER_URL);
ctxProp.put(Context.SECURITY_PRINCIPAL, USER);
ctxProp.put(Context.SECURITY_CREDENTIALS, PASSWORD);
jndiContext = new InitialContext(ctxProp);
} catch (NamingException e) {
System.out.println(
"Could not create JNDI API " + "context: " + e.toString());
e.printStackTrace();
System.exit(1);
}
/*
* Look up connection factory and topic. If either does
* not exist, exit.
*/
try {
topicConnectionFactory =
(TopicConnectionFactory) jndiContext.lookup(
"jmsfactory/default/TopicConnectionFactory");
//System.err.println(" dasfjh jhg gf topic " + topicName);
topic = (Topic) jndiContext.lookup(topicName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " + e.toString());
e.printStackTrace();
}
/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create publisher and text message.
* Send messages, varying text slightly.
* Finally, close connection.
*/
try {
topicConnection = topicConnectionFactory.createTopicConnection();
//topicConnection.start();
topicSession =
topicConnection.createTopicSession(
false,
Session.AUTO_ACKNOWLEDGE);
topicConnection.start();
topic = topicSession.createTopic("MyTestTopic");
System.out.println("Topic Name \n" + topic);
//topicSession.run();
topicPublisher = topicSession.createPublisher(topic);
message = topicSession.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
System.out.println("Publishing message start: " );
message.setText("This is message " + (i + 1));
System.out.println("Publishing message: " + message.getText());
topicPublisher.publish(message);
}
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
e.printStackTrace();
}
finally {
if (topicConnection != null) {
try {
topicSession.close();
topicConnection.close();
} catch (JMSException e) {
}
}
}
}
}
************************************************************************
while executing this program we are are getting the following exception.
************************************************************************
Topic name publisher is jmstopics/TestTopic/MyTestTopic
Topic Name
================================= Destination ==================================
Type Topic
Name MyTestTopic
ID 16777249
================================================================================
javax.jms.JMSException: Communication exception.
at com.sap.jms.protocol.notification.ServerExceptionResponse.getException(ServerExceptionResponse.java:271)
at com.sap.jms.client.session.Session.checkReceivedPacket(Session.java:1767)
at com.sap.jms.client.session.Session.createProducer(Session.java:1605)
at com.sap.jms.client.session.TopicSession.createPublisher(TopicSession.java:46)
at SimpleTopicPublisher.main(SimpleTopicPublisher.java:138)
Exception occurred: javax.jms.JMSException: Communication exception.
****************************************************************************
thanks for replying ASAP
regards
Ankur S