diff --git a/src/main/java/com/eactive/eai/adapter/controller/ApiAdapterController.java b/src/main/java/com/eactive/eai/adapter/controller/ApiAdapterController.java index b4bba6e..1c66bf1 100644 --- a/src/main/java/com/eactive/eai/adapter/controller/ApiAdapterController.java +++ b/src/main/java/com/eactive/eai/adapter/controller/ApiAdapterController.java @@ -27,6 +27,8 @@ import com.eactive.eai.adapter.service.ApiAdapterService; import com.eactive.eai.common.TransactionContextKeys; import com.eactive.eai.common.exception.ExceptionUtil; import com.eactive.eai.common.server.EAIServerManager; +import com.eactive.eai.common.stdmessage.STDMessageDAO; +import com.eactive.eai.common.util.ApplicationContextProvider; import com.eactive.eai.common.util.DatetimeUtil; import com.eactive.eai.common.util.InboundErrorLogger; import com.eactive.eai.common.util.Logger; @@ -42,6 +44,7 @@ import org.json.simple.JSONObject; import java.util.HashMap; import java.util.Map; import java.sql.Timestamp; +import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageInfo; @RestController public class ApiAdapterController implements HttpAdapterServiceKey { @@ -62,16 +65,12 @@ public class ApiAdapterController implements HttpAdapterServiceKey { // /api/v1/public/getUserInfo.svc apiUri = StringUtils.removeStart(apiUri, servletRequest.getContextPath()); apiUri = StringUtils.removeEnd(apiUri, "/"); + HttpDynamicInAdapterUri adptUri = findAdptUri(apiUri, HttpDynamicInAdapterManager.getInstance()); //Received time , jwhong long receivedTimeMillis = System.currentTimeMillis(); String receivedTimeStr = String.valueOf(receivedTimeMillis); - - System.out.println("현재 시간 밀리초(long): " + receivedTimeMillis); - System.out.println("현재 시간 밀리초(String): " + receivedTimeStr); - //Timestamp timestamp = new Timestamp(System.currentTimeMillis()); - //System.out.println("현재 Timestamp: " + timestamp); if (logger.isDebug()) { logger.debug("ApiAdapterController] service request uri : " + servletRequest.getRequestURI()); @@ -105,7 +104,7 @@ public class ApiAdapterController implements HttpAdapterServiceKey { Properties transactionProp = new Properties(); //transactionProp.put(INBOUND_REQUESTED_TIME, receivedTimeMillis); // jwhong, put api received time transactionProp.put(INBOUND_REQUESTED_TIME, receivedTimeStr); - + try { String responseData = service.callApi(servletRequest, servletResponse, httpProp, adapterGroupVO, adapterVO, transactionProp); // if (RESPONSE_TYPE_ASYNC.equals(responseType)) { // table의 값이 ASYNC 로 들어가 있는데 response_type_async는 ASYN 로 되어 있어 아래처럼 비교함 jwhong 2025 @@ -116,8 +115,12 @@ public class ApiAdapterController implements HttpAdapterServiceKey { if (httpStatus == 200) { // 업체별 aync response message 가 다르다. String asyncMsgStyle = httpProp.getProperty("ASYNC_RTNMSG_TYPE", "").toUpperCase(); - //String responseBody = makeResponseBodyMsg(asyncMsgStyle); - String responseBody = asyncMsgStyle; + String responseBody =""; + if (asyncMsgStyle == null || asyncMsgStyle.trim().isEmpty()) { + responseBody = makeResponseBodyMsg(); + } else { + responseBody = asyncMsgStyle; + } responseEntity = ResponseEntity.status(httpStatus).contentType(mediaType).body(responseBody); // jwhong } else { @@ -167,15 +170,25 @@ public class ApiAdapterController implements HttpAdapterServiceKey { * @param apiUri * @return */ - private HttpDynamicInAdapterUri findAdptUri(String apiUri, HttpDynamicInAdapterManager manager) { + private HttpDynamicInAdapterUri findAdptUri(String apiUri, HttpDynamicInAdapterManager manager) throws Exception { if (StringUtils.isBlank(apiUri)) { return null; } + + //** jwhong TSEAIHS04의 api full path와 비교하여 adapter를 가져온다 + STDMessageDAO dao = ApplicationContextProvider.getContext().getBean(STDMessageDAO.class); + StandardMessageInfo stdInfo = dao.getSTDMsgByPath(apiUri); + String serviceKey = stdInfo.getBzwksvckeyname(); + int idx = serviceKey.indexOf(":"); + String adapterGrpName = (idx != -1) ? serviceKey.substring(0, idx) : serviceKey; // ':' 이전 문자열 추출 + //*** for (int i = 0; i < 10; i++) { HttpDynamicInAdapterUri adptUri = manager.getAdptUri(apiUri); if (adptUri != null) { - return adptUri; + if (adptUri.getAdptGrpName().equals(adapterGrpName)) { + return adptUri; + } } // /api/v1/public @@ -221,6 +234,23 @@ public class ApiAdapterController implements HttpAdapterServiceKey { InboundErrorLogger.error(errorInfoVO); } + + private String makeResponseBodyMsg() { + + Map dataMap = new HashMap<>(); + dataMap.put("result", 1); + Map map = new HashMap<>(); + + map.put("code", "200"); + map.put("data", dataMap); + map.put("message", "정상 처리 되었습니다."); + + JSONObject json = new JSONObject(); + json.putAll(map); + + return json.toJSONString(); + } + /* private String makeResponseBodyMsg(String asyncMsgStyle) {