feat: ACIKey 토큰 발급 테스트 배치 추가 (TASK_BATCH_ACIKEY)

- acikey 패키지 신규 생성
- AciKeyTokenJobConfig.java: Job/Step 설정
- AciKeyTokenTasklet.java: API 호출 및 토큰 확인 로직
- application-dev.yaml: acikey 설정값 추가 (url/userid/apikey)
This commit is contained in:
이주일
2026-05-23 03:33:28 +09:00
parent 7a3484cdcf
commit d7cc157171
3 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
package com.wb.domainserver.acikey;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
// ACIKey 토큰 발급 테스트 배치 - API 호출 및 토큰 확인 로직
@Slf4j
@Component
public class AciKeyTokenTasklet implements Tasklet {
@Value("${acikey.url}")
private String aciKeyUrl;
@Value("${acikey.userid}")
private String userId;
@Value("${acikey.apikey}")
private String apiKey;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
log.info("[AciKeyBatch] 배치 시작");
log.info("[AciKeyBatch] API URL: {}", aciKeyUrl);
try {
// Header 설정
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("USERID", userId);
headers.set("APIKEY", apiKey);
HttpEntity<String> requestEntity = new HttpEntity<>("{}", headers);
// API 호출
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Map> response = restTemplate.exchange(
aciKeyUrl,
HttpMethod.POST,
requestEntity,
Map.class
);
Map<String, Object> body = response.getBody();
log.info("[AciKeyBatch] 응답 전체: {}", body);
String status = (String) body.get("Status");
String aciKey = (String) body.get("ACIKey");
String errMsg = (String) body.get("ErrMsg");
if ("A10".equals(status)) {
log.info("[AciKeyBatch] ✅ 토큰 발급 성공!");
log.info("[AciKeyBatch] ACIKey: {}", aciKey);
contribution.incrementWriteCount(1);
} else {
log.error("[AciKeyBatch] ❌ 토큰 발급 실패. Status: {}, ErrMsg: {}", status, errMsg);
throw new RuntimeException("ACIKey 토큰 발급 실패. Status: " + status + ", ErrMsg: " + errMsg);
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
log.error("[AciKeyBatch] ❌ API 호출 중 오류 발생: {}", e.getMessage(), e);
throw new RuntimeException("AciKey API 호출 오류", e);
}
log.info("[AciKeyBatch] 배치 종료");
return RepeatStatus.FINISHED;
}
}