로깅 개선 및 EAI 배치 가상 연동 작업 완료
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package com.eactive.ext.kjb.eai;
|
||||
|
||||
import com.eactive.ext.kjb.common.KjbProperty;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
public class KjbEaiBatchModule {
|
||||
private final KjbProperty property;
|
||||
private final CloseableHttpClient httpClient;
|
||||
|
||||
|
||||
public KjbEaiBatchModule(@NotNull KjbProperty property) {
|
||||
if (property == null) {
|
||||
throw new IllegalArgumentException("KjbProperty cannot be null");
|
||||
}
|
||||
|
||||
this.property = property;
|
||||
|
||||
if (StringUtils.isNotEmpty(property.getEaiBatchUrl())) {
|
||||
this.httpClient = HttpClients.createDefault();
|
||||
} else {
|
||||
this.httpClient = null;
|
||||
log.warn("EAI_BATCH_URL 가 설정되지 않음. 실제 EAI 배치 연동 없이 동작함");
|
||||
}
|
||||
}
|
||||
|
||||
public EaiBatchMessage call(String interfaceId, String filename) throws IOException {
|
||||
EaiBatchMessage reqMessage = EaiBatchMessage.createRequest(interfaceId, filename);
|
||||
log.debug("EAI 배치 호출: {}", reqMessage);
|
||||
|
||||
if (this.httpClient != null) {
|
||||
String url = property.getEaiBatchUrl() + "?eaibatMsg=" + reqMessage.toString();
|
||||
final HttpGet httpGet = new HttpGet(url);
|
||||
|
||||
String message = httpClient.execute(httpGet, response -> EntityUtils.toString(response.getEntity(), "EUC-KR"));
|
||||
|
||||
EaiBatchMessage resMessage = EaiBatchMessage.fromResponse(message);
|
||||
log.debug("EAI 배치 응답: {}", resMessage);
|
||||
return resMessage;
|
||||
} else {
|
||||
log.info("EAI_BATCH_URL 이 설정되지 않아 실제 호출하지 않음. 요청 메시지: {}", reqMessage);
|
||||
|
||||
// 정상응답 리턴
|
||||
EaiBatchMessage resMessage = EaiBatchMessage.fromResponse(String.format("%-20s%-8s%-10s%-1s%s@@", interfaceId, "", "0000000000", "1", "S:" + filename));
|
||||
log.debug("EAI 배치 응답(모의): {}", resMessage);
|
||||
return resMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user