Author: arnaudsimon
Date: Fri Dec 7 09:14:44 2007
New Revision: 602154
URL: http://svn.apache.org/viewvc?rev=602154&view=rev
Log:
changed for accepting messages from python and c++
Added:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java
(contents, props changed)
- copied, changed from r602086,
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java
(contents, props changed)
- copied, changed from r602086,
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java
Removed:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/PubSubRequestor.java
Modified:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
Modified:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java?rev=602154&r1=602153&r2=602154&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java
(original)
+++
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/common/BaseExample.java
Fri Dec 7 09:14:44 2007
@@ -49,7 +49,7 @@
private static final String DEFAULT_CONNECTION_FACTORY_NAME =
"ConnectionFactory";
/* Default number of messages to process. */
- private static final int DEFAULT_NUMBER_MESSAGES = 1;
+ private static final int DEFAULT_NUMBER_MESSAGES = 10;
/* JNDI provider URL. */
private String _providerURL;
Modified:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java?rev=602154&r1=602153&r2=602154&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
(original)
+++
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java
Fri Dec 7 09:14:44 2007
@@ -79,23 +79,19 @@
// Create a Message
TextMessage message;
System.out.println(CLASS + ": Creating a TestMessage to send to
the destination");
- message = session.createTextMessage();
-
- // Set a property for illustrative purposes
- //message.setDoubleProperty("Amount", 10.1);
// Loop to publish the requested number of messages.
for (int i = 1; i < getNumberMessages() + 1; i++)
{
// NOTE: We have NOT HAD TO START THE CONNECTION TO BEGIN
SENDING messages,
// this is different to the consumer end as a CONSUMERS
CONNECTIONS MUST BE STARTED BEFORE RECEIVING.
- message.setText("Message " + i);
+ message = session.createTextMessage("Message " + i);
System.out.println(CLASS + ": Sending message: " + i);
messageProducer.send(message, getDeliveryMode(),
Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
}
// And send a final message to indicate termination.
- message.setText("That's all, folks!");
+ message = session.createTextMessage("That's all, folks!");
messageProducer.send(message, getDeliveryMode(),
Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
// Close the connection to the broker
Copied:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java
(from r602086,
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java)
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java?p2=incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java&p1=incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java&r1=602086&r2=602154&rev=602154&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/P2PRequestor.java
(original)
+++
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java
Fri Dec 7 09:14:44 2007
@@ -28,23 +28,23 @@
* This example illustrates the use of the JMS utility class
<code>QueueRequestor</code>
* which provides a synchronous RPC-like abstraction using temporary
destinations
* to deliver responses back to the client.
- *
+ * <p/>
* <p>Run with <code>-help</code> argument for a description of command line
arguments.
- *
*/
-public class P2PRequestor extends BaseExample
+public class Client extends BaseExample
{
/* Used in log output. */
- private static final String CLASS = "P2PRequestor";
+ private static final String CLASS = "Client";
/* The queue name */
private String _queueName;
/**
- * Create a P2PRequestor client.
+ * Create a Client client.
+ *
* @param args Command line arguments.
*/
- public P2PRequestor(String[] args)
+ public Client(String[] args)
{
super(CLASS, args);
_queueName = _argProcessor.getStringArgument("-queueName");
@@ -52,13 +52,14 @@
/**
* Run the message requestor example.
+ *
* @param args Command line arguments.
*/
public static void main(String[] args)
{
- _options.put("-queueName", "The queue name");
- _defaults.put("-queueName", "message_queue");
- P2PRequestor requestor = new P2PRequestor(args);
+ _options.put("-queueName", "The queue name");
+ _defaults.put("-queueName", "request");
+ Client requestor = new Client(args);
requestor.runTest();
}
@@ -74,7 +75,8 @@
// As this application is using a MessageConsumer we need to set
an ExceptionListener on the connection
// so that errors raised within the JMS client library can be
reported to the application
- System.out.println(CLASS + ": Setting an ExceptionListener on the
connection as sample uses a MessageConsumer");
+ System.out.println(
+ CLASS + ": Setting an ExceptionListener on the connection
as sample uses a MessageConsumer");
connection.setExceptionListener(new ExceptionListener()
{
@@ -109,7 +111,7 @@
request = session.createTextMessage();
- // Get the number of times that this sample should request service
+ // Get the number of times that this sample should request service
for (int i = 0; i < getNumberMessages(); i++)
{
request = session.createTextMessage("Twas brillig, and the
slithy toves");
@@ -126,8 +128,8 @@
// And send a final message to indicate termination.
request.setText("That's all, folks!");
MessageProducer messageProducer =
session.createProducer(destination);
- messageProducer.send(request, getDeliveryMode(),
Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
-
+ messageProducer.send(request, getDeliveryMode(),
Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+
// Close the connection to the server
System.out.println(CLASS + ": Closing connection");
connection.close();
@@ -142,15 +144,24 @@
}
}
- private void sendReceive(TextMessage request, QueueRequestor requestor)
throws JMSException
+ private void sendReceive(TextMessage request, QueueRequestor requestor)
throws JMSException
{
Message response;
response = requestor.request(request);
System.out.println(CLASS + ": \tRequest Content= " +
request.getText());
// Print out the details of the response received
+ String text;
if (response instanceof TextMessage)
{
- System.out.println(CLASS + ": \t Response Content= " +
((TextMessage) response).getText());
+ text = ((TextMessage) response).getText();
+ }
+ else
+ {
+ byte[] body = new byte[(int) ((BytesMessage)
response).getBodyLength()];
+ ((BytesMessage) response).readBytes(body);
+ text = new String(body);
}
+ System.out.println(CLASS + ": \tResponse Content= " + text);
}
}
+
Propchange:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Client.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java
(from r602086,
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java)
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java?p2=incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java&p1=incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java&r1=602086&r2=602154&rev=602154&view=diff
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/MessageMirror.java
(original)
+++
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java
Fri Dec 7 09:14:44 2007
@@ -30,10 +30,10 @@
* received message has a ReplyTo header then a new response message is sent
* to that specified destination.
*/
-public class MessageMirror extends BaseExample
+public class Server extends BaseExample
{
/* Used in log output. */
- private static final String CLASS = "MessageMirror";
+ private static final String CLASS = "Server";
/* The destination type */
private String _destinationType;
@@ -42,11 +42,11 @@
private String _destinationName;
/**
- * Create a MessageMirror client.
+ * Create a Server client.
*
* @param args Command line arguments.
*/
- public MessageMirror(String[] args)
+ public Server(String[] args)
{
super(CLASS, args);
_destinationType = _argProcessor.getStringArgument("-destinationType");
@@ -63,9 +63,9 @@
_options.put("-destinationType", "Destination Type: queue/topic");
_defaults.put("-destinationType", "queue");
_options.put("-destinationName", "Destination Name");
- _defaults.put("-destinationName", "message_queue");
- MessageMirror messageMirror = new MessageMirror(args);
- messageMirror.runTest();
+ _defaults.put("-destinationName", "request");
+ Server server = new Server(args);
+ server.runTest();
}
/**
@@ -140,30 +140,38 @@
requestMessage = messageConsumer.receive();
- // Print out the details of the just received message
- System.out.println(CLASS + ": Message received:");
-
+ String text;
if (requestMessage instanceof TextMessage)
{
- if (((TextMessage)
requestMessage).getText().equals("That's all, folks!"))
- {
- System.out.println("Received final message for " +
destination);
- end = true;
- }
- System.out.println("\tContents = " + ((TextMessage)
requestMessage).getText());
+ text = ((TextMessage) requestMessage).getText();
+ }
+ else
+ {
+ byte[] body = new byte[(int) ((BytesMessage)
requestMessage).getBodyLength()];
+ ((BytesMessage) requestMessage).readBytes(body);
+ text = new String(body);
+ }
+
+
+ if (text.equals("That's all, folks!"))
+ {
+ System.out.println(CLASS + ": Received final message for "
+ destination);
+ end = true;
+ }
+ else
+ {
+ System.out.println(CLASS + ": \tContents = " + text);
}
// Now bounce the message if a ReplyTo header was set.
if (requestMessage.getJMSReplyTo() != null)
{
System.out.println(CLASS + ": Activating response queue
listener for: " + destination);
- responseMessage =
- session.createTextMessage();
- if (requestMessage instanceof TextMessage)
- {
- responseMessage.setText(((TextMessage)
requestMessage).getText().toUpperCase());
- System.out.println(CLASS + ": \tResponse = " +
responseMessage.getText());
- }
+ responseMessage = session.createTextMessage();
+
+ responseMessage.setText(text.toUpperCase());
+ System.out.println(CLASS + ": \tResponse = " +
responseMessage.getText());
+
messageProducer =
session.createProducer(requestMessage.getJMSReplyTo());
messageProducer.send(responseMessage);
}
Propchange:
incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/requestResponse/Server.java
------------------------------------------------------------------------------
svn:eol-style = native