From 7ca7f087ab99260099bf4ca488af5fd555479c44 Mon Sep 17 00:00:00 2001 From: SeungwanJo Date: Mon, 14 Feb 2022 02:45:53 +0900 Subject: [PATCH] [Add] refine slack url (#2739) --- .../slack/SlackWebhookEventPublisher.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/slack/SlackWebhookEventPublisher.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/slack/SlackWebhookEventPublisher.java index 59daeca4df7..fbc70a7f910 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/slack/SlackWebhookEventPublisher.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/slack/SlackWebhookEventPublisher.java @@ -1,7 +1,10 @@ package org.openmetadata.catalog.slack; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.ws.rs.client.Client; @@ -35,7 +38,7 @@ public class SlackWebhookEventPublisher extends AbstractEventPublisher { clientBuilder.readTimeout(12, TimeUnit.SECONDS); client = clientBuilder.build(); target = client.target(slackWebhookURL).request(); - openMetadataUrl = config.getOpenMetadataUrl(); + openMetadataUrl = refineUri(config.getOpenMetadataUrl()); } @Override @@ -247,4 +250,20 @@ public class SlackWebhookEventPublisher extends AbstractEventPublisher { event.getEntityFullyQualifiedName(), event.getEntityFullyQualifiedName()); } + + private String refineUri(String url) { + URI urlInstance = null; + try { + urlInstance = new URI(url); + } catch (URISyntaxException e) { + LOG.error("Slack URL is not in url format - {}", url); + } + + if (Objects.nonNull(urlInstance)) { + String scheme = urlInstance.getScheme(); + String host = urlInstance.getHost(); + return String.format("%s://%s", scheme, host); + } + return url; + } }