camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-8696: Allow ApnsNotification/EnhancedApnsNotification instances to be send to apns endpoints. Thanks to Justin Heesemann for the patch.
Date Mon, 27 Apr 2015 06:16:23 GMT
Repository: camel
Updated Branches:
  refs/heads/master 2ec2b8750 -> 7ca0c8756


CAMEL-8696: Allow ApnsNotification/EnhancedApnsNotification instances to be send to apns endpoints.
Thanks to Justin Heesemann for the patch.


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

Branch: refs/heads/master
Commit: 7ca0c8756fa237ba1b9c9caf662dffd0df66c4ae
Parents: 2ec2b87
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Apr 27 08:19:52 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Apr 27 08:19:52 2015 +0200

----------------------------------------------------------------------
 .../camel/component/apns/ApnsProducer.java      | 19 +++++++++++++-----
 .../camel/component/apns/model/MessageType.java |  2 +-
 .../camel/component/apns/ApnsProducerTest.java  | 21 ++++++++++++++++++++
 3 files changed, 36 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7ca0c875/components/camel-apns/src/main/java/org/apache/camel/component/apns/ApnsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-apns/src/main/java/org/apache/camel/component/apns/ApnsProducer.java
b/components/camel-apns/src/main/java/org/apache/camel/component/apns/ApnsProducer.java
index 76f6a49..ce021fb 100644
--- a/components/camel-apns/src/main/java/org/apache/camel/component/apns/ApnsProducer.java
+++ b/components/camel-apns/src/main/java/org/apache/camel/component/apns/ApnsProducer.java
@@ -23,6 +23,7 @@ import java.util.Date;
 import java.util.List;
 
 import com.notnoop.apns.APNS;
+import com.notnoop.apns.ApnsNotification;
 import com.notnoop.exceptions.ApnsException;
 import org.apache.camel.Exchange;
 import org.apache.camel.component.apns.model.ApnsConstants;
@@ -64,8 +65,18 @@ public class ApnsProducer extends DefaultProducer {
     }
 
     private void notify(Exchange exchange) throws ApnsException {
-        String message = exchange.getIn().getBody(String.class);
+        MessageType messageType = getHeaderMessageType(exchange, MessageType.STRING);
+
+        if (messageType == MessageType.APNS_NOTIFICATION) {
+            ApnsNotification apnsNotification = exchange.getIn().getBody(ApnsNotification.class);
+            getEndpoint().getApnsService().push(apnsNotification);
+        } else {
+            constructNotificationAndNotify(exchange, messageType);
+        }
+    }
 
+    private void constructNotificationAndNotify(Exchange exchange, MessageType messageType)
{
+        String payload;
         Collection<String> tokens;
         if (isTokensConfiguredUsingUri()) {
             if (hasTokensHeader(exchange)) {
@@ -76,13 +87,11 @@ public class ApnsProducer extends DefaultProducer {
             String tokensHeader = getHeaderTokens(exchange);
             tokens = extractTokensFromString(tokensHeader);
         }
-
-        MessageType messageType = getHeaderMessageType(exchange, MessageType.STRING);
-
-        String payload;
         if (messageType == MessageType.STRING) {
+            String message = exchange.getIn().getBody(String.class);
             payload = APNS.newPayload().alertBody(message).build();
         } else {
+            String message = exchange.getIn().getBody(String.class);
             payload = message;
         }
         Date expiry = exchange.getIn().getHeader(ApnsConstants.HEADER_EXPIRY, Date.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/7ca0c875/components/camel-apns/src/main/java/org/apache/camel/component/apns/model/MessageType.java
----------------------------------------------------------------------
diff --git a/components/camel-apns/src/main/java/org/apache/camel/component/apns/model/MessageType.java
b/components/camel-apns/src/main/java/org/apache/camel/component/apns/model/MessageType.java
index bbba780..9b90271 100644
--- a/components/camel-apns/src/main/java/org/apache/camel/component/apns/model/MessageType.java
+++ b/components/camel-apns/src/main/java/org/apache/camel/component/apns/model/MessageType.java
@@ -18,6 +18,6 @@ package org.apache.camel.component.apns.model;
 
 public enum MessageType {
 
-    STRING, PAYLOAD;
+    STRING, PAYLOAD, APNS_NOTIFICATION;
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7ca0c875/components/camel-apns/src/test/java/org/apache/camel/component/apns/ApnsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-apns/src/test/java/org/apache/camel/component/apns/ApnsProducerTest.java
b/components/camel-apns/src/test/java/org/apache/camel/component/apns/ApnsProducerTest.java
index 3fe4502..c130c76 100644
--- a/components/camel-apns/src/test/java/org/apache/camel/component/apns/ApnsProducerTest.java
+++ b/components/camel-apns/src/test/java/org/apache/camel/component/apns/ApnsProducerTest.java
@@ -26,6 +26,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.apns.factory.ApnsServiceFactory;
 import org.apache.camel.component.apns.model.ApnsConstants;
+import org.apache.camel.component.apns.model.MessageType;
 import org.apache.camel.component.apns.util.ApnsUtils;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.After;
@@ -65,6 +66,23 @@ public class ApnsProducerTest extends CamelTestSupport {
         assertArrayEquals(apnsNotification.marshall(), server.received.toByteArray());
     }
 
+
+    @Test(timeout = 5000)
+    public void testProducerWithApnsNotification() throws InterruptedException {
+        String message = "Hello World";
+        String messagePayload = APNS.newPayload().alertBody(message).build();
+
+        final EnhancedApnsNotification apnsNotification =
+                new EnhancedApnsNotification(14, EnhancedApnsNotification.MAXIMUM_EXPIRY,
FAKE_TOKEN, messagePayload);
+        server.stopAt(apnsNotification.length());
+
+        template.sendBody("direct:testWithApnsNotification", apnsNotification);
+
+        server.messages.acquire();
+        assertArrayEquals(apnsNotification.marshall(), server.received.toByteArray());
+
+    }
+
     protected CamelContext createCamelContext() throws Exception {
         CamelContext camelContext = super.createCamelContext();
 
@@ -81,6 +99,9 @@ public class ApnsProducerTest extends CamelTestSupport {
         return new RouteBuilder() {
             public void configure() throws Exception {
                 from("direct:test").setHeader(ApnsConstants.HEADER_TOKENS, constant(FAKE_TOKEN)).to("apns:notify");
+                from("direct:testWithApnsNotification")
+                        .setHeader(ApnsConstants.HEADER_MESSAGE_TYPE, constant(MessageType.APNS_NOTIFICATION.name()))
+                        .to("apns:notify");
             }
         };
     }


Mime
View raw message