outbound target url - path variable 지원
- {var1}/aaa/{httpHeaderGroup.var2} depth 있는 경우도 지원도되록 변경
This commit is contained in:
+33
-26
@@ -78,6 +78,8 @@ import com.eactive.eai.common.util.CommonLib;
|
||||
import com.eactive.eai.common.util.JSONUtils;
|
||||
import com.eactive.eai.common.util.TxFileLogger;
|
||||
import com.eactive.eai.common.util.XMLUtils;
|
||||
import com.eactive.eai.util.JsonPathUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.kjbank.encrypt.exchange.crypto.AES256Cipher;
|
||||
@@ -225,16 +227,9 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
//Object dataContent = null;
|
||||
|
||||
if (MessageType.JSON.equals(messageType)) {
|
||||
|
||||
Object parsed = JSONUtils.parseJsonGeneric(sendData);
|
||||
|
||||
if(parsed instanceof JSONObject) {
|
||||
JSONObject jsonObject = (JSONObject) parsed;
|
||||
if (jsonObject != null && StringUtils.isNotBlank(headerGroupName)) {
|
||||
httpHeader = jsonObject.get(headerGroupName);
|
||||
jsonObject.remove(headerGroupName);
|
||||
}
|
||||
|
||||
dataObject = jsonObject;
|
||||
|
||||
} else if(parsed instanceof JSONArray) {
|
||||
@@ -242,12 +237,6 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
}
|
||||
} else if (MessageType.XML.equals(messageType)) {
|
||||
Document doc = XMLUtils.convertXmlDocument(sendData);
|
||||
if (doc != null && StringUtils.isNotBlank(headerGroupName)) {
|
||||
Element root = doc.getRootElement();
|
||||
Element httpHeaderElement = root.element(headerGroupName);
|
||||
root.remove(httpHeaderElement);
|
||||
httpHeader = httpHeaderElement;
|
||||
}
|
||||
dataObject = doc;
|
||||
}
|
||||
|
||||
@@ -274,6 +263,21 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
uri = changeUrl(messageType, vo.getUrl(), restOptionData, dataObject, inboundPathVariables);
|
||||
}
|
||||
}
|
||||
|
||||
if(dataObject instanceof JSONObject) {
|
||||
if (dataObject != null && StringUtils.isNotBlank(headerGroupName)) {
|
||||
httpHeader = ((JSONObject)dataObject).get(headerGroupName);
|
||||
((JSONObject)dataObject).remove(headerGroupName);
|
||||
}
|
||||
} else if (dataObject instanceof Document) {
|
||||
Document doc = (Document)dataObject;
|
||||
if (doc != null && StringUtils.isNotBlank(headerGroupName)) {
|
||||
Element root = doc.getRootElement();
|
||||
Element httpHeaderElement = root.element(headerGroupName);
|
||||
root.remove(httpHeaderElement);
|
||||
httpHeader = httpHeaderElement;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("HttpClientAdapterServiceRest] dataObject2 = [" + dataObject + "]");
|
||||
|
||||
@@ -1675,23 +1679,26 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
uriVariables.add(fieldName);
|
||||
}
|
||||
if (MessageType.JSON.equals(messageType)) {
|
||||
JSONObject jsonObject;
|
||||
if (sendData instanceof JSONObject) {
|
||||
jsonObject = (JSONObject) sendData;
|
||||
} else {
|
||||
jsonObject = (JSONObject) JSONValue.parse((String) sendData);
|
||||
}
|
||||
for (Object tempObject : uriVariables) {
|
||||
String urlVaribleId = (String) tempObject;
|
||||
String uriVariable = null;
|
||||
if( jsonObject != null ) {
|
||||
uriVariable = (String) jsonObject.get(urlVaribleId);
|
||||
jsonObject.remove(urlVaribleId);
|
||||
}
|
||||
JsonNode jsonNode = JsonPathUtil.toTree(sendData);
|
||||
// JSONObject jsonObject;
|
||||
// if (sendData instanceof JSONObject) {
|
||||
// jsonObject = (JSONObject) sendData;
|
||||
//
|
||||
// } else {
|
||||
// jsonObject = (JSONObject) JSONValue.parse((String) sendData);
|
||||
// }
|
||||
for (String urlVaribleId : uriVariables) {
|
||||
String uriVariable = JsonPathUtil.getAt(jsonNode, urlVaribleId, "\\.");
|
||||
// String uriVariable = null;
|
||||
// if( jsonObject != null ) {
|
||||
// uriVariable = (String) jsonObject.get(urlVaribleId);
|
||||
// jsonObject.remove(urlVaribleId);
|
||||
// }
|
||||
|
||||
if (StringUtils.isBlank(uriVariable) && inboundPathVariables.containsKey(urlVaribleId)) {
|
||||
uriVariable = inboundPathVariables.get(urlVaribleId);
|
||||
}
|
||||
|
||||
urlVariableList.add(uriVariable);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.eactive.eai.util;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -19,14 +21,29 @@ public class JsonPathUtil {
|
||||
// JsonNode 기반 단일 파싱 API — 연속 get/set 시 파싱 횟수 절감
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
/** JSON 문자열을 JsonNode 트리로 파싱. */
|
||||
public static JsonNode toTree(String json) throws Exception {
|
||||
return objectMapper.readTree(json);
|
||||
/** JSON 문자열을 JsonNode 트리로 파싱. */
|
||||
public static JsonNode toTree(Object json) throws Exception {
|
||||
if(json == null)
|
||||
return null;
|
||||
else if(json instanceof JsonNode)
|
||||
return (JsonNode)json;
|
||||
else if(json instanceof String)
|
||||
return objectMapper.readTree((String)json);
|
||||
else if(json instanceof JSONObject)
|
||||
return objectMapper.readTree(((JSONObject)json).toJSONString());
|
||||
else
|
||||
return objectMapper.readTree(json.toString());
|
||||
}
|
||||
|
||||
/** 이미 파싱된 트리에서 경로의 값을 추출. */
|
||||
public static String getAt(JsonNode root, String path) {
|
||||
JsonNode node = getNodeAtPath(root, path);
|
||||
JsonNode node = getNodeAtPath(root, path, "/");
|
||||
return node != null ? node.asText() : null;
|
||||
}
|
||||
|
||||
/** 이미 파싱된 트리에서 경로의 값을 추출. */
|
||||
public static String getAt(JsonNode root, String path, String delimeter) {
|
||||
JsonNode node = getNodeAtPath(root, path, delimeter);
|
||||
return node != null ? node.asText() : null;
|
||||
}
|
||||
|
||||
@@ -90,12 +107,12 @@ public class JsonPathUtil {
|
||||
|
||||
// 특정 경로에 해당하는 부모 노드를 가져오는 유틸리티 함수
|
||||
private static JsonNode getParentNode(JsonNode rootNode, String parentPath) {
|
||||
return getNodeAtPath(rootNode, parentPath);
|
||||
return getNodeAtPath(rootNode, parentPath, "/");
|
||||
}
|
||||
|
||||
// 특정 경로에 해당하는 노드를 가져오는 유틸리티 함수
|
||||
private static JsonNode getNodeAtPath(JsonNode rootNode, String path) {
|
||||
String[] tokens = path.split("/");
|
||||
private static JsonNode getNodeAtPath(JsonNode rootNode, String path, String delimeter) {
|
||||
String[] tokens = path.split(delimeter);
|
||||
JsonNode currentNode = rootNode;
|
||||
|
||||
for (String token : tokens) {
|
||||
@@ -144,7 +161,7 @@ public class JsonPathUtil {
|
||||
if (lastSlash == 0) {
|
||||
result.remove(fieldName);
|
||||
} else {
|
||||
JsonNode parent = getNodeAtPath(result, removeFromPath.substring(0, lastSlash));
|
||||
JsonNode parent = getNodeAtPath(result, removeFromPath.substring(0, lastSlash), "/");
|
||||
if (parent instanceof ObjectNode) {
|
||||
((ObjectNode) parent).remove(fieldName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user