FileDocCategorySizeDatePackage
HelloWorldClient.javaAPI DocJBoss 4.2.13834Fri Jul 13 20:52:44 BST 2007org.jboss.ejb3.test.appclient.client

HelloWorldClient

public class HelloWorldClient extends Object
Comment
author
Carlo de Wolf
version
$Revision: $

Fields Summary
private static org.jboss.ejb3.test.appclient.HelloWorldService
helloWorldService
private static String
msg
private static String
result
private static javax.jms.ConnectionFactory
connectionFactory
private static javax.jms.Destination
destination
private static int
postConstructCalls
Constructors Summary
Methods Summary
public static intgetPostConstructCalls()

   
      
   
      return postConstructCalls;
   
public static java.lang.StringgetResult()

      return result;
   
public static voidmain(java.lang.String[] args)

      String name = "unspecified";
      if(args.length > 0)
         name = args[0];
      
      if(helloWorldService == null)
         throw new NullPointerException("helloWorldService is null");
      
      if(msg == null)
         throw new NullPointerException("msg is null");
      
      result = helloWorldService.sayHelloTo(name) + ", " + msg;
      
      testMDB();
   
public static voidpostConstruct()

      postConstructCalls++;
   
public static voidtestMDB()

      if(connectionFactory == null)
         throw new NullPointerException("connectionFactory is null");
      
      if(destination == null)
         throw new NullPointerException("destination is null");
      
      try
      {
         Connection conn = connectionFactory.createConnection();
         Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
         
         Queue replyTo = session.createTemporaryQueue();
         TextMessage msg = session.createTextMessage("Hello world");
         msg.setJMSReplyTo(replyTo);
         
         MessageConsumer consumer = session.createConsumer(replyTo);
         conn.start();
         
         MessageProducer producer = session.createProducer(destination);
         producer.send(destination, msg);
         
         TextMessage reply = (TextMessage) consumer.receive(2000);
         System.out.println("reply = " + reply.getText());
         
         producer.close();
         conn.stop();
         consumer.close();
         session.close();
      }
      catch(Exception e)
      {
         throw new RuntimeException(e);
      }