From c4649a436bd6681908635018a632cb9a203f3e29 Mon Sep 17 00:00:00 2001 From: kang Date: Tue, 15 Oct 2024 18:56:00 +0900 Subject: [PATCH 1/2] chore: change object to map --- .../java/co/orange/ddanzi/service/PaymentService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/co/orange/ddanzi/service/PaymentService.java b/src/main/java/co/orange/ddanzi/service/PaymentService.java index bc65b29..3a05d6a 100644 --- a/src/main/java/co/orange/ddanzi/service/PaymentService.java +++ b/src/main/java/co/orange/ddanzi/service/PaymentService.java @@ -33,6 +33,7 @@ import org.springframework.web.util.UriComponentsBuilder; +import java.util.HashMap; import java.util.Map; @Slf4j @@ -172,12 +173,12 @@ public String getPortOneAccessToken(){ HttpHeaders headers = new HttpHeaders(); headers.set("Content-Type", "application/json"); - PortOneTokenRequestDto requestBody = PortOneTokenRequestDto.builder() - .imp_key(accessKey) - .imp_secret(accessSecret) - .build(); + Map requestBody = new HashMap<>(); + requestBody.put("imp_key", accessKey); + requestBody.put("imp_secret", accessSecret); + + HttpEntity> entity = new HttpEntity<>(requestBody, headers); - HttpEntity entity = new HttpEntity<>(requestBody, headers); try { log.info("Request Body: {}", new ObjectMapper().writeValueAsString(requestBody)); } catch (JsonProcessingException e) { From fc2c9495b67b88ca5e2f8358223caefbbf19f28d Mon Sep 17 00:00:00 2001 From: kang Date: Tue, 15 Oct 2024 18:56:09 +0900 Subject: [PATCH 2/2] feat: add loggerx --- .../restTemplete/RestTempleteConfig.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/co/orange/ddanzi/global/restTemplete/RestTempleteConfig.java b/src/main/java/co/orange/ddanzi/global/restTemplete/RestTempleteConfig.java index 8e9ebf5..b1090ef 100644 --- a/src/main/java/co/orange/ddanzi/global/restTemplete/RestTempleteConfig.java +++ b/src/main/java/co/orange/ddanzi/global/restTemplete/RestTempleteConfig.java @@ -1,11 +1,20 @@ package co.orange.ddanzi.global.restTemplete; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.RestTemplate; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + @Configuration public class RestTempleteConfig { @@ -21,4 +30,35 @@ public RestTemplate restTemplate(RestTemplateBuilder builder) { .rootUri(hostUrl+":"+port) .build(); } + + public class LoggingInterceptor implements ClientHttpRequestInterceptor { + private static final Logger log = LoggerFactory.getLogger(LoggingInterceptor.class); + + @Override + public ClientHttpResponse intercept( + org.springframework.http.HttpRequest request, + byte[] body, + org.springframework.http.client.ClientHttpRequestExecution execution) throws IOException { + + log.info("Request URI: {}", request.getURI()); + log.info("Request Method: {}", request.getMethod()); + log.info("Request Headers: {}", request.getHeaders()); + log.info("Request Body: {}", new String(body, StandardCharsets.UTF_8)); + + ClientHttpResponse response = execution.execute(request, body); + + BufferedReader reader = new BufferedReader(new InputStreamReader(response.getBody(), StandardCharsets.UTF_8)); + StringBuilder responseBody = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + responseBody.append(line); + } + + log.info("Response Status Code: {}", response.getStatusCode()); + log.info("Response Headers: {}", response.getHeaders()); + log.info("Response Body: {}", responseBody.toString()); + + return response; + } + } }