Compare commits
No commits in common. "15deda383abfdcab6cbe8147d08f5ebc2e96c47a" and "709425a4848d129cfc52452d9936ea859d55cb20" have entirely different histories.
15deda383a
...
709425a484
@ -4,11 +4,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|||||||
import com.interplug.qcast.biz.displayItem.DisplayItemService;
|
import com.interplug.qcast.biz.displayItem.DisplayItemService;
|
||||||
import com.interplug.qcast.biz.displayItem.dto.ItemSyncResponse;
|
import com.interplug.qcast.biz.displayItem.dto.ItemSyncResponse;
|
||||||
import com.interplug.qcast.util.InterfaceQsp;
|
import com.interplug.qcast.util.InterfaceQsp;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import org.springframework.batch.core.Job;
|
import org.springframework.batch.core.Job;
|
||||||
import org.springframework.batch.core.JobExecutionListener;
|
import org.springframework.batch.core.JobExecutionListener;
|
||||||
import org.springframework.batch.core.Step;
|
import org.springframework.batch.core.Step;
|
||||||
@ -37,9 +34,6 @@ public class MaterialConfiguration implements JobExecutionListener {
|
|||||||
@Value("${qsp.master-material-batch-url}")
|
@Value("${qsp.master-material-batch-url}")
|
||||||
private String qspInterfaceUrl;
|
private String qspInterfaceUrl;
|
||||||
|
|
||||||
@Value("${qsp.master-material-batch-page-size:1000}")
|
|
||||||
private int pageSize;
|
|
||||||
|
|
||||||
public MaterialConfiguration(DisplayItemService displayItemService, InterfaceQsp interfaceQsp) {
|
public MaterialConfiguration(DisplayItemService displayItemService, InterfaceQsp interfaceQsp) {
|
||||||
this.displayItemService = displayItemService;
|
this.displayItemService = displayItemService;
|
||||||
this.interfaceQsp = interfaceQsp;
|
this.interfaceQsp = interfaceQsp;
|
||||||
@ -64,32 +58,12 @@ public class MaterialConfiguration implements JobExecutionListener {
|
|||||||
@Bean
|
@Bean
|
||||||
@StepScope
|
@StepScope
|
||||||
public ListItemReader<ItemSyncResponse> materialReader() throws Exception {
|
public ListItemReader<ItemSyncResponse> materialReader() throws Exception {
|
||||||
List<ItemSyncResponse> aggregated = new ArrayList<>();
|
this.itemSyncList =
|
||||||
int page = 1;
|
interfaceQsp.callApiData(
|
||||||
while (true) {
|
HttpMethod.GET,
|
||||||
Map<String, Object> params = new HashMap<>();
|
qspInterfaceUrl + "?allYn=N",
|
||||||
params.put("allYn", "N");
|
null,
|
||||||
params.put("page", page);
|
new TypeReference<List<ItemSyncResponse>>() {});
|
||||||
params.put("size", pageSize);
|
|
||||||
|
|
||||||
List<ItemSyncResponse> pageItems =
|
|
||||||
interfaceQsp.callApiData(
|
|
||||||
HttpMethod.GET,
|
|
||||||
qspInterfaceUrl,
|
|
||||||
params,
|
|
||||||
new TypeReference<List<ItemSyncResponse>>() {});
|
|
||||||
|
|
||||||
if (pageItems == null || pageItems.isEmpty()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
aggregated.addAll(pageItems);
|
|
||||||
if (pageItems.size() < pageSize) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
page++;
|
|
||||||
}
|
|
||||||
this.itemSyncList = aggregated;
|
|
||||||
return (itemSyncList != null)
|
return (itemSyncList != null)
|
||||||
? new ListItemReader<>(itemSyncList)
|
? new ListItemReader<>(itemSyncList)
|
||||||
: new ListItemReader<>(Collections.emptyList());
|
: new ListItemReader<>(Collections.emptyList());
|
||||||
|
|||||||
@ -37,41 +37,34 @@ public class InterfaceQsp {
|
|||||||
* @return String
|
* @return String
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public String callApi(HttpMethod httpMethod, String apiPath, Object requestObject)
|
public String callApi(HttpMethod httpMethod, String apiPath, Object requestObject)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
URL url = null;
|
URL url = null;
|
||||||
HttpURLConnection con = null;
|
HttpURLConnection con = null;
|
||||||
OutputStreamWriter osw = null;
|
OutputStreamWriter osw = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
StringBuilder sb = null;
|
StringBuilder sb = null;
|
||||||
long startAt = System.currentTimeMillis();
|
|
||||||
String requestType = requestObject == null ? "none" : requestObject.getClass().getSimpleName();
|
try {
|
||||||
|
|
||||||
try {
|
// GET 요청 시 requestObject를 쿼리 스트링으로 변환
|
||||||
|
if (HttpMethod.GET.equals(httpMethod) && requestObject != null) {
|
||||||
// GET 요청 시 requestObject를 쿼리 스트링으로 변환
|
|
||||||
if (HttpMethod.GET.equals(httpMethod) && requestObject != null) {
|
|
||||||
ObjectMapper om = new ObjectMapper();
|
ObjectMapper om = new ObjectMapper();
|
||||||
Map<String, Object> params = om.convertValue(requestObject, Map.class); // Object -> Map 변환
|
Map<String, Object> params = om.convertValue(requestObject, Map.class); // Object -> Map 변환
|
||||||
String queryString =
|
String queryString =
|
||||||
params.entrySet().stream()
|
params.entrySet().stream()
|
||||||
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||||
.reduce((p1, p2) -> p1 + "&" + p2)
|
.reduce((p1, p2) -> p1 + "&" + p2)
|
||||||
.orElse("");
|
.orElse("");
|
||||||
apiPath += "?" + queryString; // 쿼리 스트링 추가
|
apiPath += "?" + queryString; // 쿼리 스트링 추가
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug(
|
url = new URL(apiPath);
|
||||||
"QSP API call start: method={}, url={}, requestType={}",
|
con = (HttpURLConnection) url.openConnection();
|
||||||
httpMethod,
|
con.setConnectTimeout(120000); // 서버에 연결되는 Timeout 시간 설정
|
||||||
apiPath,
|
con.setReadTimeout(120000); // InputStream 읽어 오는 Timeout 시간 설정
|
||||||
requestType);
|
con.setRequestMethod(httpMethod.toString());
|
||||||
url = new URL(apiPath);
|
|
||||||
con = (HttpURLConnection) url.openConnection();
|
|
||||||
con.setConnectTimeout(120000); // 서버에 연결되는 Timeout 시간 설정
|
|
||||||
con.setReadTimeout(120000); // InputStream 읽어 오는 Timeout 시간 설정
|
|
||||||
con.setRequestMethod(httpMethod.toString());
|
|
||||||
con.setRequestProperty("Content-Type", "application/json");
|
con.setRequestProperty("Content-Type", "application/json");
|
||||||
con.setRequestProperty("Referer", frontUrl);
|
con.setRequestProperty("Referer", frontUrl);
|
||||||
con.setDoInput(true);
|
con.setDoInput(true);
|
||||||
@ -91,33 +84,20 @@ public class InterfaceQsp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sb = new StringBuilder();
|
sb = new StringBuilder();
|
||||||
int status = con.getResponseCode();
|
if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
if (status == HttpURLConnection.HTTP_OK) {
|
br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
|
||||||
br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
|
|
||||||
|
String line;
|
||||||
String line;
|
while ((line = br.readLine()) != null) {
|
||||||
while ((line = br.readLine()) != null) {
|
sb.append(line);
|
||||||
sb.append(line);
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
log.debug(
|
throw e;
|
||||||
"QSP API call end: method={}, url={}, status={}, durationMs={}",
|
} finally {
|
||||||
httpMethod,
|
try {
|
||||||
apiPath,
|
if (osw != null) osw.close();
|
||||||
status,
|
if (br != null) br.close();
|
||||||
System.currentTimeMillis() - startAt);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(
|
|
||||||
"QSP API call failed: method={}, url={}, durationMs={}",
|
|
||||||
httpMethod,
|
|
||||||
apiPath,
|
|
||||||
System.currentTimeMillis() - startAt,
|
|
||||||
e);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (osw != null) osw.close();
|
|
||||||
if (br != null) br.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@ -176,30 +156,23 @@ public class InterfaceQsp {
|
|||||||
* @return String
|
* @return String
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public byte[] callApi(
|
public byte[] callApi(
|
||||||
HttpMethod httpMethod, String apiPath, Object requestObject, Map<String, String> result)
|
HttpMethod httpMethod, String apiPath, Object requestObject, Map<String, String> result)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
URL url = null;
|
URL url = null;
|
||||||
HttpURLConnection con = null;
|
HttpURLConnection con = null;
|
||||||
OutputStreamWriter osw = null;
|
OutputStreamWriter osw = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
|
|
||||||
byte[] bt = null;
|
byte[] bt = null;
|
||||||
long startAt = System.currentTimeMillis();
|
|
||||||
String requestType = requestObject == null ? "none" : requestObject.getClass().getSimpleName();
|
try {
|
||||||
|
url = new URL(apiPath);
|
||||||
try {
|
con = (HttpURLConnection) url.openConnection();
|
||||||
log.debug(
|
con.setConnectTimeout(30000); // 서버에 연결되는 Timeout 시간 설정
|
||||||
"QSP API call start: method={}, url={}, requestType={}",
|
con.setReadTimeout(30000); // InputStream 읽어 오는 Timeout 시간 설정
|
||||||
httpMethod,
|
con.setRequestMethod(httpMethod.toString());
|
||||||
apiPath,
|
|
||||||
requestType);
|
|
||||||
url = new URL(apiPath);
|
|
||||||
con = (HttpURLConnection) url.openConnection();
|
|
||||||
con.setConnectTimeout(30000); // 서버에 연결되는 Timeout 시간 설정
|
|
||||||
con.setReadTimeout(30000); // InputStream 읽어 오는 Timeout 시간 설정
|
|
||||||
con.setRequestMethod(httpMethod.toString());
|
|
||||||
con.setRequestProperty("Content-Type", "application/json");
|
con.setRequestProperty("Content-Type", "application/json");
|
||||||
con.setRequestProperty("Referer", frontUrl);
|
con.setRequestProperty("Referer", frontUrl);
|
||||||
con.setDoInput(true);
|
con.setDoInput(true);
|
||||||
@ -217,40 +190,27 @@ public class InterfaceQsp {
|
|||||||
osw.flush();
|
osw.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int status = con.getResponseCode();
|
if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
||||||
if (status == HttpURLConnection.HTTP_OK) {
|
// response 헤더 값 결과 셋팅
|
||||||
// response 헤더 값 결과 셋팅
|
result.put("type", con.getHeaderField("Content-Type"));
|
||||||
result.put("type", con.getHeaderField("Content-Type"));
|
result.put("disposition", con.getHeaderField("Content-Disposition"));
|
||||||
result.put("disposition", con.getHeaderField("Content-Disposition"));
|
|
||||||
|
InputStream inputStream = con.getInputStream();
|
||||||
InputStream inputStream = con.getInputStream();
|
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||||
outputStream.write(buffer, 0, bytesRead);
|
outputStream.write(buffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
bt = outputStream.toByteArray(); // 파일 데이터 반환
|
bt = outputStream.toByteArray(); // 파일 데이터 반환
|
||||||
}
|
}
|
||||||
log.debug(
|
} catch (Exception e) {
|
||||||
"QSP API call end: method={}, url={}, status={}, durationMs={}",
|
throw e;
|
||||||
httpMethod,
|
} finally {
|
||||||
apiPath,
|
try {
|
||||||
status,
|
if (osw != null) osw.close();
|
||||||
System.currentTimeMillis() - startAt);
|
if (br != null) br.close();
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(
|
|
||||||
"QSP API call failed: method={}, url={}, durationMs={}",
|
|
||||||
httpMethod,
|
|
||||||
apiPath,
|
|
||||||
System.currentTimeMillis() - startAt,
|
|
||||||
e);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (osw != null) osw.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