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 f2608355c891ff4aabe49c2c3665bb13083c3f8a
Author: Andrea Cosentino <anco...@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 7eb6650..143c532 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 5c665d5..c9835be 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
@@ -62,7 +62,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)) {
@@ -130,7 +130,7 @@ public class SlackConsumer extends 
ScheduledBatchPollingConsumer {
 
     private String getChannelId(String channel) throws IOException, 
ParseException {
         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 57b7e4c..1e75df0 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
@@ -54,6 +54,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
@@ -169,6 +171,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);
     }

Reply via email to