• 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
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

javax.jms.JMSException: Communication exception.

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also facing same kind of problem. If anyone get solotion then please reply.
 
Mav Ricky
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic