Two Laptop Bag*
The moose likes EJB and other Java EE Technologies and the fly likes javax.jms.JMSException: Communication exception. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "javax.jms.JMSException: Communication exception." Watch "javax.jms.JMSException: Communication exception." New topic
Author

javax.jms.JMSException: Communication exception.

Mav Ricky
Ranch Hand

Joined: May 19, 2004
Posts: 76
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
seema vajpayee
Greenhorn

Joined: Jan 22, 2007
Posts: 1
I am also facing same kind of problem. If anyone get solotion then please reply.
Mav Ricky
Ranch Hand

Joined: May 19, 2004
Posts: 76
hi
the problem is resolved by myself only

find the new code
**************************************************************************

/*
* Created on Jan 19, 2007
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/

/**
* @author ankur_srivastava
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* The SimpleTopicPublisher class consists only of a main method,
* which publishes several messages to a topic.
*
* Run this program in conjunction with SimpleTopicSubscriber.
* Specify a topic name on the command line when you run the
* program. By default, the program sends one message.
* Specify a number after the topic name to send that number
* of messages.
*/
import java.util.Hashtable;

import javax.jms.JMSException;
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;
Context 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 {
Hashtable ctxProp = new Hashtable();
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");
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, 1);

topicConnection.start();
topic = topicSession.createTopic("TestTopic/MyTestTopic");

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) {
}
}
}
}
}
***************************************************************************


regards
Ankur S
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.jms.JMSException: Communication exception.
 
Similar Threads
Problem with jms Message Selector
Problem with jms Message Selector
Problem running JMS client java program accessing Websphere 5.0 jms server
Connecting to J2EE Server installed in Solaris
Jboss Remote Connection JMS