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/11/30 10:09:22 UTC

[camel] 01/16: CAMEL-12925 - Camel-Slack: Consumer must be able to use a different server than the default one

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

acosentino pushed a commit to branch sandbox/camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 905176f1a7c4f0a37b46d16ecdc940d6715cb423
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Nov 12 14:16:16 2018 +0100

    CAMEL-12925 - Camel-Slack: Consumer must be able to use a different server than the default one
---
 components/camel-slack/src/main/docs/slack-component.adoc   |  3 ++-
 .../component/slack/SlackComponentVerifierExtension.java    |  2 +-
 .../org/apache/camel/component/slack/SlackConsumer.java     |  4 ++--
 .../org/apache/camel/component/slack/SlackEndpoint.java     | 13 +++++++++++++
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/components/camel-slack/src/main/docs/slack-component.adoc b/components/camel-slack/src/main/docs/slack-component.adoc
index a7c5699..329fd2d 100644
--- a/components/camel-slack/src/main/docs/slack-component.adoc
+++ b/components/camel-slack/src/main/docs/slack-component.adoc
@@ -77,7 +77,7 @@ with the following path and query parameters:
 |===
 
 
-==== Query Parameters (25 parameters):
+==== Query Parameters (26 parameters):
 
 
 [width="100%",cols="2,5,^1,2",options="header"]
@@ -86,6 +86,7 @@ with the following path and query parameters:
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
 | *maxResults* (consumer) | The Max Result for the poll | 10 | String
 | *sendEmptyMessageWhenIdle* (consumer) | If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean
+| *serverUrl* (consumer) | The Server URL of the Slack instance | https://slack.com | String
 | *token* (consumer) | The token to use |  | String
 | *exceptionHandler* (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |  | ExceptionHandler
 | *exchangePattern* (consumer) | Sets the exchange pattern when the consumer creates an exchange. |  | ExchangePattern
diff --git a/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackComponentVerifierExtension.java b/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackComponentVerifierExtension.java
index b4b0d5f..b8c10fc 100644
--- a/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackComponentVerifierExtension.java
+++ b/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackComponentVerifierExtension.java
@@ -111,7 +111,7 @@ public class SlackComponentVerifierExtension extends DefaultComponentVerifierExt
 
             try {
                 HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
-                HttpPost httpPost = new HttpPost("https://slack.com/api/channels.list");
+                HttpPost httpPost = new HttpPost(parameters.get("serverUrl") + "/api/channels.list");
 
                 List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
                 params.add(new BasicNameValuePair("token", token));
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 a78dfe8..0295779 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
@@ -61,7 +61,7 @@ public class SlackConsumer extends ScheduledBatchPollingConsumer {
         Queue<Exchange> exchanges;
 
         HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
-        HttpPost httpPost = new HttpPost("https://slack.com/api/channels.history");
+        HttpPost httpPost = new HttpPost(slackEndpoint.getServerUrl() + "/api/channels.history");
         List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
         params.add(new BasicNameValuePair("channel", channelId));
         if (ObjectHelper.isNotEmpty(timestamp)) {
@@ -129,7 +129,7 @@ public class SlackConsumer extends ScheduledBatchPollingConsumer {
 
     private String getChannelId(String channel) throws IOException, DeserializationException {
         HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
-        HttpPost httpPost = new HttpPost("https://slack.com/api/channels.list");
+        HttpPost httpPost = new HttpPost(slackEndpoint.getServerUrl() + "/api/channels.list");
 
         List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
         params.add(new BasicNameValuePair("token", slackEndpoint.getToken()));
diff --git a/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackEndpoint.java b/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackEndpoint.java
index e36096f..8bec47f 100644
--- a/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackEndpoint.java
+++ b/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackEndpoint.java
@@ -53,6 +53,8 @@ public class SlackEndpoint extends ScheduledPollEndpoint {
     private String token;
     @UriParam(label = "consumer", defaultValue = "10")
     private String maxResults = "10";
+    @UriParam(label = "consumer", defaultValue = "https://slack.com")
+    private String serverUrl = "https://slack.com";
 
     /**
      * Constructor for SlackEndpoint
@@ -168,6 +170,17 @@ public class SlackEndpoint extends ScheduledPollEndpoint {
         this.maxResults = maxResult;
     }
 
+    public String getServerUrl() {
+        return serverUrl;
+    }
+    
+    /**
+     * The Server URL of the Slack instance
+     */
+    public void setServerUrl(String serverUrl) {
+        this.serverUrl = serverUrl;
+    }
+
     public Exchange createExchange(JSONObject object) {
         return createExchange(getExchangePattern(), object);
     }