outbound target url - path variable 지원
- {var1}/aaa/{httpHeaderGroup.var2} depth 있는 경우도 지원도되록 변경
This commit is contained in:
@@ -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