CommunicationException in SerialContext lookup

A

Abraham Khalil

Using jdk1.4.2 and using the appserver to setup the administer objects
for the jndi.Using Sun example of SimpleAysnchConsumer, SimpleProducer
and TextListener

Administrated objects setup are:
Connection Factories: JNDI Name: jms/QueueConnectionFactory
Destination Resources: JNDI Name: jms/Queue

and running it as:
appclient.bat -client SimpleProducer.jar jms/Queue queue 3

It's reporting an error of as below and need some tips on why this is
happening?
Source code for SimpleProducer.java is shown below too

Thanks
Abraham Khalil


Destination name is jms/Queue, type is queue
Jan 20, 2004 11:34:48 AM com.sun.enterprise.naming.SerialContext
lookup
SEVERE: NAM5003: CommunicationException in SerialContext lookup()
com.sun.enterprise.resource.PoolingException
at com.sun.enterprise.connectors.AdministeredObjectResource.createAdmini
steredObject(AdministeredObjectResource.java:143)
at com.sun.enterprise.naming.factory.AdministeredObjectFactory.getObject
Instance(AdministeredObjectFactory.java:67)
at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:3
01)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:130
)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at SimpleProducer.main(SimpleProducer.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:28
5)
at com.sun.enterprise.appclient.Main.<init>(Main.java:406)
at com.sun.enterprise.appclient.Main.main(Main.java:105)
Caused by: java.security.PrivilegedActionException:
com.sun.enterprise.resource.
PoolingException
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.enterprise.connectors.AdministeredObjectResource.createAdmini
steredObject(AdministeredObjectResource.java:139)
.....
......



/**
* The SimpleProducer class consists only of a main method,
* which sends several messages to a queue or topic.
*
* Run this program in conjunction with SimpleSynchConsumer or
* SimpleAsynchConsumer. Specify a queue or topic name on the
* command line when you run the program. By default, the
* program sends one message. Specify a number after the
* destination name to send that number of messages.
*/
import javax.jms.*;
import javax.naming.*;

public class SimpleProducer {

/**
* Main method.
*
* @param args the destination used by the example,
* its type, and, optionally, the number of
* messages to send
*/
public static void main(String[] args) {
String destName = null;
String destType = null;
Context jndiContext = null;
ConnectionFactory connectionFactory = null;
Connection connection = null;
Session session = null;
Destination dest = null;
MessageProducer producer = null;
TextMessage message = null;
final int NUM_MSGS;

if ( (args.length < 2) || (args.length > 3) ) {
System.out.println("Program takes two or three arguments:
" +
"<dest_name> <queue|topic> " +
"[<number-of-messages>");
System.exit(1);
}
destName = new String(args[0]);
destType = new String(args[1]);
System.out.println("Destination name is " + destName +
", type is " + destType);
if (args.length == 3){
NUM_MSGS = (new Integer(args[2])).intValue();
} else {
NUM_MSGS = 1;
}

/*
* Create a JNDI API InitialContext object if none exists
* yet.
*/
try {
jndiContext = new InitialContext();
} catch (NamingException e) {
System.out.println("Could not create JNDI API " +
"context: " + e.toString());
System.exit(1);
}

/*
* Look up connection factory and destination. If either
* does not exist, exit. If you look up a
* TopicConnectionFactory instead of a
* QueueConnectionFactory, program behavior is the same.
*/
try {
connectionFactory = (ConnectionFactory)
jndiContext.lookup("jms/QueueConnectionFactory");
if (destType.equals("queue")) {
dest = (Queue) jndiContext.lookup(destName);
} else if (destType.equals("topic")) {
dest = (Topic) jndiContext.lookup(destName);
} else {
throw new Exception("Invalid destination type" +
"; must be queue or topic");
}
} catch (Exception e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
e.printStackTrace();
System.exit(1);
}

/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create producer and text message.
* Send messages, varying text slightly.
* Send end-of-messages message.
* Finally, close connection.
*/
try {
connection = connectionFactory.createConnection();
session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(dest);
message = session.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is message " + (i + 1));
System.out.println("Sending message: " +
message.getText());
producer.send(message);
}

/*
* Send a non-text control message indicating end of
* messages.
*/
producer.send(session.createMessage());
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {}
}
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top