Update feign client

This commit is contained in:
woozu-shin 2024-05-13 00:13:49 +09:00
parent 365b15e553
commit 53d7ba0bea
7 changed files with 45 additions and 12 deletions

View File

@ -12,7 +12,6 @@ import org.springframework.context.event.EventListener;
import java.sql.SQLException;
@Slf4j
@Profile({"datasource-local", "datasource-development"})
@Configuration
public class H2ConsoleConfiguration {

View File

@ -1,8 +1,7 @@
package com.myoa.engineering.crawl.shopping.configuration;
package com.myoa.engineering.crawl.shopping.configuration.feign;
import feign.Logger;
import feign.RequestInterceptor;
import feign.codec.ErrorDecoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@ -0,0 +1,15 @@
package com.myoa.engineering.crawl.shopping.configuration.feign;
import feign.RequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FmkoreaClientFeignConfiguration {
@Bean
public RequestInterceptor requestInterceptor() {
return requestTemplate -> new UserAgentInterceptor().apply(requestTemplate);
}
}

View File

@ -0,0 +1,15 @@
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);
}
}

View File

@ -1,30 +1,35 @@
package com.myoa.engineering.crawl.shopping.controller;
import com.myoa.engineering.crawl.shopping.crawlhandler.PpomppuCrawlDomesticHandler;
import com.myoa.engineering.crawl.shopping.crawlhandler.CrawlHandler;
import com.myoa.engineering.crawl.shopping.support.dto.constant.CrawlTarget;
import com.slack.api.methods.MethodsClient;
import com.slack.api.methods.SlackApiException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("/api/v1/exploit")
public class TestAPIController {
private final PpomppuCrawlDomesticHandler ppomppuCrawlDomesticHandler;
private final MethodsClient methodsClient;
private final List<CrawlHandler> crawlHandlers;
public TestAPIController(PpomppuCrawlDomesticHandler ppomppuCrawlDomesticHandler,
MethodsClient methodsClient) {
this.ppomppuCrawlDomesticHandler = ppomppuCrawlDomesticHandler;
public TestAPIController(MethodsClient methodsClient, List<CrawlHandler> crawlHandlers) {
this.methodsClient = methodsClient;
this.crawlHandlers = crawlHandlers;
}
@GetMapping("/triggers")
public void triggerExploit() {
ppomppuCrawlDomesticHandler.handle();
public void triggerExploit(@RequestParam("crawlTarget") CrawlTarget crawlTarget) {
crawlHandlers
.stream().filter(e -> e.getCrawlTarget().equals(crawlTarget))
.forEach(CrawlHandler::handle);
}
@GetMapping("/test-message")

View File

@ -1,6 +1,6 @@
package com.myoa.engineering.crawl.shopping.infra.client.slack;
import com.myoa.engineering.crawl.shopping.configuration.FeignDefaultConfig;
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;

View File

@ -21,7 +21,7 @@ public class ParseEventEmitter {
@Scheduled(cron = "0 0/5 * * * ?")
public void emit() {
log.info("[emitDomesticBoard] trigger fired!");
log.info("[emit] trigger fired!");
crawlHandlers.forEach(CrawlHandler::handle);
}