[jboss-svn-commits] JBL Code SVN: r23410 - in labs/jbossesb/workspace/skeagh/examples/helloworld: src/main/java/org/jboss/esb/examples and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 9 17:10:22 EDT 2008


Author: beve
Date: 2008-10-09 17:10:22 -0400 (Thu, 09 Oct 2008)
New Revision: 23410

Modified:
   labs/jbossesb/workspace/skeagh/examples/helloworld/pom.xml
   labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/java/org/jboss/esb/examples/JmsClient.java
Log:
Added the option for the JmsClient to prompt the user for the message payload.

Modified: labs/jbossesb/workspace/skeagh/examples/helloworld/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/helloworld/pom.xml	2008-10-09 20:28:16 UTC (rev 23409)
+++ labs/jbossesb/workspace/skeagh/examples/helloworld/pom.xml	2008-10-09 21:10:22 UTC (rev 23410)
@@ -36,7 +36,7 @@
                     <mainClass>org.jboss.esb.examples.JmsClient</mainClass>
 					<arguments>
 						<argument>jbossesb.TestQueue</argument>
-						<argument>Message payload text...</argument>
+						<!--argument>Message payload text...</argument-->
 					</arguments>
                 </configuration>
             </plugin>

Modified: labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/java/org/jboss/esb/examples/JmsClient.java
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/java/org/jboss/esb/examples/JmsClient.java	2008-10-09 20:28:16 UTC (rev 23409)
+++ labs/jbossesb/workspace/skeagh/examples/helloworld/src/main/java/org/jboss/esb/examples/JmsClient.java	2008-10-09 21:10:22 UTC (rev 23410)
@@ -20,6 +20,9 @@
  */
 package org.jboss.esb.examples;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 import java.util.Arrays;
 
 import javax.jms.Destination;
@@ -39,6 +42,9 @@
  * Usage:
  * java org.jboss.esb.examples.JmsClient destination "Message content goes here"
  *
+ * The second argument is optional and if left out the user will be prompted
+ * to enter a message payload.
+ *
  * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
  *
  */
@@ -58,14 +64,14 @@
      */
     public static void main(final String... args)
     {
-        if (args.length != 2)
+        if (args.length < 1)
         {
             printUsage();
             System.exit(-1);
         }
 
         final String destinationName = args[0];
-        final String payload = args[1];
+        String payload = getPayload(args);
 
         try
         {
@@ -138,4 +144,38 @@
         System.err.println("*****************************************************************************");
     }
 
+    /**
+     * Prompts for the message payload to be entered from the command line.
+     *
+     * @param message The message to be displayed to the user.
+     * @return String The text typed at the command line by the user.
+     */
+    private static String getPayloadFromCommandLine(final String message)
+    {
+        try
+        {
+            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+            System.out.print("> " + message);
+            return in.readLine();
+        }
+        catch (final IOException e)
+        {
+            e.printStackTrace();
+        }
+        System.out.println(System.getProperty("line.separator"));
+        return null;
+    }
+
+    /**
+     * Get the payload from either the command line of from the
+     * second argument passed to the main method.
+     *
+     * @param args The args array passed to the main method.
+     * @return String The message payload.
+     */
+    private static String getPayload(final String... args)
+    {
+        return args.length == 2 ? args[1] : getPayloadFromCommandLine("Specify message payload test >");
+    }
+
 }




More information about the jboss-svn-commits mailing list