This commit is contained in:
jaewohong
2026-01-15 15:08:09 +09:00
parent cafebb528f
commit d9543fa160
@@ -114,6 +114,8 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
public static final String HTTP_HEADER_SETTING = "HTTP_HEADER_SETTING";
public static final String PAYLOAD_PARAM_NAME_CLIENT_ID = "client_id"; // jwhong
static final String KJB_ROOTLESS_ARRAY = "{ \"KJB_ROOTLESS_ARRAY\" : ";
private boolean useAdapterToken;
private boolean encryptResponseApply;
@@ -161,7 +163,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
// 레이아웃 메시지 타입 REST URL 추출 시 활용. Default JSON
String messageType = prop.getProperty("MESSAGE_TYPE", MessageType.JSON);
String inboundMethod = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_METHOD, "POST");
String inboundToken = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_TOKEN, "");
//String inboundToken = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_TOKEN, "");
//Outbound 요청에 대한 응답 메시지의 복호화 여부 결정위해 jwhong
encryptResponseApply = StringUtils.equalsIgnoreCase(prop.getProperty("ENCRYPT_RESPONSE_APPLY", "N"), "Y");
@@ -378,7 +380,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
// assignPostBody(dataObject, contentType, vo.getEncode(), method);
//assignPostBody(dataContent, contentType, vo.getEncode(), method); // jwhong commnet
// KJBank API 추적정보를 Header에 제공. jwhong
// String inboundToken= assignRequestKJHeaders(method, prop, tempProp );
String inboundToken= assignRequestKJHeaders(method, prop, tempProp );
assignPostBody(dataContent, contentType, vo.getEncode(), method, vo.getAdapterName(), auth, inboundToken, currentDate);
break;
default:
@@ -396,9 +398,6 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
// Adapter 레벨 header 보다 data로 넘어온 httpHeader를 우선 적용(header명이 같다면 덮어씀)
assignRequestHeaders(method, httpHeader, prop);
// KJBank API 추적정보를 Header에 제공. jwhong
//assignRequestKJHeaders(method, prop, tempProp );
int status = -1;
try {
@@ -612,6 +611,13 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
"RECV [" + new String(responseMessage, vo.getEncode()) + "]"
+ CommonLib.getDumpMessage(responseMessage));
}
String jsonStr = new String(responseMessage, vo.getEncode());
if ( jsonStr.trim().startsWith("[") ) {
jsonStr = KJB_ROOTLESS_ARRAY + jsonStr + "}";
responseMessage = jsonStr.getBytes(vo.getEncode());
}
return assignResponseHeaders(method, responseMessage, headerGroupName, vo.getEncode(), messageType,
@@ -866,6 +872,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
/*
* KJBank Target System으로 요청 보낼때 header에 clientId(업체정보), APIM거래추적자(UUID), 최초 요청시간, guid 추가해서 보낸다. jwhong
* token 만 return 하는것으로 수정함
*/
private String assignRequestKJHeaders(HttpUriRequestBase method, Properties prop, Properties tempProp){
@@ -912,51 +919,6 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
if (authorization != null && authorization.startsWith("Bearer ")) {
jwtToken = authorization.substring(7); // "Bearer " 이후의 JWT만 추출
}
String headerRelay = PropManager.getInstance().getProperty("HEADER_RELAY_ADAPTER","adapter.name");
Set<String> values = new HashSet<>(Arrays.asList(headerRelay.split(",")));
String inputAdapter = tempProp.getProperty(HttpAdapterServiceKey.OUT_ADAPTER_GROUP_NAME, "");
String[] parts = inputAdapter.split("_");
String target = parts[1]; // adapter name의 앞의 3자리
String adapterName = target.substring(0, 3);
if (values.contains(adapterName)) {
/* 업체정보 */
String clientId = JwtClientIdExtractor(jwtToken);
method.setHeader("clientId", clientId);
/* APIM 거래추적자 */
String uuid = tempProp.getProperty(TransactionContextKeys.TRANSACTION_UUID, "");
method.setHeader("traceId", uuid);
/* GUID */
String guid = tempProp.getProperty(TransactionContextKeys.GUID, "");
method.setHeader("guid", guid);
/* 최초요청시간 */
String receivedTimestamp = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_REQUESTED_TIME, "");
method.setHeader("receivedTimestamp", receivedTimestamp);
}
/* 업체정보 */
//String clientId = JwtClientIdExtractor(jwtToken);
//method.setHeader("clientId", clientId);
/* APIM 거래추적자 */
//String uuid = tempProp.getProperty(TransactionContextKeys.TRANSACTION_UUID, "");
//method.setHeader("traceId", uuid);
/* GUID */
//String guid = tempProp.getProperty(TransactionContextKeys.GUID, "");
//method.setHeader("guid", guid);
/* 최초요청시간 */
//String receivedTimestamp = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_REQUESTED_TIME, "");
//method.setHeader("receivedTimestamp", receivedTimestamp);
return jwtToken;
}
@@ -983,7 +945,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
}
@SuppressWarnings("deprecation")
private void assignPostBody(Object eaiBody, String contentType, String charset, HttpUriRequestBase method, String adapterName, String niceAuth, String inboundToken, Date currentDate) {
private void assignPostBody(Object eaiBody, String contentType, String charset, HttpUriRequestBase method, String adapterName, String niceAuth, String inboundToken, Date currentDate) throws Exception {
if (eaiBody == null) {
return;
}
@@ -1023,7 +985,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
}
// from here by jwhong
private String doOutboundPreFilter(Object eaiBody, String adapterName, String niceAuth, String inboundToken, Date currentDate) {
private String doOutboundPreFilter(Object eaiBody, String adapterName, String niceAuth, String inboundToken, Date currentDate) throws Exception {
Properties properties = AdapterPropManager.getInstance().getProperties(adapterName); // jwhong
String encryptAlgorithm = properties.getProperty("ENCRYPT_ALGORITHM",""); // jwhong
@@ -1063,7 +1025,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
return responseMessage;
}
private String doOutboundPreEncrypt(Object eaiBody, String encryptAlgorithm, String clientSecretKey, String encryptAES256Iv, String encryptAES256Key, String certPath, Date currentDate) {
private String doOutboundPreEncrypt(Object eaiBody, String encryptAlgorithm, String clientSecretKey, String encryptAES256Iv, String encryptAES256Key, String certPath, Date currentDate) throws Exception {
String encryptedMessage = "";
String encryptedJsonKey = "";
@@ -1082,6 +1044,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
} catch (Exception e) {
e.printStackTrace();
logger.error("HttpClientAdapterServiceRest] AES128 Encryption error=" + e.getMessage());
throw new Exception("[HttpClient5AdapterServiceRest] Pre Encrypt Error : Encrypted Error, AES128 Key Invalid");
}
break;
case "AES128-TOGETHER":
@@ -1091,6 +1054,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
} catch (Exception e) {
e.printStackTrace();
logger.error("HttpClientAdapterServiceRest] AES128 Encryption error=" + e.getMessage());
throw new Exception("[HttpClient5AdapterServiceRest] Pre Encrypt Error : Encrypted Error, AES128 Key Invalid");
}
break;
case "AES256":
@@ -1100,6 +1064,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
} catch (Exception e) {
e.printStackTrace();
logger.error("HttpClientAdapterServiceRest] AES256 Encryption error=" + e.getMessage());
throw new Exception("[HttpClient5AdapterServiceRest] Pre Encrypt Error : Encrypted Error, AES256 Key Invalid");
}
break;
case "AES256-KAKAO":
@@ -1108,6 +1073,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
} catch (Exception e) {
e.printStackTrace();
logger.error("HttpClientAdapterServiceRest] AES256 Encryption error=" + e.getMessage());
throw new Exception("[HttpClient5AdapterServiceRest] Pre Encrypt Error : Encrypted Error, AES256 Key Invalid");
}
break;
case "AES256-TOSS":
@@ -1116,6 +1082,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
} catch (Exception e) {
e.printStackTrace();
logger.error("HttpClientAdapterServiceRest] AES256 Encryption error=" + e.getMessage());
throw new Exception("[HttpClient5AdapterServiceRest] Pre Encrypt Error : Encrypted Error, AES256 Key Invalid");
}
break;
case "AES256-NICEON":
@@ -1127,6 +1094,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
} catch (Exception e) {
e.printStackTrace();
logger.error("HttpClientAdapterServiceRest] AES256 Encryption error=" + e.getMessage());
throw new Exception("[HttpClient5AdapterServiceRest] Pre Encrypt Error : Encrypted Error, AES256 Key Invalid");
}
break;
case "AES256GCM":
@@ -1139,6 +1107,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
} catch (Exception e) {
e.printStackTrace();
logger.error("HttpClientAdapterServiceRest] AES256GCM Encryption error=" + e.getMessage());
throw new Exception("[HttpClient5AdapterServiceRest] Pre Encrypt Error : Encrypted Error, AES256GCM Key Invalid");
}
break;
case "ECDHESA256":
@@ -1160,6 +1129,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
} catch (Exception e) {
e.printStackTrace();
logger.error("HttpClientAdapterServiceRest] AES256GCM Encryption error=" + e.getMessage());
throw new Exception("[HttpClient5AdapterServiceRest] Pre Encrypt Error : Encrypted Error, ECDHESA256 Key Invalid");
}
break;
default:
@@ -1502,22 +1472,11 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
@SuppressWarnings("deprecation")
private JSONObject parseJson(String message) throws Exception {
if (message == null || message.trim().isEmpty()) {
return null;
}
if (message == null) {
return null;
}
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; // 혹은 상황에 맞는 예외 처리
return (JSONObject) JSONValue.parse(message);
}
private Document convertXmlDocument(String message) throws Exception {