HTTP DELETE 처리
private Map<String, Object> delete(String _id, IF_Token _if_Token) throws Exception {
Map<String, Object> returnMapinsert = new HashMap<>();
try {
HttpURLConnection httpURLConnection = null;
try {
//connection
URL url = new URL(config.get base URL().concat(Const_Url.toString().concat(_id)));
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setInstanceFollowRedirects(false);
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestMethod("DELETE");
// header information
CommonUtil.setheader(httpURLConnection, _if_Token, domainService.getDomainName(), domainService.getUserID());
httpURLConnection.connect();
int httpStatusCode = -1;
try {
returnMapinsert = do_delete_id(httpURLConnection);
} catch (Exception e) {
try {
httpStatusCode = httpURLConnection.getResponseCode();
} catch (Exception e2) {
httpStatusCode = -1;
}
returnMapinsert = do_Err(e, httpURLConnection, httpStatusCode);
} finally {
httpURLConnection.disconnect();
}
} catch (Exception e) {
LOG.error(e.getMessage());
} finally {
httpURLConnection.disconnect();
}
} catch (Exception e) {
LOG.error(e.getMessage());
}
return returnMapinsert;
}
private Map<String, Object> do_delete_id(HttpURLConnection httpURLConnection) throws Exception {
return CommonUtil.setResponseString(httpURLConnection, "");
}
private Map<String, Object> do_Err(Exception e, HttpURLConnection httpURLConnection, int httpStatusCode) throws Exception {
return CommonUtil.errMap(e, httpURLConnection, httpStatusCode);
}
◇ delete 메서드:
・ _id: 삭제할 리소스를 식별하는 ID입니다.
・ _if_Token: 인증 토큰 객체입니다.
・ returnMapinsert: 삭제 작업 결과를 저장할 맵 객체입니다.
・ 메서드는 Exception을 던질 수 있습니다.
메서드 내부에서는 다음과 같은 작업들을 수행합니다:
・ try-catch 블록 내부에서 HTTP 연결 설정 및 DELETE 요청을 합니다.
・ 헤더 정보를 설정합니다.
・ DELETE 요청을 서버에 전송합니다.
・ 응답 코드를 확인하고 적절한 처리를 합니다.
◇ do_delete_id 메서드: httpURLConnection:
・ DELETE 요청을 보낸 HttpURLConnection 객체입니다.
이 메서드는 CommonUtil.setResponseString 메서드를 호출하여 HTTP 응답을 처리하고 결과를 반환합니다.
◇ do_Err 메서드: e:
・ 예외 객체입니다.
・ httpURLConnection: DELETE 요청을 보낸 HttpURLConnection 객체입니다.
・ httpStatusCode: HTTP 응답 코드입니다.
이 메서드는 CommonUtil.errMap 메서드를 호출하여 예외와 응답 상태를 처리하고 결과를 반환합니다.