camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hekon...@apache.org
Subject [2/2] camel git commit: Paho consumer now keeps the original MQTT message as a header.
Date Tue, 17 Mar 2015 15:39:27 GMT
Paho consumer now keeps the original MQTT message as a header.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3bcc9d48
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3bcc9d48
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3bcc9d48

Branch: refs/heads/master
Commit: 3bcc9d4824ee39a6d7eb06fa75540b4668950992
Parents: b5a5904
Author: Henryk Konsek <hekonsek@gmail.com>
Authored: Tue Mar 17 16:39:18 2015 +0100
Committer: Henryk Konsek <hekonsek@gmail.com>
Committed: Tue Mar 17 16:39:18 2015 +0100

----------------------------------------------------------------------
 .../camel/component/paho/PahoConstants.java     | 25 ++++++++++++++++++++
 .../camel/component/paho/PahoConsumer.java      |  7 +++++-
 .../camel/component/paho/PahoComponentTest.java | 20 +++++++++++++++-
 3 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3bcc9d48/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConstants.java
b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConstants.java
new file mode 100644
index 0000000..35b6a49
--- /dev/null
+++ b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConstants.java
@@ -0,0 +1,25 @@
+/**
+ * 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.paho;
+
+public final class PahoConstants {
+
+    public static final String HEADER_ORIGINAL_MESSAGE = "PahoOriginalMessage";
+
+    private PahoConstants() {
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3bcc9d48/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java
b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java
index 31f56e3..100644c 100644
--- a/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java
+++ b/components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java
@@ -28,6 +28,8 @@ import org.eclipse.paho.client.mqttv3.MqttMessage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.component.paho.PahoConstants.HEADER_ORIGINAL_MESSAGE;
+
 public class PahoConsumer extends DefaultConsumer {
 
     private static final Logger LOG = LoggerFactory.getLogger(PahoConsumer.class);
@@ -49,7 +51,10 @@ public class PahoConsumer extends DefaultConsumer {
 
             @Override
             public void messageArrived(String topic, MqttMessage message) throws Exception
{
-                Exchange exchange = ExchangeBuilder.anExchange(getEndpoint().getCamelContext()).withBody(message.getPayload()).build();
+                Exchange exchange = ExchangeBuilder.anExchange(getEndpoint().getCamelContext()).
+                        withBody(message.getPayload()).
+                        withHeader(HEADER_ORIGINAL_MESSAGE, message).
+                        build();
                 getAsyncProcessor().process(exchange, new AsyncCallback() {
                     @Override
                     public void done(boolean doneSync) {

http://git-wip-us.apache.org/repos/asf/camel/blob/3bcc9d48/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
b/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
index 07a5d5c..43674da 100644
--- a/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
+++ b/components/camel-paho/src/test/java/org/apache/camel/component/paho/PahoComponentTest.java
@@ -18,12 +18,14 @@ package org.apache.camel.component.paho;
 
 import org.apache.activemq.broker.BrokerService;
 import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.AvailablePortFinder;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
+import org.eclipse.paho.client.mqttv3.MqttMessage;
 import org.junit.Test;
 
 public class PahoComponentTest extends CamelTestSupport {
@@ -89,7 +91,7 @@ public class PahoComponentTest extends CamelTestSupport {
         mock.expectedBodiesReceived(msg);
 
         // When
-        template.sendBody("mock:test", msg);
+        template.sendBody("direct:test", msg);
 
         // Then
         mock.assertIsSatisfied();
@@ -118,4 +120,20 @@ public class PahoComponentTest extends CamelTestSupport {
         assertSame(connectOptions, pahoWithConnectOptionsFromRegistry.resolveMqttConnectOptions());
     }
 
+    @Test
+    public void shouldKeepOriginalMessageInHeader() throws InterruptedException {
+        // Given
+        final String msg = "msg";
+        mock.expectedBodiesReceived(msg);
+
+        // When
+        template.sendBody("direct:test", msg);
+
+        // Then
+        mock.assertIsSatisfied();
+        Exchange exchange = mock.getExchanges().get(0);
+        MqttMessage message = exchange.getIn().getHeader(PahoConstants.HEADER_ORIGINAL_MESSAGE,
MqttMessage.class);
+        assertEquals(msg, new String(message.getPayload()));
+    }
+
 }


Mime
View raw message