javax.naming.CommunicationException
dimagh Jan 13, 2006 7:33 PMHello Folks:
I am trying to run the following simple JMS client but in process am getting an error. Pls. look at the bottom of the post.
I am not sure if the factory implementations and the corresponding URL/port number are correct (Pls. see the code in red below). I am running JBoss 4.0.3 locally where this program is running.
---------------------------------------------------------------------------------
package com.message;
import java.util.Hashtable;
import javax.jms.*;
import javax.naming.*;
// Topic client that sends message on a topic
public class TopicSendClient {
TopicConnection conn = null;
TopicSession session = null;
Topic topic = null;
// Main Method
public static void main(String[] args) {
System.out.println("Starting the topic publisher client");
TopicSendClient client = new TopicSendClient();
client.sendMessage("This is test message sent at: " + System.currentTimeMillis());
try {
client.stop();
} catch (JMSException e) {
System.out.println("Exception: " + e);
}
System.out.println("Stopping the topic publisher client");
System.exit(0);
}
public void setupPubSub() throws JMSException, NamingException {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "http://localhost:1099/");
InitialContext intCtx = new InitialContext(env);
Object obj = intCtx.lookup("ConnectionFactory");
TopicConnectionFactory tcf = (TopicConnectionFactory)obj;
conn = tcf.createTopicConnection();
topic = (Topic)intCtx.lookup("topic/polkTopic");
session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
conn.start();
}
public void sendMessage(String text) {
System.out.print("Getting ready to send message on topic: topic/polkTopic");
try {
setupPubSub();
} catch (JMSException e) {
System.out.println("Exception: " + e);
} catch (NamingException e) {
System.out.println("Exception: " + e);
}
try {
TopicPublisher topicPub = session.createPublisher(topic);
TextMessage msg = session.createTextMessage(text);
topicPub.publish(msg);
System.out.print("Sent message: " + "'" + msg.getText() + ", " + "on topic: topic/polkTopic");
topicPub.close();
} catch (JMSException e) {
System.out.println("Exception: " + e);
}
System.out.println("Ending the TopicSendClient job!");
}
public void stop() throws JMSException {
conn.stop();
session.close();
conn.close();
}
}
---------------------------------------------------------------------------------
Following is the exception I am getting:
---------------------------------------------------------------------------------
topic/polkTopicException: javax.naming.CommunicationException: Could not obtain connection to any of these urls: http://localhost:1099/ and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server http:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server http:1099 [Root exception is java.net.UnknownHostException: http: http]]]
java.lang.NullPointerException
at com.message.TopicSendClient.sendMessage(TopicSendClient.java:60)
at com.message.TopicSendClient.main(TopicSendClient.java:19)
Exception in thread "main"
---------------------------------------------------------------------------------
Any help would be appreciated.
Thanks
- AK