JsonNode 사용방식으로 변경
This commit is contained in:
+66
-72
@@ -7,11 +7,7 @@ import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -22,10 +18,6 @@ import java.util.Properties;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// encrypt test by jwhong
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
@@ -58,44 +50,33 @@ import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterPropManager;
|
||||
import com.eactive.eai.adapter.http.HttpMemoryLogger;
|
||||
import com.eactive.eai.adapter.http.HttpMethodType;
|
||||
import com.eactive.eai.adapter.http.client.HttpClient5AdapterServiceSupport;
|
||||
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
||||
import com.eactive.eai.adapter.http.client.HttpClientAdapterVO;
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
||||
import com.eactive.eai.authserver.service.OAuth2Manager;
|
||||
import com.eactive.eai.common.TransactionContextKeys;
|
||||
import com.eactive.eai.common.authoutbound.AccessTokenManagerByDB;
|
||||
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.JacksonUtil;
|
||||
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.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.kjbank.encrypt.exchange.crypto.AES256Cipher;
|
||||
import com.kjbank.encrypt.exchange.crypto.AES256GCMCipher;
|
||||
import com.kjbank.encrypt.exchange.crypto.AESCipher;
|
||||
import com.kjbank.encrypt.exchange.crypto.ECDHESA256Cipher;
|
||||
import com.nimbusds.jwt.SignedJWT;
|
||||
import com.openbanking.eai.common.token.AccessTokenManager;
|
||||
import com.openbanking.eai.common.token.AccessTokenVO;
|
||||
import com.openbanking.eai.common.token.OAuth2AccessTokenVO;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 1. 기능 : EAI HTTP OutBound 용 어댑터로 수동 시스템의 HTTP 웹 컴포넌트를 GET/POST 방식으로 호출할 수 있는
|
||||
* 기능을 제공한다.<br>
|
||||
@@ -128,8 +109,6 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
|
||||
private boolean useAdapterToken;
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 1. 기능 : REST API 통신에 사용 <br>
|
||||
* 2. 처리 개요 : - 속성 정보를 설정 하고 수동 시스템 서비스를 호출 한다. <br>
|
||||
@@ -235,7 +214,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
} else if(sendData instanceof JSONObject) {
|
||||
dataObject = sendData;
|
||||
} else {
|
||||
dataObject = JsonPathUtil.toTree(sendData);
|
||||
dataObject = JacksonUtil.readTree(sendData);
|
||||
}
|
||||
} else if (MessageType.XML.equals(messageType)) {
|
||||
Document doc = XMLUtils.convertXmlDocument(sendData);
|
||||
@@ -771,7 +750,6 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object assignResponseHeaders(HttpUriRequestBase method, byte[] responseMessage, String headerGroupName,
|
||||
String encode, String responseContentType, String relayHeaderKeys, int status, Properties responseHeaderProp) throws Exception {
|
||||
String messageType = MessageType.JSON;
|
||||
@@ -798,43 +776,52 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
}
|
||||
|
||||
if(StringUtils.equalsAny(messageType, MessageType.JSON)) {
|
||||
JSONObject headerJson = new JSONObject();
|
||||
if (StringUtils.equalsIgnoreCase(relayHeaderKeys, "ALL")) {
|
||||
for (Enumeration<Object> e = responseHeaderProp.keys(); e.hasMoreElements(); ) {
|
||||
String key = (String)e.nextElement();
|
||||
headerJson.put(StringUtils.lowerCase(key), responseHeaderProp.getProperty(key));
|
||||
}
|
||||
} else {
|
||||
String[] relayKeyArr = org.springframework.util.StringUtils.tokenizeToStringArray(relayHeaderKeys, ",");
|
||||
for (String key : relayKeyArr) {
|
||||
String value = responseHeaderProp.getProperty(key);
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
headerJson.put(StringUtils.lowerCase(key), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
ObjectNode headerJson = JacksonUtil.createObjectNode();
|
||||
|
||||
headerJson.put(HTTP_STATUS, String.valueOf(status));
|
||||
if (StringUtils.equalsIgnoreCase(relayHeaderKeys, "ALL")) {
|
||||
for (Enumeration<Object> e = responseHeaderProp.keys(); e.hasMoreElements(); ) {
|
||||
String key = (String) e.nextElement();
|
||||
headerJson.put(StringUtils.lowerCase(key), responseHeaderProp.getProperty(key));
|
||||
}
|
||||
} else {
|
||||
String[] relayKeyArr = org.springframework.util.StringUtils.tokenizeToStringArray(relayHeaderKeys, ",");
|
||||
for (String key : relayKeyArr) {
|
||||
String value = responseHeaderProp.getProperty(key);
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
headerJson.put(StringUtils.lowerCase(key), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (headerJson.size() <= 0) {
|
||||
return new String(responseMessage, charset);
|
||||
}
|
||||
headerJson.put(HTTP_STATUS, String.valueOf(status));
|
||||
|
||||
JSONObject message = null;
|
||||
if (responseMessage == null || responseMessage.length == 0) {
|
||||
message = new JSONObject();
|
||||
} else {
|
||||
message = parseJson(new String(responseMessage, charset));
|
||||
if (message == null) {
|
||||
message = new JSONObject();
|
||||
message.put("Malformed_Response_Message", new String(responseMessage, charset));
|
||||
}
|
||||
}
|
||||
if (headerJson.isEmpty()) {
|
||||
return new String(responseMessage, charset);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(headerGroupName) && message != null)
|
||||
message.put(headerGroupName, headerJson);
|
||||
ObjectNode message;
|
||||
if (responseMessage == null || responseMessage.length == 0) {
|
||||
message = JacksonUtil.createObjectNode();
|
||||
} else {
|
||||
JsonNode parsed = null;
|
||||
try {
|
||||
parsed = JacksonUtil.readTree(new String(responseMessage, charset));
|
||||
} catch (Exception e) {
|
||||
logger.warn("response message parse error", e);
|
||||
}
|
||||
if (parsed == null || !parsed.isObject()) {
|
||||
message = JacksonUtil.createObjectNode();
|
||||
message.put("Malformed_Response_Message", new String(responseMessage, charset));
|
||||
} else {
|
||||
message = (ObjectNode) parsed;
|
||||
}
|
||||
}
|
||||
|
||||
return message;
|
||||
if (StringUtils.isNotBlank(headerGroupName) && message != null) {
|
||||
message.set(headerGroupName, headerJson);
|
||||
}
|
||||
|
||||
return message;
|
||||
} else if (StringUtils.equalsAny(messageType, MessageType.XML)) {
|
||||
Document doc = XMLUtils.convertXmlDocument(new String(responseMessage, charset));
|
||||
Element root = doc.getRootElement();
|
||||
@@ -951,24 +938,31 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject httpValues = (JSONObject) JSONValue.parse(httpSettingJsonStr);
|
||||
JsonNode httpValues = JacksonUtil.readTree(httpSettingJsonStr);
|
||||
|
||||
for (Object key : httpValues.keySet()) {
|
||||
Object obj = httpValues.get(key);
|
||||
if ((obj instanceof JSONObject) || (obj instanceof JSONArray)) {
|
||||
continue;
|
||||
if (httpValues == null || !httpValues.isObject()) {
|
||||
logger.error("HTTP_HEADER_SETTING value is not json Type, skip.");
|
||||
} else {
|
||||
Iterator<String> fieldNames = httpValues.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String key = fieldNames.next();
|
||||
JsonNode obj = httpValues.get(key);
|
||||
|
||||
if (obj == null || obj.isObject() || obj.isArray()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String headerValue = obj.isNull() ? "" : obj.asText();
|
||||
method.setHeader(key, headerValue);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Request Header :" + key + "=[" + headerValue + "]");
|
||||
}
|
||||
}
|
||||
|
||||
method.setHeader((String) key, obj);
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Request Header :" + (String) key + "=[" + (String) obj + "]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}catch (Exception e) {
|
||||
logger.error("HTTP_HEADER_SETTING value is not JSONObject Type, skip.", e);
|
||||
} catch (Exception e) {
|
||||
logger.error("HTTP_HEADER_SETTING value is not json Type, skip.", e);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1042,7 +1036,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
} else if(eaiBody instanceof JSONObject) {
|
||||
body = ((JSONObject)eaiBody).toJSONString();
|
||||
} else if(eaiBody instanceof ObjectNode) {
|
||||
body = mapper.writeValueAsString((ObjectNode) eaiBody);
|
||||
body = JacksonUtil.writeAsString((ObjectNode) eaiBody);
|
||||
} else {
|
||||
body = eaiBody.toString();
|
||||
}
|
||||
@@ -1170,7 +1164,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
uriVariables.add(fieldName);
|
||||
}
|
||||
if (MessageType.JSON.equals(messageType)) {
|
||||
JsonNode jsonNode = JsonPathUtil.toTree(sendData);
|
||||
JsonNode jsonNode = JacksonUtil.readTree(sendData);
|
||||
// JSONObject jsonObject;
|
||||
// if (sendData instanceof JSONObject) {
|
||||
// jsonObject = (JSONObject) sendData;
|
||||
|
||||
@@ -99,7 +99,7 @@ public abstract class HttpAdapterServiceSupport implements HttpAdapterService, H
|
||||
} else if (obj instanceof JSONObject) {
|
||||
return ((JSONObject) obj).toJSONString();
|
||||
} else if (obj instanceof JsonNode) {
|
||||
return mapper.writeValueAsString((JsonNode) obj);
|
||||
return (JsonNode) obj;
|
||||
} else {
|
||||
throw new Exception("RECEAIAHA001");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user