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:
@@ -0,0 +1,35 @@
|
|||||||
|
package com.wb.domainserver.acikey;
|
||||||
|
|
||||||
|
import org.springframework.batch.core.Job;
|
||||||
|
import org.springframework.batch.core.Step;
|
||||||
|
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||||
|
import org.springframework.batch.core.repository.JobRepository;
|
||||||
|
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
// ACIKey 토큰 발급 테스트 배치 - Job/Step 설정
|
||||||
|
@Configuration
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AciKeyTokenJobConfig {
|
||||||
|
|
||||||
|
private final JobRepository jobRepository;
|
||||||
|
private final PlatformTransactionManager transactionManager;
|
||||||
|
private final AciKeyTokenTasklet aciKeyTokenTasklet;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Job aciKeyTokenJob() {
|
||||||
|
return new JobBuilder("aciKeyTokenJob", jobRepository)
|
||||||
|
.start(aciKeyTokenStep())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Step aciKeyTokenStep() {
|
||||||
|
return new StepBuilder("aciKeyTokenStep", jobRepository)
|
||||||
|
.tasklet(aciKeyTokenTasklet, transactionManager)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,3 +30,8 @@ secret:
|
|||||||
mail:
|
mail:
|
||||||
host: 10.2.1.76
|
host: 10.2.1.76
|
||||||
port: 25
|
port: 25
|
||||||
|
|
||||||
|
acikey:
|
||||||
|
url: https://acieshop.com/api/kr/token/
|
||||||
|
userid: UNIHAN
|
||||||
|
apikey: DC94F29AFD5399F54AAE7FAA46045B65
|
||||||
|
|||||||
Reference in New Issue
Block a user