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 8e9ebf56..b1090efc 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; + } + } } diff --git a/src/main/java/co/orange/ddanzi/service/PaymentService.java b/src/main/java/co/orange/ddanzi/service/PaymentService.java index bc65b290..3a05d6af 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) {