From 51db6c88cfc2d827f90141ceeef0d798b7d2abf3 Mon Sep 17 00:00:00 2001 From: cho Date: Mon, 12 Jan 2026 15:20:30 +0900 Subject: [PATCH] =?UTF-8?q?RootlessArray=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/HttpClient5AdapterServiceRest.java | 23 +++++++++++++++++- .../impl/HttpAdapterServiceStandard.java | 24 ++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) 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 846d66e..ad296ca 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 @@ -988,6 +988,16 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp return; } + if (eaiBody instanceof JSONObject) { + JSONObject jsonObject = (JSONObject) eaiBody; + if( jsonObject.containsKey("KJB_ROOTLESS_ARRAY") ) { + ContentType contentTypeObj = ContentType.create(contentType, charset); + JSONArray array = (JSONArray) jsonObject.get("KJB_ROOTLESS_ARRAY"); + StringEntity entity = new StringEntity(array.toJSONString(), contentTypeObj); + method.setEntity(entity); + return; + } + } if (StringUtils.contains(contentType, "application/x-www-form-urlencoded")) { if (eaiBody instanceof JSONObject) { @@ -1500,7 +1510,18 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp return null; } - return (JSONObject) JSONValue.parse(message); + 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; // 혹은 상황에 맞는 예외 처리 } private Document convertXmlDocument(String message) throws Exception { diff --git a/src/main/java/com/eactive/eai/adapter/http/dynamic/impl/HttpAdapterServiceStandard.java b/src/main/java/com/eactive/eai/adapter/http/dynamic/impl/HttpAdapterServiceStandard.java index 8bcd3f4..f41e532 100644 --- a/src/main/java/com/eactive/eai/adapter/http/dynamic/impl/HttpAdapterServiceStandard.java +++ b/src/main/java/com/eactive/eai/adapter/http/dynamic/impl/HttpAdapterServiceStandard.java @@ -184,7 +184,18 @@ public class HttpAdapterServiceStandard extends HttpAdapterServiceSupport prop.put(ALLOW_IP, httpProp.getProperty(ALLOW_IP, "")); String body = new String ( requestBytes,encode); - + + try { + Object root = JSONValue.parse(body); + if( root instanceof JSONArray ) { + JSONObject wrappedObject = new JSONObject(); + wrappedObject.put("KJB_ROOTLESS_ARRAY", root); + requestBytes = wrappedObject.toJSONString().getBytes(encode); + } + + }catch (Exception e) { + // ignore json이 아니기에 해줄것이 없음. + } // 로컬 서비스 호출 Object result = null; @@ -235,6 +246,17 @@ public class HttpAdapterServiceStandard extends HttpAdapterServiceSupport if (addData.length() > 0){ responseData = addData + responseData; } + + try { + Object root = JSONValue.parse(responseData); + if( root instanceof JSONObject ) { + JSONObject wrappedObject = (JSONObject) root; + responseData = wrappedObject.get("KJB_ROOTLESS_ARRAY").toString(); + } + + }catch (Exception e) { + // ignore json이 아니기에 해줄것이 없음. + } // 300응답에서 받은 Header정보 사용하기 위해 읽어옴. Map responsePropertyMap = new HashMap();