camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r731836 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/converter/jaxp/ components/camel-jms/src/main/java/org/apache/camel/component/jms/ components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/
Date Tue, 06 Jan 2009 05:31:45 GMT
Author: davsclaus
Date: Mon Jan  5 21:31:43 2009
New Revision: 731836

URL: http://svn.apache.org/viewvc?rev=731836&view=rev
Log:
CAMEL-1213: Fixed setting exchanged id in camel-jms. Polished to use ObjectHelper.notNull

Added:
    activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
    activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java?rev=731836&r1=731835&r2=731836&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/BytesSource.java
Mon Jan  5 21:31:43 2009
@@ -23,6 +23,8 @@
 
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.camel.util.ObjectHelper;
+
 /**
  * A helper class which provides a JAXP {@link javax.xml.transform.Source Source} from a
byte[]
  * which can be read as many times as required.
@@ -33,10 +35,12 @@
     private byte[] data;
 
     public BytesSource(byte[] data) {
+        ObjectHelper.notNull(data, "data");
         this.data = data;
     }
 
     public BytesSource(byte[] data, String systemId) {
+        ObjectHelper.notNull(data, "data");
         this.data = data;
         setSystemId(systemId);
     }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java?rev=731836&r1=731835&r2=731836&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/jaxp/StringSource.java
Mon Jan  5 21:31:43 2009
@@ -28,6 +28,8 @@
 
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.camel.util.ObjectHelper;
+
 /**
  * A helper class which provides a JAXP {@link javax.xml.transform.Source Source} from a
String which can
  * be read as many times as required.
@@ -42,9 +44,7 @@
     }
 
     public StringSource(String text) {
-        if (text == null) {
-            throw new NullPointerException("text cannot be null");
-        }
+        ObjectHelper.notNull(text, "text");
         this.text = text;
     }
 

Modified: activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java?rev=731836&r1=731835&r2=731836&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
(original)
+++ activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
Mon Jan  5 21:31:43 2009
@@ -64,16 +64,16 @@
 
     @Override
     public void copyFrom(org.apache.camel.Message that) {
-        // for performance lets not copy the messageID if we are a JMS message
         boolean copyMessageId = true;
         if (that instanceof JmsMessage) {
             JmsMessage thatMessage = (JmsMessage) that;
             this.jmsMessage = thatMessage.jmsMessage;
             if (this.jmsMessage != null) {
+                // for performance lets not copy the messageID if we are a JMS message
                 copyMessageId = false;
             }
         }
-        if (!copyMessageId) {
+        if (copyMessageId) {
             setMessageId(that.getMessageId());
         }
         setBody(that.getBody());

Added: activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java?rev=731836&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java
(added)
+++ activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsToFileMessageIdTest.java
Mon Jan  5 21:31:43 2009
@@ -0,0 +1,88 @@
+/**
+ * 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.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+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.JmsMessage;
+import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * Unit test to verify issue we had in Camel 1.4
+ */
+public class JmsToFileMessageIdTest extends ContextTestSupport {
+
+    public void testFromJmsToFileAndMessageId() throws Exception {
+        // Mock endpoint to collect message at the end of the route
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+
+        template.sendBody("activemq:foo", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+
+        return camelContext;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // Make a route from an activemq queue to a file endpoint, then try to call
getMessageId()
+                from("activemq:foo")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                // assert camel id is based on jms id 
+                                String camelId = exchange.getIn().getMessageId();
+                                assertNotNull(camelId);
+
+                                JmsMessage jms = (JmsMessage) exchange.getIn();
+                                String jmsId = jms.getJmsMessage().getJMSMessageID();
+                                assertNotNull(jmsId);
+
+                                assertEquals(jmsId, camelId);
+                            }
+                        })
+                        .to("file://target/tofile")
+                        .process(new Processor() {
+                            public void process(Exchange exchange) {
+                                // in Camel 1.4 or older this caused a NPE
+                                assertNotNull(exchange.getIn().getMessageId());
+                            }
+                        })
+                        .to("mock:result");
+            }
+        };
+
+    }
+}

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

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



Mime
View raw message