You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/06/30 12:16:36 UTC

svn commit: r789650 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/JmsProducer.java test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java

Author: davsclaus
Date: Tue Jun 30 10:16:36 2009
New Revision: 789650

URL: http://svn.apache.org/viewvc?rev=789650&view=rev
Log:
Added unit test based on user forum issue with custom JMSReplyTo and inOnly route.

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java   (with props)
Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java?rev=789650&r1=789649&r2=789650&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java Tue Jun 30 10:16:36 2009
@@ -301,7 +301,9 @@
                 // as we are not out capable and thus do not expect a reply, and therefore
                 // the consumer of this message we send should not return a reply
                 String to = destinationName != null ? destinationName : "" + destination;
-                LOG.warn("Disabling JMSReplyTo as this Exchange is not OUT capable with JMSReplyTo: " + replyTo + " to destination: " + to + " for Exchange: " + exchange);
+                LOG.warn("Disabling JMSReplyTo as this Exchange is not OUT capable with JMSReplyTo: " + replyTo
+                        + " for destination: " + to + ". Use preserveMessageQos=true to force Camel to keep the JMSReplyTo."
+                        + " Exchange: " + exchange);
                 exchange.getIn().setHeader("JMSReplyTo", null);
             }
         }

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java?rev=789650&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java Tue Jun 30 10:16:36 2009
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jms.issues;
+
+import javax.jms.Destination;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.camel.component.ActiveMQComponent;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jms.JmsConstants;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.springframework.jms.core.JmsTemplate;
+import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
+
+/**
+ * @version $Revision$
+ */
+public class JmsCustomJMSReplyToIssueTest extends ContextTestSupport {
+
+    private ActiveMQComponent amq;
+
+    public void testCustomJMSReplyTo() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Bye World");
+
+        // start a inOnly route
+        template.sendBody("direct:start", "Hello World");
+
+        // now consume using something that is not Camel
+        Thread.sleep(1000);
+
+        JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
+        TextMessage msg = (TextMessage) jms.receive("in");
+        assertEquals("Hello World", msg.getText());
+
+        // there should be a JMSReplyTo so we know where to send the reply
+        Destination replyTo = msg.getJMSReplyTo();
+        assertEquals("queue://myReplyQueue", replyTo.toString());
+
+        // send reply
+        template.sendBody("activemq:" + replyTo.toString(), "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+        amq = activeMQComponent("vm://localhost?broker.persistent=false&broker.useJmx=false");
+        camelContext.addComponent("activemq", amq);
+
+        return camelContext;
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("direct:start").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getOut().setBody("Hello World");
+                        // use our custom JMSReplyTo to decide where the reply should be sent
+                        exchange.getOut().setHeader(JmsConstants.JMS_REPLY_DESTINATION, "myReplyQueue");
+                    }
+                // must preserve QoS so Camel will send JMSReplyTo even if message is inOnly
+                }).to("activemq:queue:in?preserveMessageQos=true");
+
+                from("activemq:queue:myReplyQueue").to("mock:result");
+            }
+        };
+    }
+
+}

Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsCustomJMSReplyToIssueTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date