From 20c301ea578fcc54948c214db71610f8e7212a0f Mon Sep 17 00:00:00 2001 From: woozu-shin Date: Mon, 13 May 2024 19:34:36 +0900 Subject: [PATCH] [NO-ISSUE] Add header --- build.gradle | 2 +- .../datasource/H2ConsoleConfiguration.java | 1 + .../feign/FakeUserAgentInterceptor.java | 19 +++++++++++++++++++ .../FmkoreaClientFeignConfiguration.java | 2 +- .../feign/UserAgentInterceptor.java | 15 --------------- .../client/fmkorea/FmkoreaBoardClient.java | 4 +++- .../infra/client/slack/SlackAPIClient.java | 17 ----------------- 7 files changed, 25 insertions(+), 35 deletions(-) create mode 100644 shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/FakeUserAgentInterceptor.java delete mode 100644 shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/UserAgentInterceptor.java delete mode 100644 shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/infra/client/slack/SlackAPIClient.java diff --git a/build.gradle b/build.gradle index 8d5f629..29772ee 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,7 @@ subprojects { ext { set('springCloudVersion', "2020.0.4") - set("BASE_IMAGE_REGISTRY_URL", "192.168.0.10:10001") + set("BASE_IMAGE_REGISTRY_URL", "registry.myoa-universe.com") } apply from: "${project.rootDir}/jib.gradle" diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/datasource/H2ConsoleConfiguration.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/datasource/H2ConsoleConfiguration.java index 3645d3e..df83861 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/datasource/H2ConsoleConfiguration.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/datasource/H2ConsoleConfiguration.java @@ -12,6 +12,7 @@ import org.springframework.context.event.EventListener; import java.sql.SQLException; @Slf4j +@Profile("!prod") @Configuration public class H2ConsoleConfiguration { diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/FakeUserAgentInterceptor.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/FakeUserAgentInterceptor.java new file mode 100644 index 0000000..f9dbbf8 --- /dev/null +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/FakeUserAgentInterceptor.java @@ -0,0 +1,19 @@ +package com.myoa.engineering.crawl.shopping.configuration.feign; + +import feign.RequestInterceptor; +import feign.RequestTemplate; +import org.apache.http.HttpHeaders; + +public class FakeUserAgentInterceptor implements RequestInterceptor { + + private static final String USER_AGENT_VALUE = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"; + + @Override + public void apply(RequestTemplate template) { + template.header(HttpHeaders.USER_AGENT, USER_AGENT_VALUE); + template.header(HttpHeaders.ACCEPT, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8"); + template.header(HttpHeaders.ACCEPT_LANGUAGE, "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7"); + template.header(HttpHeaders.USER_AGENT, USER_AGENT_VALUE); + template.header(HttpHeaders.USER_AGENT, USER_AGENT_VALUE); + } +} diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/FmkoreaClientFeignConfiguration.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/FmkoreaClientFeignConfiguration.java index 869a448..1dbec28 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/FmkoreaClientFeignConfiguration.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/FmkoreaClientFeignConfiguration.java @@ -9,7 +9,7 @@ public class FmkoreaClientFeignConfiguration { @Bean public RequestInterceptor requestInterceptor() { - return requestTemplate -> new UserAgentInterceptor().apply(requestTemplate); + return requestTemplate -> new FakeUserAgentInterceptor().apply(requestTemplate); } } diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/UserAgentInterceptor.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/UserAgentInterceptor.java deleted file mode 100644 index 210c9ce..0000000 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/configuration/feign/UserAgentInterceptor.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.myoa.engineering.crawl.shopping.configuration.feign; - -import feign.RequestInterceptor; -import feign.RequestTemplate; - -public class UserAgentInterceptor implements RequestInterceptor { - - private static final String USER_AGENT_HEADER = "User-Agent"; - private static final String USER_AGENT_VALUE = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"; - - @Override - public void apply(RequestTemplate template) { - template.header(USER_AGENT_HEADER, USER_AGENT_VALUE); - } -} diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/infra/client/fmkorea/FmkoreaBoardClient.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/infra/client/fmkorea/FmkoreaBoardClient.java index 7c402bf..a40c4ee 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/infra/client/fmkorea/FmkoreaBoardClient.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/infra/client/fmkorea/FmkoreaBoardClient.java @@ -1,5 +1,6 @@ package com.myoa.engineering.crawl.shopping.infra.client.fmkorea; +import com.myoa.engineering.crawl.shopping.configuration.feign.FmkoreaClientFeignConfiguration; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.SpringQueryMap; import org.springframework.web.bind.annotation.GetMapping; @@ -7,7 +8,8 @@ import org.springframework.web.bind.annotation.PathVariable; import java.util.Map; -@FeignClient(value = "fmkorea-board-client", url = "https://www.fmkorea.com") +@FeignClient(value = "fmkorea-board-client", url = "https://www.fmkorea.com", +configuration = FmkoreaClientFeignConfiguration.class) public interface FmkoreaBoardClient { @GetMapping("{boardLink}") diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/infra/client/slack/SlackAPIClient.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/infra/client/slack/SlackAPIClient.java deleted file mode 100644 index 3b6e00c..0000000 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/infra/client/slack/SlackAPIClient.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.myoa.engineering.crawl.shopping.infra.client.slack; - -import com.myoa.engineering.crawl.shopping.configuration.feign.FeignDefaultConfig; -import com.myoa.engineering.crawl.shopping.dto.slack.v1.SlackMessageDTO; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; - -@FeignClient(value = "slack-api-client", url = "https://slack.com/api", - configuration = FeignDefaultConfig.class) -public interface SlackAPIClient { - - @PostMapping("/chat.postMessage") - String sendMessage(@RequestBody SlackMessageDTO message, - @RequestHeader("Authorization") String token); -}