불필요한 로직 제거 및 json 처리 메소드 이동

This commit is contained in:
curry772
2026-06-12 09:14:28 +09:00
parent 05a456b461
commit a616cd6334
2 changed files with 31 additions and 8 deletions
@@ -36,7 +36,6 @@ import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ContentType;
@@ -76,6 +75,7 @@ import com.eactive.eai.common.exception.ExceptionUtil;
import com.eactive.eai.common.message.MessageType;
import com.eactive.eai.common.property.PropManager;
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.jayway.jsonpath.DocumentContext;
@@ -209,11 +209,13 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
}
HttpClient mclient = this.client;
String sendData = "";
Object sendData = "";
if (data instanceof String) {
sendData = (String) data;
sendData = data;
} else if (data instanceof byte[]) {
sendData = new String((byte[]) data, vo.getEncode());
} else if (data instanceof JSONObject) {
sendData = data;
}
////mclient.getParams().setContentCharset(vo.getEncode());
@@ -224,7 +226,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
if (MessageType.JSON.equals(messageType)) {
Object parsed = parseJsonGeneric(sendData);
Object parsed = JSONUtils.parseJsonGeneric(sendData);
if(parsed instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) parsed;
@@ -235,10 +237,6 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
dataObject = jsonObject;
if (jsonObject.containsKey("innerList")) {
JSONArray innerList = (JSONArray) jsonObject.get("innerList");
dataObject = innerList;
}
} else if(parsed instanceof JSONArray) {
// not support
}
@@ -12,6 +12,7 @@ import org.apache.commons.lang3.math.NumberUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class JSONUtils {
@@ -19,6 +20,30 @@ public class JSONUtils {
private JSONUtils() {
throw new IllegalStateException("Utility class");
}
public static Object parseJsonGeneric(Object jsonData) {
if (jsonData == null) {
return new JSONObject();
}
if (jsonData instanceof JSONObject) {
return (JSONObject) jsonData;
} else if (jsonData instanceof String) {
if (StringUtils.isBlank((String) jsonData)) {
return new JSONObject();
}
try {
JSONParser parser = new JSONParser();
Object parsedObj = parser.parse((String) jsonData);
return parsedObj;
} catch (ParseException e) {
e.printStackTrace();
return null;
}
} else
throw new IllegalArgumentException("not support json type. " + jsonData.getClass());
}
public static JSONObject parseJson(Object message) {
if (message == null) {