interfasce 추가
This commit is contained in:
parent
686f7e978c
commit
e3b78204c2
@ -100,7 +100,6 @@ public class JobLauncherController {
|
|||||||
*/
|
*/
|
||||||
// @Scheduled(cron = "*/30 * * * * *")
|
// @Scheduled(cron = "*/30 * * * * *")
|
||||||
@Scheduled(cron = "0 0 0 * * *")
|
@Scheduled(cron = "0 0 0 * * *")
|
||||||
@GetMapping("/batch/master/storeAdditionalInfo")
|
|
||||||
public String storeAdditionalInfoJob()
|
public String storeAdditionalInfoJob()
|
||||||
throws JobInstanceAlreadyCompleteException,
|
throws JobInstanceAlreadyCompleteException,
|
||||||
JobExecutionAlreadyRunningException,
|
JobExecutionAlreadyRunningException,
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
package com.interplug.qcast.util;
|
package com.interplug.qcast.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.interplug.qcast.biz.user.dto.SyncResponse;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -8,16 +12,20 @@ import java.io.OutputStreamWriter;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class InterfaceQsp {
|
public class InterfaceQsp {
|
||||||
|
|
||||||
|
@Value("${qsp.url}")
|
||||||
|
private String qspUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API Call
|
* API Call
|
||||||
*
|
*
|
||||||
@ -71,10 +79,8 @@ public class InterfaceQsp {
|
|||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (osw != null)
|
if (osw != null) osw.close();
|
||||||
osw.close();
|
if (br != null) br.close();
|
||||||
if (br != null)
|
|
||||||
br.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@ -83,6 +89,48 @@ public class InterfaceQsp {
|
|||||||
return sb != null ? sb.toString() : null;
|
return sb != null ? sb.toString() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API 호출후 Response 객체로 Return
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
* @param qspInterUrl
|
||||||
|
* @param requestObject
|
||||||
|
* @param responseObject
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public <T> T callApiData(
|
||||||
|
HttpMethod method, String qspInterUrl, Object requestObject, Object responseObject)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
|
// 데이터 읽기
|
||||||
|
SyncResponse syncResponse = new SyncResponse();
|
||||||
|
|
||||||
|
String strResponse = this.callApi(method, qspUrl + qspInterUrl, requestObject);
|
||||||
|
ObjectMapper om =
|
||||||
|
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
|
||||||
|
String dataJson = "";
|
||||||
|
if (!"".equals(strResponse)) {
|
||||||
|
|
||||||
|
syncResponse = om.readValue(strResponse, SyncResponse.class);
|
||||||
|
|
||||||
|
// 'data' 필드를 직접 사용하여 BatchResponse로 변환
|
||||||
|
if (syncResponse.getData() != null) {
|
||||||
|
dataJson = om.writeValueAsString(syncResponse.getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (responseObject == null) {
|
||||||
|
return (T) dataJson;
|
||||||
|
} else if (responseObject instanceof Class<?>) {
|
||||||
|
return om.readValue(dataJson, (Class<T>) responseObject);
|
||||||
|
} else if (responseObject instanceof TypeReference<?>) {
|
||||||
|
return om.readValue(dataJson, (TypeReference<T>) responseObject);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unsupported responseType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API Call - byte return, file down 사용
|
* API Call - byte return, file down 사용
|
||||||
*
|
*
|
||||||
@ -91,8 +139,9 @@ public class InterfaceQsp {
|
|||||||
* @return String
|
* @return String
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public byte[] callApi(HttpMethod httpMethod, String apiPath, Object requestObject,
|
public byte[] callApi(
|
||||||
Map<String, String> result) throws Exception {
|
HttpMethod httpMethod, String apiPath, Object requestObject, Map<String, String> result)
|
||||||
|
throws Exception {
|
||||||
|
|
||||||
URL url = null;
|
URL url = null;
|
||||||
HttpURLConnection con = null;
|
HttpURLConnection con = null;
|
||||||
@ -142,10 +191,8 @@ public class InterfaceQsp {
|
|||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (osw != null)
|
if (osw != null) osw.close();
|
||||||
osw.close();
|
if (br != null) br.close();
|
||||||
if (br != null)
|
|
||||||
br.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user