Author: ritchiem
Date: Mon Nov 24 04:46:34 2008
New Revision: 720181

URL: http://svn.apache.org/viewvc?rev=720181&view=rev
Log:
QPID-1480 : Updated Simple Request Response code

Modified:
    
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java
    
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java

Modified: 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java?rev=720181&r1=720180&r2=720181&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Client.java
 Mon Nov 24 04:46:34 2008
@@ -53,8 +53,6 @@
 
     private InitialContext _ctx;
 
-    private static boolean TRANSACTED = true;
-    private static final boolean NOT_TRANSACTED = !TRANSACTED;
     private CountDownLatch _shutdownHook = new CountDownLatch(1);
 
     public Client()
@@ -71,7 +69,7 @@
         {
             connection = ((ConnectionFactory) 
lookupJNDI(CONNECTION_JNDI_NAME)).createConnection();
 
-            session = connection.createSession(NOT_TRANSACTED, 
Session.AUTO_ACKNOWLEDGE);
+            session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
 
             Destination requestQueue = (Queue) lookupJNDI(QUEUE_JNDI_NAME);
 
@@ -131,6 +129,15 @@
             //Handle the exception appropriately
         }
 
+        try
+        {
+            System.out.println("Sent Request Message ID :" + 
txtMessage.getJMSMessageID());
+        }
+        catch (JMSException e)
+        {
+            //Handle exception more appropriately.
+        }
+
         //Wait for the return message to arrive
         try
         {
@@ -161,7 +168,7 @@
      */
     public void onMessage(Message message)
     {
-        String messageText = null;
+        String messageText;
         try
         {
             if (message instanceof TextMessage)

Modified: 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java?rev=720181&r1=720180&r2=720181&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/simple/reqresp/Server.java
 Mon Nov 24 04:46:34 2008
@@ -37,10 +37,15 @@
 import javax.naming.NamingException;
 import java.util.Properties;
 import java.util.concurrent.CountDownLatch;
+import java.io.BufferedReader;
+import java.io.BufferedInputStream;
+import java.io.Reader;
+import java.io.InputStreamReader;
+import java.io.IOException;
 
 public class Server implements MessageListener
 {
-    final String BROKER = "tcp://localhost:1234";
+    final String BROKER = "localhost";
 
     final String INITIAL_CONTEXT_FACTORY = 
"org.apache.qpid.jndi.PropertiesFileInitialContextFactory";
 
@@ -50,9 +55,6 @@
     final String QUEUE_JNDI_NAME = "queue";
     final String QUEUE_NAME = "example.RequestQueue";
 
-    private static boolean TRANSACTED = true;
-    private static final boolean NOT_TRANSACTED = !TRANSACTED;
-
 
     private InitialContext _ctx;
     private Session _session;
@@ -68,7 +70,7 @@
         {
             connection = ((ConnectionFactory) 
lookupJNDI(CONNECTION_JNDI_NAME)).createConnection();
 
-            _session = connection.createSession(NOT_TRANSACTED, 
Session.AUTO_ACKNOWLEDGE);
+            _session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
 
             Destination requestQueue = (Queue) lookupJNDI(QUEUE_JNDI_NAME);
 
@@ -92,6 +94,8 @@
             return;
         }
 
+        System.out.println("Server process started and waiting for messages.");
+
         //Wait to process an single message then quit.
         try
         {
@@ -135,10 +139,19 @@
             //Set the correlation ID from the received message to be the 
correlation id of the response message
             //this lets the client identify which message this is a response 
to if it has more than
             //one outstanding message to the server
-            response.setJMSCorrelationID(message.getJMSCorrelationID());
+            response.setJMSCorrelationID(message.getJMSMessageID());
+
+            try
+            {
+                System.out.println("Received message press enter to send 
response....");
+                new BufferedReader(new 
InputStreamReader(System.in)).readLine();
+            }
+            catch (IOException e)
+            {
+                //Error attemptying to pause
+            }
 
-            //Send the response to the Destination specified by the JMSReplyTo 
field of the received message,
-            //this is presumably a temporary queue created by the client
+            //Send the response to the Destination specified by the JMSReplyTo 
field of the received message.            
             _replyProducer.send(message.getJMSReplyTo(), response);
         }
         catch (JMSException e)


Reply via email to