hi there,
I am
test MDB using WSAD and so far I have put the QueueFactory and Queue etc in the server, deploy the bean and server runs fine on localhost.
Then I put this code as my client, There is one line here test the class type I got back from JNDI lookup and the type is javax.naming.Reference
Then, I cut&paste the same logic put in struts.war logonAction.java and deploy war in my test EAR file, deploy on WAS5.0 Test server, now it runs, I see the message published and this time, class type I got back from JNDI lookup is class com.ibm.ejs.jms.JMSQueueConnectionFactoryHandle
Well, I spent couple hrs to figure out how to run JMS client as a stand alone application, and finally, still, cannt beat it
I attached my test client here, anyone on this board have been able to successfully run a standalone JMS client and using Websphere, please shed some light. Realy appreciate it.
Thanks
-Ying
------------------------------ code here ----------------------------
import javax.jms.Message;
import javax.jms.MapMessage;
import javax.jms.Session;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.Queue;
import javax.jms.QueueSender;
import javax.jms.JMSException;
import javax.naming.Context;
import javax.naming.Reference;
import javax.naming.RefAddr;
import javax.naming.InitialContext;
import java.util.Properties;
import java.util.Date;
import java.util.*;
public class JmsClient {
public static void main(
String [] args) throws Exception {
Integer cruiseID = new Integer(111); //new Integer(args[0]);
int count = 10; //new Integer(args[1]).intValue();
Context jndiContext = getInitialContext();
System.out.println("test...."+ jndiContext.lookup("jms/TestQueueFactory");
.getClass());
QueueConnectionFactory factory = (QueueConnectionFactory)jndiContext.lookup("jms/TestQueueFactory");
Queue reservationQueue = (Queue)jndiContext.lookup("jms/testQueue");
QueueConnection connect = factory.createQueueConnection();
QueueSession session = connect.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(reservationQueue);
for (int i = 0; i < count; i++) {
MapMessage message = session.createMapMessage();
//message.setJMSReplyTo(ticketQueue); // Used in ReservationProcessor to send Tickets back out
message.setStringProperty("MessageFormat", "Version 3.4");
message.setInt("CruiseID", 111);
message.setInt("CustomerID",i%2+1); // either Customer 1 or 2, all we've got in database
message.setInt("CabinID",i%10+100); // cabins 100-109 only
message.setDouble("Price", (double)1000+i);
// the card expires in about 30 days
Date expDate = new Date(System.currentTimeMillis()+43200000);
message.setString("CreditCardNum", "923830283029");
message.setLong("CreditCardExpDate", expDate.getTime());
message.setString("CreditCardType", "Master"); //CreditCardDO.MASTER_CARD);
System.out.println("Sending reservation message #"+i);
sender.send(message);
}
connect.close();
}
public static Context getInitialContext() throws javax.naming.NamingException {
java.util.Properties properties = new java.util.Properties();
properties.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost/");
properties.put(
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
//"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
//"com.ibm.ws.naming.util.WsnInitCtxFactory");
"com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext initialContext = new InitialContext(properties);
return initialContext;
}
}