Skip to content

Commit

Permalink
Fix: 내부 통신 시 SingleResult 로 결과 받을수 있게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
gytjd committed Nov 18, 2024
1 parent f60d75e commit 537d391
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions src/main/java/AIWA/McpBackend/service/aws/AwsResourceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<MemberCredentialDTO> response = restTemplate.getForEntity(url, MemberCredentialDTO.class);
System.out.println("Response: " + response.getBody());
// SingleResult<MemberCredentialDTO>로 응답을 받기 위한 요청
ResponseEntity<SingleResult<MemberCredentialDTO>> response =
restTemplate.exchange(
url,
HttpMethod.GET,
null,
new ParameterizedTypeReference<SingleResult<MemberCredentialDTO>>() {}
);

// 응답 상태 코드 및 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<Ec2InstanceDTO> fetchEc2Instances(String userId) {
Expand Down

0 comments on commit 537d391

Please sign in to comment.