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/03/24 10:36:34 UTC

svn commit: r757693 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/ test/java/org/apache/camel/component/jms/

Author: davsclaus
Date: Tue Mar 24 09:36:29 2009
New Revision: 757693

URL: http://svn.apache.org/viewvc?rev=757693&view=rev
Log:
CAMEL-1461: JMSProducer only sets JMSReplyTo if exchange is out capable. Fixed a NPE.

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithInOnlyTest.java   (with props)
Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java?rev=757693&r1=757692&r2=757693&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/EndpointMessageListener.java Tue Mar 24 09:36:29 2009
@@ -88,8 +88,8 @@
                         cause = exchange.getException();
                         sendReply = true;
                     } else {
-                        // only throw exception if endpoint is not configured to transfer exceptions
-                        // back to caller
+                        // only throw exception if endpoint is not configured to transfer exceptions back to caller
+                        // do not send a reply but wrap and rethrow the exception
                         rce = wrapRuntimeCamelException(exchange.getException());
                     }
                 } else if (exchange.getFault().getBody() != null) {
@@ -97,14 +97,14 @@
                     body = exchange.getFault();
                     sendReply = true;
                 }
-            } else {
+            } else if (exchange.getOut(false) != null) {
                 // process OK so get the reply
                 body = exchange.getOut(false);
                 sendReply = true;
             }
 
             // send the reply if we got a response and the exchange is out capable
-            if (sendReply && !disableReplyTo && exchange.getPattern().isOutCapable()) {
+            if (rce == null && sendReply && !disableReplyTo && exchange.getPattern().isOutCapable()) {
                 sendReply(replyDestination, message, exchange, body, cause);
             }
 

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java?rev=757693&r1=757692&r2=757693&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsBinding.java Tue Mar 24 09:36:29 2009
@@ -47,6 +47,7 @@
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -215,6 +216,7 @@
                 // create jms message containg the caused exception
                 answer = createJmsMessage(cause, session);
             } else {
+                ObjectHelper.notNull(camelMessage, "message body");
                 // create regular jms message using the camel message body
                 answer = createJmsMessage(exchange, camelMessage.getBody(), camelMessage.getHeaders(), session, exchange.getContext());
                 appendJmsProperties(answer, exchange, camelMessage);
@@ -249,7 +251,14 @@
             if (headerName.equals("JMSCorrelationID")) {
                 jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class, headerValue));
             } else if (headerName.equals("JMSReplyTo") && headerValue != null) {
-                jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange, Destination.class, headerValue));
+                if (exchange.getPattern().isOutCapable()) {
+                    // only set the JMSReply if the Exchange supports Out
+                    jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange, Destination.class, headerValue));
+                } else {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Exchange is not out capable, Ignoring JMSReplyTo: " + headerValue);
+                    }
+                }
             } else if (headerName.equals("JMSType")) {
                 jmsMessage.setJMSType(ExchangeHelper.convertToType(exchange, String.class, headerValue));
             } else if (LOG.isDebugEnabled()) {

Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithInOnlyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithInOnlyTest.java?rev=757693&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithInOnlyTest.java (added)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsRouteWithInOnlyTest.java Tue Mar 24 09:36:29 2009
@@ -0,0 +1,95 @@
+/**
+ * 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;
+
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * Unit test inspired by user forum
+ *
+ * @version $Revision$
+ */
+public class JmsRouteWithInOnlyTest extends ContextTestSupport {
+
+    protected String componentName = "activemq";
+
+    public void testSendOrder() throws Exception {
+        MockEndpoint inbox = getMockEndpoint("mock:inbox");
+        inbox.expectedBodiesReceived("Camel in Action");
+
+        MockEndpoint order = getMockEndpoint("mock:topic");
+        order.expectedBodiesReceived("Camel in Action");
+
+        Object out = template.requestBody("activemq:queue:inbox", "Camel in Action");
+        assertEquals("OK: Camel in Action", out);
+
+        assertMockEndpointsSatisfied();
+
+        // assert MEP
+        assertEquals(ExchangePattern.InOut, inbox.getReceivedExchanges().get(0).getPattern());
+        assertEquals(ExchangePattern.InOnly, order.getReceivedExchanges().get(0).getPattern());
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("orderService", new MyOrderServiceBean());
+        return jndi;
+    }
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent(componentName, jmsComponentClientAcknowledge(connectionFactory));
+
+        return camelContext;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("activemq:queue:inbox")
+                    .to("mock:inbox")
+                    .inOnly("activemq:topic:order")
+                    .beanRef("orderService", "handleOrder");
+
+                from("activemq:topic:order")
+                    .to("mock:topic");
+            }
+        };
+    }
+
+    public static class MyOrderServiceBean {
+
+        public String handleOrder(String body) {
+            return "OK: " + body;
+        }
+
+    }
+}

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

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