diff --git a/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java b/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java index fd3d012..8bff18d 100644 --- a/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java +++ b/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java @@ -114,6 +114,8 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp public static final String HTTP_HEADER_SETTING = "HTTP_HEADER_SETTING"; public static final String PAYLOAD_PARAM_NAME_CLIENT_ID = "client_id"; // jwhong + + static final String KJB_ROOTLESS_ARRAY = "{ \"KJB_ROOTLESS_ARRAY\" : "; private boolean useAdapterToken; private boolean encryptResponseApply; @@ -612,7 +614,13 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp "RECV [" + new String(responseMessage, vo.getEncode()) + "]" + CommonLib.getDumpMessage(responseMessage)); } - + + String jsonStr = new String(responseMessage, vo.getEncode()); + + if ( jsonStr.trim().startsWith("[") ) { + jsonStr = KJB_ROOTLESS_ARRAY + jsonStr + "}"; + responseMessage = jsonStr.getBytes(vo.getEncode()); + } return assignResponseHeaders(method, responseMessage, headerGroupName, vo.getEncode(), messageType, relayResponseHeaderKeys, status, responseHeaderProp); @@ -1502,22 +1510,11 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp @SuppressWarnings("deprecation") private JSONObject parseJson(String message) throws Exception { - if (message == null || message.trim().isEmpty()) { - return null; - } + if (message == null) { + return null; + } - Object obj = JSONValue.parse(message); - - if (obj instanceof JSONObject) { - return (JSONObject) obj; - } else if (obj instanceof JSONArray) { - // 배열일 경우 새로운 객체로 감싸서 반환 - JSONObject wrapper = new JSONObject(); - wrapper.put("KJB_ROOTLESS_ARRAY", obj); - return wrapper; - } - - return null; // 혹은 상황에 맞는 예외 처리 + return (JSONObject) JSONValue.parse(message); } private Document convertXmlDocument(String message) throws Exception { diff --git a/src/main/java/com/eactive/eai/adapter/http/dynamic/filter/HmacSha256VerifyFilterKjb.java b/src/main/java/com/eactive/eai/adapter/http/dynamic/filter/HmacSha256VerifyFilterKjb.java index 4d73b4e..92bed3d 100644 --- a/src/main/java/com/eactive/eai/adapter/http/dynamic/filter/HmacSha256VerifyFilterKjb.java +++ b/src/main/java/com/eactive/eai/adapter/http/dynamic/filter/HmacSha256VerifyFilterKjb.java @@ -14,6 +14,8 @@ import javax.servlet.http.HttpServletResponse; //import org.apache.commons.net.util.Base64; import org.springframework.http.HttpStatus; import org.apache.commons.lang3.StringUtils; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; import com.eactive.eai.adapter.http.HttpMethodType; import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey; @@ -24,6 +26,8 @@ import com.eactive.eai.common.TransactionContextKeys; import com.eactive.eai.common.util.Logger; public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter { + + static final String KJB_ROOTLESS_ARRAY = "{ \"KJB_ROOTLESS_ARRAY\" : "; static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER); @@ -58,6 +62,14 @@ public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter { String chkBody = inboundBody; String clientSecret = assignClientSecret(prop, request); + if (chkBody.startsWith(KJB_ROOTLESS_ARRAY)) { + chkBody = chkBody.substring(KJB_ROOTLESS_ARRAY.length()); + + if (chkBody.endsWith("}")) { + chkBody = chkBody.substring(0, chkBody.length() - 1); + } + } + String macUrl = calculateHMAC(chkUrl, clientSecret); String macBody = calculateHMAC(chkBody, clientSecret); @@ -145,6 +157,15 @@ public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter { String outboundBody = (String) resultMessage; try { + + if (outboundBody.startsWith(KJB_ROOTLESS_ARRAY)) { + outboundBody = outboundBody.substring(KJB_ROOTLESS_ARRAY.length()); + + if (outboundBody.endsWith("}")) { + outboundBody = outboundBody.substring(0, outboundBody.length() - 1); + } + } + String clientSecret = assignClientSecret(prop, request); String macBody = calculateHMAC(outboundBody, clientSecret); @@ -157,5 +178,6 @@ public class HmacSha256VerifyFilterKjb implements HttpAdapterFilter { return resultMessage; } + }