-
1. Re: Unable to run PTP Clients on JBoss
adrian.brock Jan 16, 2003 8:50 PM (in response to mkreddy123)By default your beans are added to jndi
using <ejb-name>
so your HelloWorldHome is at "HelloWorld"
why are you trying to cast it to a QueueConnectionFactory?
Try lookup("ConnectionFactory")
the connection factories and their jndi-names
are defined in
server/default/deploy/jbossmq-service.xml
Regards,
Adrian -
2. Re: Unable to run PTP Clients on JBoss
mkreddy123 Jan 17, 2003 12:13 AM (in response to mkreddy123)Yes i tried to look for Connection Factory but still the same error..
These 2 programs are running fine on J2EE Server(from command prompt)..What is the problem with JBoss?..
if any .xml r to written ..pl say how to write/and where to place .xml? and similarly for jars..
Runtime Error which i got was:
- ClassCastException
this was how i ran the program making some slight changes in run-client.bat which was given under -D:\jboss-3.0.5RC1\template\build\bin directory icopied both of the batch files in my current working directory..
======================================================
D:\examples\HelloWorld>rm
C:\jdk1.3.1_01\jre\bin\java.exe -classpath ".;D:\jboss-3.0.5RC1\client\concurren
t.jar;D:\jboss-3.0.5RC1\client\gnu-regexp.jar;D:\jboss-3.0.5RC1\client\jacorb.ja
r;D:\jboss-3.0.5RC1\client\jboss-client.jar;D:\jboss-3.0.5RC1\client\jboss-commo
n-client.jar;D:\jboss-3.0.5RC1\client\jboss-iiop-client.jar;D:\jboss-3.0.5RC1\cl
ient\jboss-j2ee.jar;D:\jboss-3.0.5RC1\client\jboss-jaas.jar;D:\jboss-3.0.5RC1\cl
ient\jboss-jsr77.jar;D:\jboss-3.0.5RC1\client\jboss-net-client.jar;D:\jboss-3.0.
5RC1\client\jboss-system-client.jar;D:\jboss-3.0.5RC1\client\jbossall-client.jar
;D:\jboss-3.0.5RC1\client\jbossha-client.jar;D:\jboss-3.0.5RC1\client\jbossjmx-a
nt.jar;D:\jboss-3.0.5RC1\client\jbossmq-client.jar;D:\jboss-3.0.5RC1\client\jbos
smqha.jar;D:\jboss-3.0.5RC1\client\jbosssx-client.jar;D:\jboss-3.0.5RC1\client\j
cert.jar;D:\jboss-3.0.5RC1\client\jms.jar;D:\jboss-3.0.5RC1\client\jmx-connector
-client-factory.jar;D:\jboss-3.0.5RC1\client\jmx-ejb-connector-client.jar;D:\jbo
ss-3.0.5RC1\client\jmx-rmi-connector-client.jar;D:\jboss-3.0.5RC1\client\jnet.ja
r;D:\jboss-3.0.5RC1\client\jnp-client.jar;D:\jboss-3.0.5RC1\client\jsse.jar;D:\j
boss-3.0.5RC1\client\log4j.jar" mohan.SimpleQueueSender topic 2
Queue name is topic
Exception in thread "main" java.lang.ClassCastException: org.jboss.mq.SpyQueue
at mohan.SimpleQueueSender.main(SimpleQueueSender.java:65)
=======================================================
code 1(SimpleQueueSender.java)
====
package mohan;
import javax.jms.*;
import javax.naming.*;
import java.util.Hashtable;
public class SimpleQueueSender {
/**
* Main method.
*
* @param args the queue used by the example and,
* optionally, the number of messages to send
*/
public static void main(String[] args) {
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
TextMessage message = null;
final int NUM_MSGS;
if ( (args.length < 1) || (args.length > 2) ) {
System.out.println("Usage: java SimpleQueueSender " +
"<queue-name> [<number-of-messages>]");
System.exit(1);
}
queueName = new String(args[0]);
System.out.println("Queue name is " + queueName);
if (args.length == 2){
NUM_MSGS = (new Integer(args[1])).intValue();
} else {
NUM_MSGS = 1;
}
Hashtable prop = new Hashtable();
prop.put ("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
prop.put ("java.naming.provider.url","jnp://localhost:1099");
prop.put ("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
/*
* Create a JNDI API InitialContext object if none exists
* yet.
*/
try {
jndiContext = new InitialContext(prop);
} catch (NamingException e) {
System.out.println("Could not create JNDI API " +
"context: " + e.toString());
System.exit(1);
}
/*
* Look up connection factory and queue. If either does
* not exist, exit.
*/
try {
//queueConnectionFactory = //(QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
//queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("encryption.NoCrypt");
queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("ConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
System.exit(1);
}
/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create sender and text message.
* Send messages, varying text slightly.
* Send end-of-messages message.
* Finally, close connection.
*/
try {
queueConnection =
queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is message " + (i + 1));
System.out.println("Sending message: " +
message.getText());
queueSender.send(message);
}
/*
* Send a non-text control message indicating end of
* messages.
*/
queueSender.send(queueSession.createMessage());
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {}
}
}
}
}
// end of code
code 2(SimpleQueueReceiver.java)
=======
package mohan;
import javax.jms.*;
import javax.naming.*;
import java.util.Hashtable;
public class SimpleQueueReceiver {
/**
* Main method.
*
* @param args the queue used by the example
*/
public static void main(String[] args) {
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueReceiver queueReceiver = null;
TextMessage message = null;
/*
* Read queue name from command line and display it.
*/
if (args.length != 1) {
System.out.println("Usage: java " +
"SimpleQueueReceiver <queue-name>");
System.exit(1);
}
queueName = new String(args[0]);
System.out.println("Queue name is " + queueName);
/*
* 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);
}
Hashtable prop = new Hashtable();
prop.put ("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
prop.put ("java.naming.provider.url","jnp://localhost:1099");
prop.put ("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
/*
* Look up connection factory and queue. If either does
* not exist, exit.
*/
try {
// queueConnectionFactory = (QueueConnectionFactory)
// jndiContext.lookup("QueueConnectionFactory");
queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("ConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
System.exit(1);
}
/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create receiver, then start message delivery.
* Receive all text messages from queue until
* a non-text message is received indicating end of
* message stream.
* Close connection.
*/
try {
queueConnection =
queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
queueConnection.start();
while (true) {
Message m = queueReceiver.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
System.out.println("Reading message: " +
message.getText());
} else {
break;
}
}
}
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {}
}
}
}
}
//end of code -
3. Re: Unable to run PTP Clients on JBoss
mkreddy123 Jan 17, 2003 1:04 AM (in response to mkreddy123)Yes! found out the error..
replaced
queue = (Queue) jndiContext.lookup(queueName);
with
queue = (Queue) jndiContext.lookup("queue/testQueue");
Thanks
--Mohan