Skip to content

Commit

Permalink
Merge pull request #127 from Orange-Co/feature/payment
Browse files Browse the repository at this point in the history
Feature/payment
  • Loading branch information
Kang1221 authored Oct 15, 2024
2 parents 051d1a6 + fc2c949 commit 3fac9a6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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;
}
}
}
11 changes: 6 additions & 5 deletions src/main/java/co/orange/ddanzi/service/PaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.util.UriComponentsBuilder;


import java.util.HashMap;
import java.util.Map;

@Slf4j
Expand Down Expand Up @@ -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<String, String> requestBody = new HashMap<>();
requestBody.put("imp_key", accessKey);
requestBody.put("imp_secret", accessSecret);

HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);

HttpEntity<PortOneTokenRequestDto> entity = new HttpEntity<>(requestBody, headers);
try {
log.info("Request Body: {}", new ObjectMapper().writeValueAsString(requestBody));
} catch (JsonProcessingException e) {
Expand Down

0 comments on commit 3fac9a6

Please sign in to comment.