File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run stand alone JMS client ...

 
Ying Zhou
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Glen Cai
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is J2EE client container becoming a stardard in J2EE1.4?
 
Howard Kushner
author
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
     
    siva kumar
    Ranch Hand
    Posts: 86
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 44
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic