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) {