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

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


The following commit(s) were added to refs/heads/camel-4.10.x by this push:
     new 0a0e6603e3e Remove SlackHttpClient hacks, okhttp version is aligned, 
and the hack is not needed anymore
0a0e6603e3e is described below

commit 0a0e6603e3eced7a86dc1bee5310b8b644efb42b
Author: Croway <[email protected]>
AuthorDate: Tue Feb 25 17:23:31 2025 +0100

    Remove SlackHttpClient hacks, okhttp version is aligned, and the hack is 
not needed anymore
---
 components/camel-slack/pom.xml                     | 11 ------
 .../component/slack/CustomSlackHttpClient.java     | 46 ----------------------
 .../slack/SlackComponentVerifierExtension.java     |  5 ++-
 .../camel/component/slack/SlackConsumer.java       |  3 +-
 .../camel/component/slack/SlackProducer.java       |  3 +-
 5 files changed, 7 insertions(+), 61 deletions(-)

diff --git a/components/camel-slack/pom.xml b/components/camel-slack/pom.xml
index 1e6b0e9de53..14241b1953b 100644
--- a/components/camel-slack/pom.xml
+++ b/components/camel-slack/pom.xml
@@ -48,17 +48,6 @@
             <artifactId>slack-api-client</artifactId>
             <version>${slack-api-model-version}</version>
         </dependency>
-        <dependency>
-            <groupId>com.google.code.gson</groupId>
-            <artifactId>gson</artifactId>
-        </dependency>
-
-        <!-- forcing okhttp v3.x related to 
https://issues.apache.org/jira/browse/CAMEL-16336 -->
-        <dependency>
-            <groupId>com.squareup.okhttp3</groupId>
-            <artifactId>okhttp</artifactId>
-            <version>${squareup-okhttp-version}</version>
-        </dependency>
 
         <!-- test dependencies -->
         <dependency>
diff --git 
a/components/camel-slack/src/main/java/org/apache/camel/component/slack/CustomSlackHttpClient.java
 
b/components/camel-slack/src/main/java/org/apache/camel/component/slack/CustomSlackHttpClient.java
deleted file mode 100644
index 4cb8da47704..00000000000
--- 
a/components/camel-slack/src/main/java/org/apache/camel/component/slack/CustomSlackHttpClient.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.slack;
-
-import java.io.IOException;
-
-import com.slack.api.SlackConfig;
-import com.slack.api.util.http.SlackHttpClient;
-import okhttp3.MediaType;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okhttp3.Response;
-
-/**
- * Slack-api-client use the OkHttpClient v4.x.x We need to override the 
SlackHttpClient to force the function
- * postJsonBody to work with the v3.x.x
- */
-public class CustomSlackHttpClient extends SlackHttpClient {
-
-    private static final MediaType MEDIA_TYPE_APPLICATION_JSON = 
MediaType.parse("application/json; charset=utf-8");
-
-    private final SlackConfig config = SlackConfig.DEFAULT;
-    private final OkHttpClient okHttpClient = buildOkHttpClient(config);
-
-    @Override
-    public Response postJsonBody(String url, Object obj) throws IOException {
-        RequestBody body = RequestBody.create(MEDIA_TYPE_APPLICATION_JSON, 
(String) obj);
-        Request request = new Request.Builder().url(url).post(body).build();
-        return okHttpClient.newCall(request).execute();
-    }
-}
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 8b1357aec4b..ae7277082aa 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
@@ -24,6 +24,7 @@ import com.slack.api.Slack;
 import com.slack.api.SlackConfig;
 import com.slack.api.methods.response.conversations.ConversationsListResponse;
 import com.slack.api.model.ConversationType;
+import com.slack.api.util.http.SlackHttpClient;
 import com.slack.api.webhook.WebhookResponse;
 import 
org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
 import org.apache.camel.component.extension.verifier.ResultBuilder;
@@ -87,7 +88,7 @@ public class SlackComponentVerifierExtension extends 
DefaultComponentVerifierExt
 
                 SlackConfig config = SlackHelper.createSlackConfig(serverUrl);
                 WebhookResponse response
-                        = Slack.getInstance(config, new 
CustomSlackHttpClient()).send(webhookUrl, GSON.toJson(slackMessage));
+                        = Slack.getInstance(config, new 
SlackHttpClient()).send(webhookUrl, GSON.toJson(slackMessage));
 
                 // 2xx is OK, anything else we regard as failure
                 if (response.getCode() < 200 || response.getCode() > 299) {
@@ -106,7 +107,7 @@ public class SlackComponentVerifierExtension extends 
DefaultComponentVerifierExt
 
             try {
                 SlackConfig config = SlackHelper.createSlackConfig(serverUrl);
-                ConversationsListResponse response = Slack.getInstance(config, 
new CustomSlackHttpClient()).methods(token)
+                ConversationsListResponse response = Slack.getInstance(config, 
new SlackHttpClient()).methods(token)
                         .conversationsList(req -> req
                                 
.types(Collections.singletonList(ConversationType.PUBLIC_CHANNEL))
                                 .limit(1));
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 d050060ebb3..c0d0f6fce12 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
@@ -29,6 +29,7 @@ import 
com.slack.api.methods.response.conversations.ConversationsHistoryResponse
 import com.slack.api.methods.response.conversations.ConversationsListResponse;
 import com.slack.api.model.Conversation;
 import com.slack.api.model.Message;
+import com.slack.api.util.http.SlackHttpClient;
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePropertyKey;
@@ -57,7 +58,7 @@ public class SlackConsumer extends 
ScheduledBatchPollingConsumer {
     @Override
     protected void doStart() throws Exception {
         SlackConfig config = 
SlackHelper.createSlackConfig(slackEndpoint.getServerUrl());
-        CustomSlackHttpClient client = new CustomSlackHttpClient();
+        SlackHttpClient client = new SlackHttpClient();
         this.slack = Slack.getInstance(config, client);
         this.channelId = getChannelId(slackEndpoint.getChannel(), null);
         super.doStart();
diff --git 
a/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackProducer.java
 
b/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackProducer.java
index 57cd41a2746..58dd81a562b 100644
--- 
a/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackProducer.java
+++ 
b/components/camel-slack/src/main/java/org/apache/camel/component/slack/SlackProducer.java
@@ -24,6 +24,7 @@ import com.slack.api.SlackConfig;
 import com.slack.api.methods.SlackApiException;
 import com.slack.api.methods.response.chat.ChatPostMessageResponse;
 import com.slack.api.model.Message;
+import com.slack.api.util.http.SlackHttpClient;
 import com.slack.api.webhook.WebhookResponse;
 import org.apache.camel.AsyncCallback;
 import org.apache.camel.CamelExchangeException;
@@ -47,7 +48,7 @@ public class SlackProducer extends DefaultAsyncProducer {
     @Override
     protected void doStart() throws Exception {
         SlackConfig config = 
SlackHelper.createSlackConfig(slackEndpoint.getServerUrl());
-        CustomSlackHttpClient client = new CustomSlackHttpClient();
+        SlackHttpClient client = new SlackHttpClient();
         this.slack = Slack.getInstance(config, client);
         super.doStart();
     }

Reply via email to