You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/09/13 10:08:19 UTC

[camel] 01/02: CAMEL-12806 - Camel-Slack: Add a check on the messages list while consuming

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 99b2c8320e0114128b08253f8c311441e07128ca
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Sep 13 12:02:56 2018 +0200

    CAMEL-12806 - Camel-Slack: Add a check on the messages list while consuming
---
 .../camel/component/slack/SlackConsumer.java       | 26 ++++++++++++----------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java b/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
index 948a38c..5ae6f2a 100644
--- a/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
+++ b/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackConsumer.java
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.slack;
 
+import static org.apache.camel.component.slack.utils.SlackUtils.readResponse;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -41,8 +43,6 @@ import org.json.simple.parser.ParseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.apache.camel.component.slack.utils.SlackUtils.readResponse;
-
 public class SlackConsumer extends ScheduledBatchPollingConsumer {
 
     private static final Logger LOG = LoggerFactory.getLogger(SlackConsumer.class);
@@ -85,17 +85,19 @@ public class SlackConsumer extends ScheduledBatchPollingConsumer {
 
     private Queue<Exchange> createExchanges(List list) {
         Queue<Exchange> answer = new LinkedList<>();
-        Iterator it = list.iterator();
-        int i = 0;
-        while (it.hasNext()) {
-            Object object = (Object)it.next();
-            JSONObject singleMess = (JSONObject)object;
-            if (i == 0) {
-                timestamp = (String)singleMess.get("ts");
+        if (ObjectHelper.isNotEmpty(list)) {
+            Iterator it = list.iterator();
+            int i = 0;
+            while (it.hasNext()) {
+                Object object = (Object)it.next();
+                JSONObject singleMess = (JSONObject)object;
+                if (i == 0) {
+                    timestamp = (String)singleMess.get("ts");
+                }
+                i++;
+                Exchange exchange = slackEndpoint.createExchange(singleMess);
+                answer.add(exchange);
             }
-            i++;
-            Exchange exchange = slackEndpoint.createExchange(singleMess);
-            answer.add(exchange);
         }
         return answer;
     }