wood burning stoves 2.0*
The moose likes Websphere and the fly likes Run stand alone JMS client ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "Run stand alone JMS client ..." Watch "Run stand alone JMS client ..." New topic
Author

Run stand alone JMS client ...

Ying Zhou
Greenhorn

Joined: Feb 13, 2002
Posts: 10
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;
}
}
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Place your code in a J2EE application Client JAR file inside your EAR file. Run the client using the launchClient tool. That shoudl solve the problem.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Glen Cai
Ranch Hand

Joined: Aug 24, 2002
Posts: 121
Is J2EE client container becoming a stardard in J2EE1.4?


"I, a universe of atoms, an atom in the universe." - Richard Feynman
Howard Kushner
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 361
The application client container has been a standard since J2EE 1.2 as far as I know.
The four containers per the spec are (in no particular order):
  • Application Client Container
  • Applet Container
  • Web Component Container
  • Enterprise Bean Container


  • Hope this helps.
    Regards,


    Howard Kushner<br />IBM Certified Enterprise Developer - WebSphere Studio Application Developer V5.0<br />IBM Certified Advanced System Administrator - WebSphere Application Server V5.0<br />IBM Certified Solution Developer - Web Services with WebSphere Studio V5.1<br /><a href="http://www.amazon.com/exec/obidos/tg/detail/-/1931182108/" target="_blank" rel="nofollow">Developing J2EE Applications with WebSphere Studio</a> my Certification Study Guide for IBM Test 287
    siva kumar
    Ranch Hand

    Joined: Sep 03, 2004
    Posts: 86
    HI Kyle,

    I have configured the listener port for my p2p MDB using AdminConsole

    while restarting the server i'm getting follwing errors

    Unable to lookup JMS resources, JNDI lookup exception: com.ibm.ejs.jms.JMSQueueConnectionFactoryHandle
    Unable to start MDB Listener Message, JMSDestination QCF : java.lang.ClassCastException: com.ibm.ejs.jms.JMSQueueConnectionFactoryHandle

    Failed to start MDB Message against listener port MessageListener



    and while running the application I'm getting the following exception

    javax.jms.JMSException: MQJMS2005: failed to create MQQueueManager for 'localhost:WAS_localhost_server1'
    at com.ibm.mq.jms.services.ConfigEnvironment.newException(ConfigEnvironment.java:556)
    at com.ibm.mq.jms.MQConnection.createQM(MQConnection.java:1736)
    at com.ibm.mq.jms.MQConnection.createQMNonXA(MQConnection.java:1129)
    at com.ibm.mq.jms.MQQueueConnection.<init>(MQQueueConnection.java:170)

    I haven't installed MQ series separatly.

    I'm running the application from WSAD .

    Can you please assit me to solve the problem
    Goutam Bhattacharjee
    Ranch Hand

    Joined: Aug 05, 2003
    Posts: 44
    I had this problem initially when I tried to test an MDB. I am also testing the MDB within WSAD, and have not installed MQ-Series separately. After I got this error, I did some trial & error and it finally clicked when I set the "JMS Provider" to 'Embedded messaging'. Open the server configuration, go to the 'JMS' tab --> server settings --> JMS Provider section. You will find 3 radio buttons here, by default, the selection is: Disable. Set it to 'Embedded Messaging'.
    And since you already know how to configure a listener port and attach it to your MDB, there is nothing more for me to explain on that
    Hopefully, it should work now.


    gb
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Run stand alone JMS client ...