From 537d3915200fb8e7e2702fdb89064350b2144420 Mon Sep 17 00:00:00 2001 From: gytjd Date: Mon, 18 Nov 2024 14:52:41 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EB=82=B4=EB=B6=80=20=ED=86=B5=EC=8B=A0?= =?UTF-8?q?=20=EC=8B=9C=20SingleResult=20=EB=A1=9C=20=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?=EB=B0=9B=EC=9D=84=EC=88=98=20=EC=9E=88=EA=B2=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/aws/AwsResourceService.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/main/java/AIWA/McpBackend/service/aws/AwsResourceService.java b/src/main/java/AIWA/McpBackend/service/aws/AwsResourceService.java index 9bf3976..a6eec91 100644 --- a/src/main/java/AIWA/McpBackend/service/aws/AwsResourceService.java +++ b/src/main/java/AIWA/McpBackend/service/aws/AwsResourceService.java @@ -18,9 +18,6 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestTemplate; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; @@ -63,40 +60,39 @@ public void initializeClient(String email) { private MemberCredentialDTO getMemberCredentials(String email) { // Base URL 설정 - String baseUrl = "http://member-svc/member/api/members/email"; - String url = baseUrl + "?email=" + email; - System.out.println("Requesting URL: " + url); + String url = "http://member-svc/member/api/members/email?email=" + email; try { - // REST API 호출 - ResponseEntity response = restTemplate.getForEntity(url, MemberCredentialDTO.class); - System.out.println("Response: " + response.getBody()); + // SingleResult로 응답을 받기 위한 요청 + ResponseEntity> response = + restTemplate.exchange( + url, + HttpMethod.GET, + null, + new ParameterizedTypeReference>() {} + ); + + // 응답 상태 코드 및 SingleResult 성공 여부 확인 + if (response.getStatusCode().is2xxSuccessful() && + response.getBody() != null && + response.getBody().isSuccess()) { - // 응답 상태 확인 및 데이터 반환 - if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) { - return response.getBody(); // 성공 시 응답 반환 + // 성공적으로 데이터를 가져온 경우 반환 + return response.getBody().getData(); } else { - System.err.println("Failed to retrieve data. HTTP Status: " + response.getStatusCode()); - return null; // 실패 시 null 반환 + // 실패 시 로그 출력 및 null 반환 + System.err.println("Failed to retrieve MemberCredentialDTO. Response: " + response); + return null; } - } catch (HttpClientErrorException e) { - // HTTP 클라이언트 오류 처리 (예: 4xx) - System.err.println("Client error: " + e.getStatusCode() + " - " + e.getResponseBodyAsString()); - } catch (HttpServerErrorException e) { - // HTTP 서버 오류 처리 (예: 5xx) - System.err.println("Server error: " + e.getStatusCode() + " - " + e.getResponseBodyAsString()); - } catch (ResourceAccessException e) { - // 네트워크 오류 처리 - System.err.println("Network error: " + e.getMessage()); } catch (Exception e) { - // 기타 예외 처리 - System.err.println("Unexpected error: " + e.getMessage()); + // 오류 발생 시 로그 출력 및 null 반환 + System.err.println("Exception while calling getMemberCredentials: " + e.getMessage()); e.printStackTrace(); + return null; } - - return null; // 오류 발생 시 null 반환 } + // EC2 Instances 가져오기 public List fetchEc2Instances(String userId) {