사용하지 않는 클래스 제거
This commit is contained in:
@@ -1,380 +0,0 @@
|
||||
//package com.eactive.eai.adapter.controller;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Collections;
|
||||
//import java.util.Date;
|
||||
//import java.util.Enumeration;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.Properties;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//// jwhong
|
||||
//import org.json.simple.JSONObject;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.http.HttpStatus;
|
||||
//import org.springframework.http.MediaType;
|
||||
//import org.springframework.http.ResponseEntity;
|
||||
//import org.springframework.util.AntPathMatcher;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.RestController;
|
||||
//
|
||||
//import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
//import com.eactive.eai.adapter.AdapterManager;
|
||||
//import com.eactive.eai.adapter.AdapterPropManager;
|
||||
//import com.eactive.eai.adapter.AdapterVO;
|
||||
//import com.eactive.eai.adapter.Keys;
|
||||
//import com.eactive.eai.adapter.http.HttpStatusException;
|
||||
//import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
||||
//import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
||||
//import com.eactive.eai.adapter.http.dynamic.HttpDynamicInAdapterManager;
|
||||
//import com.eactive.eai.adapter.http.dynamic.HttpDynamicInAdapterUri;
|
||||
//import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilter;
|
||||
//import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilterFactoryKjb;
|
||||
//import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthException;
|
||||
//import com.eactive.eai.adapter.service.ApiAdapterService;
|
||||
//import com.eactive.eai.common.TransactionContextKeys;
|
||||
//import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
//import com.eactive.eai.common.server.EAIServerManager;
|
||||
//import com.eactive.eai.common.stdmessage.STDMessageManager;
|
||||
//import com.eactive.eai.common.stdmessage.STDMsgInfoAddOnVO;
|
||||
//import com.eactive.eai.common.util.DatetimeUtil;
|
||||
//import com.eactive.eai.common.util.InboundErrorLogger;
|
||||
//import com.eactive.eai.common.util.Logger;
|
||||
//import com.eactive.eai.common.util.MessageUtil;
|
||||
//import com.eactive.eai.common.util.UUIDGenerator;
|
||||
//import com.eactive.eai.inbound.action.ActionException;
|
||||
//import com.eactive.eai.inbound.action.ActionFactory;
|
||||
//import com.eactive.eai.inbound.action.RequestAction;
|
||||
//import com.eactive.eai.inbound.error.InboundErrorInfoVO;
|
||||
//
|
||||
//@RestController
|
||||
//public class ApiAdapterController implements HttpAdapterServiceKey {
|
||||
// static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
|
||||
//
|
||||
// @Autowired
|
||||
// ApiAdapterService service;
|
||||
//
|
||||
// /**
|
||||
// * KJBANK 요구사항으로 /mapi/oauth2/token 과 같은 형태로 토큰 발급거래를 수행해야해서 예외처리함
|
||||
// *
|
||||
// * @See com.eactive.eai.authserver.config.AuthorizationServerConfig.configure(AuthorizationServerEndpointsConfigurer
|
||||
// * endpoints)
|
||||
// */
|
||||
// @RequestMapping(value = { "/api/*", "/mapi/*", "/api/*/{path:^(?!.*oauth).*$}/**",
|
||||
// "/mapi/{path:^(?!.*oauth2).*$}/**" })
|
||||
//// @RequestMapping(value = {"/api/**"})
|
||||
// public ResponseEntity<String> callApi(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
|
||||
// throws Exception {
|
||||
// // /ONLWeb/api/v1/public/getUserInfo.svc
|
||||
// String apiUri = servletRequest.getRequestURI();
|
||||
// // /api/v1/public/getUserInfo.svc
|
||||
// apiUri = StringUtils.removeStart(apiUri, servletRequest.getContextPath());
|
||||
// apiUri = StringUtils.removeEnd(apiUri, "/");
|
||||
//
|
||||
// HttpDynamicInAdapterUri adptUri = findAdptUri(apiUri, HttpDynamicInAdapterManager.getInstance(), "");
|
||||
//
|
||||
// if (logger.isDebug()) {
|
||||
// logger.debug("ApiAdapterController] service request uri : " + servletRequest.getRequestURI());
|
||||
// }
|
||||
//
|
||||
// if (adptUri == null) {
|
||||
// logError(servletRequest);
|
||||
// String errorMsg = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_SERVICE_NOT_FOUND,
|
||||
// "can not find Adapter Uri");
|
||||
// return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON).body(errorMsg);
|
||||
// }
|
||||
//
|
||||
// // Received time , jwhong
|
||||
// long receivedTimeMillis = System.currentTimeMillis(); // 밀리세컨 단위로 보내야함
|
||||
// String receivedTimeStr = String.valueOf(receivedTimeMillis);
|
||||
//
|
||||
// String adapterGroupName = adptUri.getAdptGrpName();
|
||||
// String adapterName = adptUri.getAdptName();
|
||||
// AdapterGroupVO adapterGroupVO = AdapterManager.getInstance().getAdapterGroupVO(adapterGroupName);
|
||||
// AdapterVO adapterVO = AdapterManager.getInstance().getAdapterVO(adapterGroupName, adapterName);
|
||||
// if (adapterVO == null) {
|
||||
// String errorMsg = MessageUtil.makeJsonErrorMessage(MessageUtil.ERROR_CODE_AP_ERROR,
|
||||
// "Adapter not found error");
|
||||
// return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(MediaType.APPLICATION_JSON)
|
||||
// .body(errorMsg);
|
||||
// }
|
||||
//
|
||||
// Properties httpProp = AdapterPropManager.getInstance().getProperties(adapterVO.getPropGroupName());
|
||||
//
|
||||
// String adptMsgType = adapterVO.getAdapterGroupVO().getMessageType();
|
||||
// String encode = StringUtils.defaultIfBlank(adapterGroupVO.getMessageEncode(), "UTF-8");
|
||||
// MediaType mediaType = MediaType.valueOf("application/json;charset=" + encode);
|
||||
// String errorResponseFormat = httpProp.getProperty(ERROR_RESPONSE_FORMAT);
|
||||
//
|
||||
// String responseType = httpProp.getProperty(RESPONSE_TYPE, "SYNC");
|
||||
// ResponseEntity responseEntity = null;
|
||||
// Properties transactionProp = new Properties();
|
||||
// // jwhong, put api received time, eaiSvcCode
|
||||
// transactionProp.put(INBOUND_REQUESTED_TIME, receivedTimeStr);
|
||||
//
|
||||
// // ** jwhong TSEAIHS04의 api full path와 비교하여 adapter를 가져온다
|
||||
//// String bzwkSvcKeyName = ""; // Adapter Group별 Action Class에 따라 구성이 달라짐. 예)
|
||||
//// // _AGW_IN_RST_SyS:POST/account/{acc_no}
|
||||
//// String adapterGrpName = ""; // Adapter Group명 예) _AGW_IN_RST_SyS : API_PATH(/api/test)
|
||||
// String apiSvcCode = ""; // eaiSvcCd 예) LONNCHCON00005S2
|
||||
// String apiFullPathKey = ""; // 예) POST|/api/test/account/list, POST|/api/test/account/{acc_no}
|
||||
// Map<String, String> pathVariables = null;
|
||||
// try {
|
||||
// // PathVariable(ex:/api/test/account/{acc_no}) 대응 및 DAO조회 제거.
|
||||
// // /api/test/account/1234567 호출시 /api/test/account/{acc_no} API 로 식별.
|
||||
//
|
||||
//// String methodAndUri = getRequestRuledPath(servletRequest, apiUri, adapterVO, transactionProp);
|
||||
// String methodAndUri = servletRequest.getMethod() + "|" + apiUri;
|
||||
// STDMessageManager manager = STDMessageManager.getInstance();
|
||||
// STDMsgInfoAddOnVO stdMsgInfo = manager.getStdMsgInfoAddOn(methodAndUri);
|
||||
//// bzwkSvcKeyName = stdMsgInfo.getBzwksvckeyname();
|
||||
// apiSvcCode = stdMsgInfo.getEaiSvcCd();
|
||||
// transactionProp.put(API_SERVICE_CODE, apiSvcCode);
|
||||
//
|
||||
//// adapterGrpName = stdMsgInfo.gAdapterGroupName();
|
||||
// apiFullPathKey = stdMsgInfo.getApiFullPath();
|
||||
// if (STDMessageManager.isPathVariable(apiFullPathKey)) {
|
||||
// pathVariables = new AntPathMatcher().extractUriTemplateVariables(apiFullPathKey, methodAndUri);
|
||||
// }
|
||||
//
|
||||
//// adptUri = findAdptUri(apiUri, HttpDynamicInAdapterManager.getInstance(), adapterGrpName);
|
||||
// } catch (Exception e) {
|
||||
//// adptUri = null;
|
||||
// }
|
||||
// // ***
|
||||
// if (pathVariables != null) {
|
||||
// transactionProp.put(INBOUND_PATH_VARIABLES, pathVariables);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// String responseData = service.callApi(servletRequest, servletResponse, httpProp, adapterGroupVO, adapterVO,
|
||||
// transactionProp);
|
||||
// // if (RESPONSE_TYPE_ASYNC.equals(responseType)) { // table의 값이 ASYNC 로 들어가 있는데
|
||||
// // response_type_async는 ASYN 로 되어 있어 아래처럼 비교함 jwhong 2025
|
||||
// if ("ASYNC".equals(responseType)) {
|
||||
// // responseEntity = ResponseEntity.ok("dummy"); // comment by jwhong
|
||||
// // servletResponse.addHeader("traceId", responseData); // uuid를 response header에
|
||||
// servletResponse.addHeader("traceId",
|
||||
// transactionProp.getProperty(TransactionContextKeys.TRANSACTION_UUID)); // uuid를 response header에
|
||||
// int httpStatus = servletResponse.getStatus();
|
||||
// if (httpStatus == 200) {
|
||||
// // 업체별 aync response message 가 다르다.
|
||||
// String asyncMsgStyle = httpProp.getProperty("ASYNC_RTNMSG_TYPE", "");
|
||||
// String responseBody = "";
|
||||
// boolean encryptAsyncAckApply = StringUtils
|
||||
// .equalsIgnoreCase(httpProp.getProperty("ASYNC_ENCRYPT_ACK", "N"), "Y");
|
||||
//
|
||||
// if (asyncMsgStyle == null || asyncMsgStyle.trim().isEmpty()) {
|
||||
// responseBody = makeResponseBodyMsg();
|
||||
// } else {
|
||||
// responseBody = asyncMsgStyle;
|
||||
// }
|
||||
// if (encryptAsyncAckApply) {
|
||||
// responseBody = service.doPostEncryption(responseBody, transactionProp, servletRequest);
|
||||
// }
|
||||
//
|
||||
// responseEntity = ResponseEntity.status(httpStatus).contentType(mediaType).body(responseBody);
|
||||
// // jwhong
|
||||
// } else {
|
||||
// responseEntity = ResponseEntity.status(httpStatus).contentType(mediaType).body(responseData);
|
||||
// }
|
||||
// } else {
|
||||
//// responseEntity = ResponseEntity.ok().contentType(mediaType).body(responseData);
|
||||
//// 버즈빌 포인트 적립 처리하기 위하여 정상응답이더라도 응답코드(apiRsltCd) 값이 200이 아닌 경우 처리를 위하여 수정
|
||||
//// Filter에서 설정한 response status값을 responseEntity 생성시 적용 modify by lwk 2025.03.24
|
||||
//
|
||||
// servletResponse.addHeader("traceId",
|
||||
// transactionProp.getProperty(TransactionContextKeys.TRANSACTION_UUID)); // uuid를 response header에
|
||||
// int httpStatus = servletResponse.getStatus();
|
||||
// if (httpStatus != 200) {
|
||||
// responseEntity = ResponseEntity.status(httpStatus).contentType(mediaType).body(responseData);
|
||||
// } else {
|
||||
// responseEntity = ResponseEntity.ok().contentType(mediaType).body(responseData);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
//
|
||||
//
|
||||
// logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
||||
//
|
||||
// String errorMsg = null;
|
||||
//
|
||||
// if( e instanceof HttpStatusException ) {
|
||||
// logger.warn("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage());
|
||||
// HttpStatusException e1 = (HttpStatusException) e;
|
||||
// errorMsg = MessageUtil.makeErrorMessageByMessageType(adptMsgType, encode,
|
||||
// MessageUtil.ERROR_CODE_AP_ERROR, e1.getMessage(), errorResponseFormat);
|
||||
// responseEntity = ResponseEntity.status(e1.getStatus()).contentType(mediaType).body(errorMsg);
|
||||
// }
|
||||
// else if( e instanceof JwtAuthException )
|
||||
// {
|
||||
// logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
||||
// errorMsg = MessageUtil.makeErrorMessageByMessageType(adptMsgType, encode,
|
||||
// MessageUtil.ERROR_CODE_AUTH_FAIL, e.getMessage(), errorResponseFormat);
|
||||
// responseEntity = ResponseEntity.status(HttpStatus.UNAUTHORIZED).contentType(mediaType).body(errorMsg);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
||||
// errorMsg = MessageUtil.makeErrorMessageByMessageType(adptMsgType, encode,
|
||||
// MessageUtil.ERROR_CODE_AP_ERROR, e.getMessage(), errorResponseFormat);
|
||||
// responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(mediaType)
|
||||
// .body(errorMsg);
|
||||
// }
|
||||
// String postFilterNames = httpProp.getProperty("POST_FILTERS","");
|
||||
//
|
||||
// if( postFilterNames.contains("HMAC_SHA256") ) {
|
||||
// HttpAdapterFilter filter = HttpAdapterFilterFactoryKjb.createFilter("HMAC_SHA256");
|
||||
// filter.doPostFilter(adapterGroupName, postFilterNames, errorMsg, transactionProp, servletRequest, servletResponse);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// } finally {
|
||||
// /**
|
||||
// * 로깅 인터셉터에 데이터를 전달하기 위한 처리 이미 거래처리가 끝나서 영향도가 없을만한 servletRequest에 Attribute로 전달
|
||||
// * 추후 더 좋은방법이 생길경우 개선 요망
|
||||
// */
|
||||
// try {
|
||||
//
|
||||
// servletRequest.setAttribute(TransactionContextKeys.TRANSACTION_PROP, transactionProp);
|
||||
//
|
||||
// if (!"ASYNC".equals(responseType)) {
|
||||
// String uuid = transactionProp.getProperty(TransactionContextKeys.TRANSACTION_UUID);
|
||||
// String url = transactionProp.getProperty(HttpClientAdapterServiceKey.INBOUND_EXTURI);
|
||||
// String method = transactionProp.getProperty(HttpClientAdapterServiceKey.INBOUND_METHOD);
|
||||
// int httpStatusCode = servletResponse.getStatus();
|
||||
//
|
||||
// Map<Object, Object> headerMap = new HashMap<>();
|
||||
// // 응답 헤더 로깅
|
||||
// for (String headerName : servletResponse.getHeaderNames()) {
|
||||
// String headerValue = servletResponse.getHeader(headerName);
|
||||
// logger.debug(String.format("httpHeader logging headerKey=%s, headerValue=%s",
|
||||
// headerName, headerValue));
|
||||
// headerMap.put(headerName, headerValue);
|
||||
// }
|
||||
// //HttpAdapterExtraLogUtil.insertHttpAdapterExtraLog(uuid, 400, adapterGroupName,adapterName, headerMap, url, method, httpStatusCode);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// logger.warn("http header db logging fail.", e);
|
||||
// }
|
||||
// }
|
||||
// return responseEntity;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * url에서 뒤쪽 /이후를 제거하면서 찾는다.<br>
|
||||
// * /api/v1/public/getUserInfo.svc
|
||||
// *
|
||||
// * @param apiUri
|
||||
// * @return
|
||||
// */
|
||||
// private HttpDynamicInAdapterUri findAdptUri(String apiUri, HttpDynamicInAdapterManager manager,
|
||||
// String adapterGrpName) throws Exception {
|
||||
// if (StringUtils.isBlank(apiUri)) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// // * manager 출력
|
||||
// logger.warn("===== adptUriMap 상세 내용 =====");
|
||||
// for (Map.Entry<String, HttpDynamicInAdapterUri> entry : manager.adptUriMap.entrySet()) {
|
||||
// HttpDynamicInAdapterUri uriObj = entry.getValue();
|
||||
// logger.warn("GroupName=" + uriObj.getAdptGrpName() + ", AdapterName=" + uriObj.getAdptName() + ", URI="
|
||||
// + uriObj.getUri());
|
||||
// }
|
||||
// logger.warn("================================");
|
||||
//
|
||||
// //
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// HttpDynamicInAdapterUri adptUri = manager.getAdptUri(apiUri);
|
||||
// if (adptUri != null) {
|
||||
// if (StringUtils.isNotEmpty(adapterGrpName)) {
|
||||
// if(adptUri.getAdptGrpName().equals(adapterGrpName)) {
|
||||
// return adptUri;
|
||||
// }
|
||||
// } else {
|
||||
// return adptUri;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // /api/v1/public
|
||||
// apiUri = StringUtils.substringBeforeLast(apiUri, "/");
|
||||
// if (apiUri.length() < 4) { // /api
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private void logError(HttpServletRequest request) {
|
||||
// InboundErrorInfoVO errorInfoVO = new InboundErrorInfoVO();
|
||||
//
|
||||
// EAIServerManager eaiServerManager = EAIServerManager.getInstance();
|
||||
// String serverName = eaiServerManager.getLocalServerName();
|
||||
// String uuid = null;
|
||||
// StringBuffer sb = new StringBuffer();
|
||||
//
|
||||
// String instanceid1 = serverName.substring(0, 2);
|
||||
// String instanceid2 = serverName.substring(serverName.length() - 2, serverName.length());
|
||||
// String instid = instanceid1 + instanceid2;
|
||||
// uuid = instid + UUIDGenerator.getUUID();
|
||||
//
|
||||
// String[] msgArgs = new String[1];
|
||||
// msgArgs[0] = request.getRequestURI();
|
||||
//
|
||||
// String errorCode = "RECEAIIRP010";
|
||||
// String errorMsg = ExceptionUtil.make(new Exception("cat not find uri"), errorCode, msgArgs);
|
||||
//
|
||||
// errorInfoVO.setEaiSvcSno(uuid); // EAI서비스일련번호
|
||||
// errorInfoVO.setAdptBwkGrpNm("HTTP_IN_NO_URI"); // 어댑터업무그룹명
|
||||
// errorInfoVO.setErrCd(errorCode); // 에러코드
|
||||
// errorInfoVO.setErrTxt(errorMsg); // 에러내용
|
||||
// errorInfoVO.setErrTm(DatetimeUtil.getCurrentTime(new Date().getTime())); // 에러발생시각
|
||||
// errorInfoVO.setErrDstcd(" ");
|
||||
// sb.append("Remote Addr : ").append(request.getRemoteAddr()).append("\n").append("Request URI : ")
|
||||
// .append(request.getRequestURI());
|
||||
// errorInfoVO.setBwkDataTxt(sb.toString()); // 업무데이터내용
|
||||
// errorInfoVO.setEaiSvrInstNm(serverName); // EAI서버인스턴스명
|
||||
//
|
||||
// InboundErrorLogger.error(errorInfoVO);
|
||||
// }
|
||||
//
|
||||
// private String makeResponseBodyMsg() {
|
||||
//
|
||||
// Map<String, Object> dataMap = new HashMap<>();
|
||||
// dataMap.put("result", 1);
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
//
|
||||
// map.put("code", "200");
|
||||
// map.put("data", dataMap);
|
||||
// map.put("message", "정상 처리 되었습니다.");
|
||||
//
|
||||
// JSONObject json = new JSONObject();
|
||||
// json.putAll(map);
|
||||
//
|
||||
// return json.toJSONString();
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// * private String makeResponseBodyMsg(String asyncMsgStyle) {
|
||||
// *
|
||||
// * Map<String, Object> dataMap = new HashMap<>(); dataMap.put("result", 1);
|
||||
// * Map<String, Object> map = new HashMap<>();
|
||||
// *
|
||||
// * switch (asyncMsgStyle) { case "TB_SUC": map.put("rspCode", "TB_SUC_000");
|
||||
// * map.put("rspMsg", "정상"); map.put("data", dataMap); break; case "ONLYDATA":
|
||||
// * map.put("data", dataMap); map.put("success", "true"); break; default:
|
||||
// * map.put("code", "200"); map.put("data", dataMap); map.put("message",
|
||||
// * "정상 처리 되었습니다."); break; }
|
||||
// *
|
||||
// * JSONObject json = new JSONObject(); json.putAll(map);
|
||||
// *
|
||||
// * return json.toJSONString(); }
|
||||
// */
|
||||
//}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.eactive.eai.adapter.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Controller
|
||||
public class TokenRedirectController {
|
||||
|
||||
@PostMapping("/sample/v1/oauth/token")
|
||||
public void redirectPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// 포워딩할 URL을 지정
|
||||
String targetUrl = "/api/v1/oauth/token";
|
||||
// 요청과 응답을 다른 URL로 포워딩
|
||||
request.getRequestDispatcher(targetUrl).forward(request, response);
|
||||
}
|
||||
}
|
||||
@@ -1,847 +0,0 @@
|
||||
package com.eactive.eai.adapter.service;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
import com.eactive.eai.adapter.AdapterPropManager;
|
||||
import com.eactive.eai.adapter.AdapterVO;
|
||||
import com.eactive.eai.adapter.Keys;
|
||||
import com.eactive.eai.adapter.http.HttpMemoryLogger;
|
||||
import com.eactive.eai.adapter.http.HttpMethodType;
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceSupport;
|
||||
import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthFilter;
|
||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
import com.eactive.eai.common.message.MessageType;
|
||||
import com.eactive.eai.common.util.CommonLib;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.inbound.action.ActionFactory;
|
||||
import com.eactive.eai.inbound.action.RequestAction;
|
||||
import com.eactive.eai.inbound.processor.Processor;
|
||||
import com.eactive.eai.message.StandardMessageUtil;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
import org.apache.mina.common.ByteBuffer;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
|
||||
//for encrypt/decrypt jwhong
|
||||
import com.eactive.eai.authserver.service.OAuth2Manager;
|
||||
import com.kjbank.encrypt.exchange.crypto.AES256Cipher;
|
||||
import com.kjbank.encrypt.exchange.crypto.AESCipher;
|
||||
import com.kjbank.encrypt.exchange.crypto.AES256GCMCipher;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import org.springframework.security.oauth2.provider.ClientDetails;
|
||||
import com.nimbusds.jwt.SignedJWT;
|
||||
import com.eactive.eai.common.context.ElinkTransactionContext;
|
||||
|
||||
|
||||
@Service
|
||||
public class ApiAdapterService extends HttpAdapterServiceSupport {
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
|
||||
|
||||
public static final String HEADER_GROUP = "HEADER_GROUP";
|
||||
public static final String HTTP_STATUS = "HTTP_STATUS"; // jwhong
|
||||
// HEADER_GROUP JSON에 추가할 항목 정의, 없으면 전체 header 추가
|
||||
public static final String HEADER_KEYS = "HEADER_KEYS";
|
||||
public static final String PROPERTIES_NAME_HTTP_REQUEST_METHOD = "httpRequestMethod";
|
||||
|
||||
private static final String JSON_CONTENT_TYPE = "application/json";
|
||||
private static final String JSON_FIELD_NAME = "json-body";
|
||||
private static final String FILE_GROUP_NAME = "image-file";
|
||||
private static final String UPLOAD_ROOT_PATH = "UPLOAD_ROOT_PATH";
|
||||
public static final String PAYLOAD_PARAM_NAME_CLIENT_ID = "client_id"; // jwhong
|
||||
private boolean encryptResponseApply; // inbound에 대한 응답 암호화 여부 flag
|
||||
|
||||
public String callApi(HttpServletRequest request, HttpServletResponse response, Properties httpProp, AdapterGroupVO adapterGroupVO, AdapterVO adapterVO, Properties transactionProp) throws Exception {
|
||||
int traceLevel = 0;
|
||||
|
||||
AdapterPropManager manager = null;
|
||||
String adptGrpName = adapterGroupVO.getName();
|
||||
String adptName = adapterVO.getName();
|
||||
|
||||
String urlDecodeYn = httpProp.getProperty(URL_DECODE_YN, "N");
|
||||
String encode = StringUtils.defaultIfBlank(adapterGroupVO.getMessageEncode(), "UTF-8");
|
||||
|
||||
String traceLevelTemp = httpProp.getProperty(TRACE_LEVEL, "0");
|
||||
String relayRequestHeaderKeys = httpProp.getProperty(HEADER_KEYS);
|
||||
String headerGroupName = httpProp.getProperty(HEADER_GROUP);
|
||||
|
||||
boolean isParameterType = false;
|
||||
String message = null;
|
||||
|
||||
String paramValue = null;
|
||||
String adptMsgType = null;
|
||||
|
||||
transactionProp.put(INBOUND_METHOD, request.getMethod());
|
||||
transactionProp.put(INBOUND_URI, request.getRequestURI());
|
||||
transactionProp.put(INBOUND_HEADER, getHeaders(request));
|
||||
transactionProp.put(INBOUND_EXTPARAMS, StringUtils.defaultString(request.getQueryString()));
|
||||
if (StringUtils.equals(adapterVO.getAdapterGroupVO().getType(), Keys.TYPE_REST)
|
||||
|| StringUtils.equals(adapterVO.getAdapterGroupVO().getType(), Keys.TYPE_HTTP_CUSTOM)) {
|
||||
// /api/v1/public/getUserInfo.svc
|
||||
String extUrl = StringUtils.removeStart(request.getRequestURI(), request.getContextPath());
|
||||
transactionProp.put(INBOUND_EXTURI, extUrl);
|
||||
} else {
|
||||
transactionProp.put(INBOUND_EXTURI, getExtUri(request));
|
||||
}
|
||||
transactionProp.put(INBOUND_CLIENT_IP, getClientIp(request)); // Client IP 추가
|
||||
transactionProp.put(Processor.REQUEST_ACTION, adapterVO.getAdapterGroupVO().getRefClass());
|
||||
transactionProp.put(API_PATH, httpProp.getProperty(API_PATH, ""));
|
||||
transactionProp.put(PRE_FILTERS, httpProp.getProperty(PRE_FILTERS, ""));
|
||||
transactionProp.put(POST_FILTERS, httpProp.getProperty(POST_FILTERS, ""));
|
||||
transactionProp.put(PROPERTIES_NAME_HTTP_REQUEST_METHOD, request.getMethod());
|
||||
transactionProp.put(ALLOW_IP, httpProp.getProperty(ALLOW_IP, ""));
|
||||
transactionProp.put("BLOCK_IP", httpProp.getProperty("BLOCK_IP", ""));
|
||||
|
||||
transactionProp.put(ENC_PATHS, httpProp.getProperty(ENC_PATHS, ""));
|
||||
|
||||
transactionProp.put(ENCRYPT_ALGORITHM, httpProp.getProperty(ENCRYPT_ALGORITHM, "")); //jwhong
|
||||
if (getHeaders(request).get(HEADER_NAME_CLIENT_ID) != null) { // jwhong
|
||||
transactionProp.put(HEADER_NAME_CLIENT_ID, getHeaders(request).get(HEADER_NAME_CLIENT_ID));
|
||||
}
|
||||
transactionProp.put(ENCRYPT_BASE_TYPE, httpProp.getProperty(ENCRYPT_BASE_TYPE, "")); //jwhong
|
||||
// //transactionProp.put(INBOUND_TOKEN, getHeaders(request).get(INBOUND_TOKEN)); // jwhong
|
||||
// transactionProp.put(INBOUND_TOKEN, getHeaders(request).get(INBOUND_TOKEN) != null ? getHeaders(request).get(INBOUND_TOKEN) : ""); //jwhong , null 이면 default로 "" put
|
||||
String inboundToken = getHeaders(request).getOrDefault(INBOUND_TOKEN, "").toString();
|
||||
if (StringUtils.isNotBlank(inboundToken) && StringUtils.startsWith(inboundToken, "Bearer ")) {
|
||||
inboundToken = inboundToken.substring(7);
|
||||
}
|
||||
transactionProp.put(INBOUND_TOKEN, inboundToken);
|
||||
transactionProp.put(ENCRYPT_AES256_IV, httpProp.getProperty(ENCRYPT_AES256_IV, "")); //jwhong
|
||||
transactionProp.put(ENCRYPT_AES256_KEY, httpProp.getProperty(ENCRYPT_AES256_KEY, "")); //jwhong
|
||||
|
||||
// SEED 컬럼암호하 시 Key로 사용함
|
||||
String seedkey = getHeaders(request).getOrDefault("x-obp-partnercode", "").toString();
|
||||
ElinkTransactionContext.setSeedKey(seedkey);
|
||||
|
||||
try {
|
||||
traceLevel = Integer.parseInt(traceLevelTemp);
|
||||
} catch (Exception e) {
|
||||
traceLevel = 0;
|
||||
}
|
||||
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
logger.debug("시작 >> encode = [" + encode + "]");
|
||||
|
||||
switch (HttpMethodType.getValue(request.getMethod())) {
|
||||
case GET:
|
||||
case DELETE:
|
||||
isParameterType = true;
|
||||
break;
|
||||
case POST:
|
||||
case PUT:
|
||||
if (StringUtils.contains(request.getContentType(), "application/x-www-form-urlencoded")) {
|
||||
isParameterType = true;
|
||||
} else if ( StringUtils.isNoneBlank(request.getQueryString()) ) { // jwhong
|
||||
isParameterType = true;
|
||||
} else {
|
||||
isParameterType = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (isParameterType) {
|
||||
paramValue = request.getQueryString();
|
||||
transactionProp.put(INBOUND_QUERY_STRING, StringUtils.defaultString(paramValue)); // Filter에서 QueryString 검증을 위해 저장
|
||||
if (paramValue == null)
|
||||
paramValue = "";
|
||||
if (traceLevel >= 3) {
|
||||
HttpMemoryLogger.txlog(adptGrpName + adptName,
|
||||
"RECV " + "[" + paramValue + "]" + CommonLib.getDumpMessage(paramValue));
|
||||
}
|
||||
|
||||
// json으로 변환
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("{");
|
||||
Map<String, String[]> paramMap = assignParameterMap(request, adptGrpName, adptName, null, transactionProp);
|
||||
int i = 0;
|
||||
for (Map.Entry<String, String[]> entry : paramMap.entrySet()) {
|
||||
if (i > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("\"").append(entry.getKey()).append("\":");
|
||||
String[] values = entry.getValue();
|
||||
if (values.length > 1) {
|
||||
// ["111", "222"]
|
||||
sb.append("[");
|
||||
for (int j = 0; j < values.length; j++) {
|
||||
if (j > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append("\"").append(JSONValue.escape(values[j])).append("\"");
|
||||
}
|
||||
sb.append("]");
|
||||
} else {
|
||||
sb.append("\"").append(JSONValue.escape(values[0])).append("\"");
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
sb.append("}");
|
||||
|
||||
paramValue = sb.toString();
|
||||
|
||||
if (logger.isDebug()) {
|
||||
logger.debug("HttpAdapterServiceRest] RECV (" + adptGrpName + ") = [" + paramValue + "]\n"
|
||||
+ CommonLib.getDumpMessage(paramValue.getBytes(encode)));
|
||||
}
|
||||
} else {
|
||||
if (request.getContentLength() > 0) {
|
||||
ServletInputStream sis = request.getInputStream();
|
||||
ByteBuffer bb = ByteBuffer.allocate(1024).setAutoExpand(true);
|
||||
int i = 0;
|
||||
byte[] cbuf = new byte[1024];
|
||||
while ((i = sis.read(cbuf, 0, 1024)) != -1) {
|
||||
if (i == 1024) {
|
||||
bb.put(cbuf);
|
||||
} else {
|
||||
byte[] tail = new byte[i];
|
||||
System.arraycopy(cbuf, 0, tail, 0, i);
|
||||
bb.put(tail);
|
||||
}
|
||||
}
|
||||
byte[] data = new byte[bb.position()];
|
||||
bb.position(0);
|
||||
bb.get(data);
|
||||
paramValue = new String(data, encode);
|
||||
|
||||
if (traceLevel >= 3) {
|
||||
HttpMemoryLogger.txlog(adptGrpName + adptName,
|
||||
"RECV " + "[" + paramValue + "]" + CommonLib.getDumpMessage(data));
|
||||
}
|
||||
|
||||
if (logger.isDebug()) {
|
||||
logger.debug("HttpAdapterServiceRest] RECV (" + adptGrpName + ") = [" + paramValue + "]\n"
|
||||
+ CommonLib.getDumpMessage(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (paramValue == null) { // parameter가 없는 경우때문에 처리
|
||||
paramValue = "";
|
||||
}
|
||||
// 순수한 Body값을 저장을 위해 위치 변경.
|
||||
transactionProp.put(INBOUND_REQUEST_MESSAGE, paramValue);
|
||||
|
||||
// paramValue가 null이 아닌 빈문자열(""," ")인 경우에 대비하여 조건 수정.
|
||||
if (StringUtils.isNotBlank(paramValue)) { // jwhong decrypt
|
||||
paramValue = doPreDecryption(paramValue, transactionProp, request);
|
||||
}
|
||||
|
||||
if ("Y".equals(urlDecodeYn) && isParameterType) {
|
||||
message = URLDecoder.decode(paramValue);
|
||||
} else {
|
||||
message = paramValue;
|
||||
}
|
||||
|
||||
if (logger.isDebug()) {
|
||||
String[] msgArgs = new String[2];
|
||||
msgArgs[0] = adptGrpName;
|
||||
msgArgs[1] = message;
|
||||
String resMsg = ExceptionUtil.make("RICEAIAHA005", msgArgs);
|
||||
logger.debug(resMsg);
|
||||
}
|
||||
|
||||
|
||||
adptMsgType = adapterVO.getAdapterGroupVO().getMessageType();
|
||||
// HttpHeaders responseHeaders = new HttpHeaders();
|
||||
// responseHeaders.setContentType(MediaType.valueOf("application/json;charset=" + encode));
|
||||
|
||||
|
||||
// HEADER_GROUP 셋팅
|
||||
if (MessageType.JSON.equals(adptMsgType) && StringUtils.isNotBlank(headerGroupName)
|
||||
&& StringUtils.isNotBlank(relayRequestHeaderKeys)) {
|
||||
JSONObject jsonMessage = (JSONObject) JSONValue.parse(message);
|
||||
JSONObject headerJson = new JSONObject();
|
||||
if (StringUtils.equalsIgnoreCase(relayRequestHeaderKeys, "ALL")) {
|
||||
for (Enumeration<String> e = request.getHeaderNames(); e.hasMoreElements(); ) {
|
||||
String key = e.nextElement();
|
||||
headerJson.put(key, request.getHeader(key));
|
||||
}
|
||||
} else {
|
||||
String[] relayKeyArr = org.springframework.util.StringUtils
|
||||
.tokenizeToStringArray(relayRequestHeaderKeys, ",");
|
||||
|
||||
for (String key : relayKeyArr) {
|
||||
String headerValue = request.getHeader(key);
|
||||
if (StringUtils.isNotBlank(headerValue)) {
|
||||
headerJson.put(key, headerValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (headerJson.size() > 0) {
|
||||
jsonMessage.put(headerGroupName, headerJson);
|
||||
message = jsonMessage.toJSONString();
|
||||
}
|
||||
}
|
||||
|
||||
if (message == null) {
|
||||
message = "";
|
||||
}
|
||||
|
||||
// 위치변경 : 가공되지 않은 Body값을 저장하기 위하여 위쪽으로 이동.
|
||||
// transactionProp.put(INBOUND_REQUEST_MESSAGE, message);
|
||||
// 로컬 서비스 호출 ,encoding 처리 추가
|
||||
String result = (String) service(adptGrpName, adptName, message, transactionProp, request, response);
|
||||
|
||||
if (logger.isDebug()) {
|
||||
logger.debug("HttpAdapterServiceRest] result " + encode + " (" + adptGrpName + ") = [" + result + "]");
|
||||
}
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
String syncAsyncType = transactionProp.getProperty(INBOUND_SYNC_ASYNC_TYPE);
|
||||
|
||||
if (!"ASYN".equals(syncAsyncType) && MessageType.JSON.equals(adptMsgType) && StringUtils.isNotBlank(headerGroupName)) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ObjectNode rootNode = (ObjectNode) mapper.readTree(result);
|
||||
JsonNode headerGroup = rootNode.get(headerGroupName);
|
||||
if(headerGroup != null) {
|
||||
for(Iterator<String> it = headerGroup.fieldNames(); it.hasNext();) {
|
||||
String name = it.next();
|
||||
String value = headerGroup.get(name).asText();
|
||||
response.addHeader(name, value);
|
||||
}
|
||||
rootNode.remove(headerGroupName);
|
||||
result = mapper.writeValueAsString(rootNode);
|
||||
}
|
||||
}
|
||||
|
||||
// KJBank는 요청에 대한 응답 (Sync응답, Aync 에 대한 Ack응답) 에 대하여 암호화 하지 않는다. 무조건 안한다. 따라서 아래부분은 구현은 했지만 사용하지 않는다.
|
||||
// 위 2가지 경우 암호화 하는걸로 요청 변경되어 아래 암호화 수행하도록 수정함
|
||||
encryptResponseApply = StringUtils.equalsIgnoreCase(httpProp.getProperty("ENCRYPT_RESPONSE_APPLY", "N"), "Y");
|
||||
if ( encryptResponseApply) {
|
||||
result = doPostEncryption(result, transactionProp, request); // jwhong Encrypt
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// jwhong decrypt
|
||||
|
||||
private String doPreDecryption(String eaiBody, Properties transactionProp, HttpServletRequest request) throws Exception {
|
||||
String decryptAlgorithm = transactionProp.getProperty(ENCRYPT_ALGORITHM, "");
|
||||
String xElinkClientId = transactionProp.getProperty(HEADER_NAME_CLIENT_ID, ""); // 이 값이 OAuth의 client id 값이다 . http header 에 포함되어 온다. jwhong
|
||||
String encryptBaseKeyType = transactionProp.getProperty(ENCRYPT_BASE_TYPE);
|
||||
//String inboundToken2 = transactionProp.getProperty(INBOUND_TOKEN, ""); // 이건 token 값이 아니고 authorization 값이다
|
||||
String inboundToken = "";
|
||||
|
||||
String secretAES256Iv = transactionProp.getProperty("ENCRYPT_AES256_IV");
|
||||
String secretAES256Key = transactionProp.getProperty("ENCRYPT_AES256_KEY");
|
||||
|
||||
if ( decryptAlgorithm == "" ) { // 복호화 대상이 아님
|
||||
return eaiBody;
|
||||
}
|
||||
|
||||
inboundToken = JwtTokenExtractor(request);
|
||||
xElinkClientId = JwtClientIdExtractor(inboundToken); // token에서 client id를 추출함
|
||||
|
||||
// 암호화 key를 token 내용으로 할지 client secret 내용으로 할지 결정함. adapter property에 정의함
|
||||
// ENCRYPT_ALGORITHM 을 설정했는데 ENCRYPT_BASE_TYPE을 설정안하면 Decrypt 수행시 Exception 발생함
|
||||
String clientSecret = "";
|
||||
if ("TOKEN".equalsIgnoreCase(encryptBaseKeyType)) {
|
||||
clientSecret = inboundToken;
|
||||
} else if ( "SECRETKEY".equalsIgnoreCase(encryptBaseKeyType)) {
|
||||
OAuth2Manager manager = OAuth2Manager.getInstance();
|
||||
ClientDetails clientDetail = manager.getClientDeatilsStore().get(xElinkClientId);
|
||||
|
||||
if ( clientDetail != null ) { // 여기서 not null 이라는 것은 apim oauth server에서 발급된 token 임.
|
||||
// 즉 KJBank 에서 요청이 들어온 것이다.
|
||||
clientSecret = clientDetail.getClientSecret();
|
||||
} // 그럼 업체에서 요청이 들어오면?? 업체도 apim oauth server에서 발급된 token을 사용하는것이다.
|
||||
}
|
||||
|
||||
byte[] decryptedMessage = null;
|
||||
decryptedMessage = doInboundPreDecrypt(eaiBody, decryptAlgorithm,clientSecret,secretAES256Iv, secretAES256Key );
|
||||
|
||||
if (decryptedMessage == null) {
|
||||
throw new Exception("[ApiAdapterService] Decrypt Error : Invalid encrypted message");
|
||||
}
|
||||
|
||||
|
||||
String resultMessage = new String(decryptedMessage, StandardCharsets.UTF_8 );
|
||||
return resultMessage;
|
||||
//return new String(decryptedMessage, StandardCharsets.UTF_8 );
|
||||
}
|
||||
|
||||
|
||||
// jwhong encrypt
|
||||
public String doPostEncryption(String eaiBody, Properties transactionProp, HttpServletRequest request) throws Exception {
|
||||
|
||||
String decryptAlgorithm = transactionProp.getProperty(ENCRYPT_ALGORITHM, "");
|
||||
String xElinkClientId = transactionProp.getProperty(HEADER_NAME_CLIENT_ID, ""); // 이 값이 OAuth의 client id 값이다 . http header 에 포함되어 온다. jwhong
|
||||
String encryptBaseKeyType = transactionProp.getProperty(ENCRYPT_BASE_TYPE);
|
||||
String inboundToken = "";
|
||||
|
||||
String secretAES256Iv = transactionProp.getProperty("ENCRYPT_AES256_IV");
|
||||
String secretAES256Key = transactionProp.getProperty("ENCRYPT_AES256_KEY");
|
||||
|
||||
if ( decryptAlgorithm == "" ) { // 복호화 대상이 아님
|
||||
return eaiBody;
|
||||
}
|
||||
|
||||
inboundToken = JwtTokenExtractor(request);
|
||||
xElinkClientId = JwtClientIdExtractor(inboundToken); // token에서 client id를 추출함
|
||||
|
||||
// 암호화 key를 token 내용으로 할지 client secret 내용으로 할지 결정함. adapter property에 정의함
|
||||
// ENCRYPT_ALGORITHM 을 설정했는데 ENCRYPT_BASE_TYPE을 설정안하면 Decrypt 수행시 Exception 발생함
|
||||
String clientSecret = "";
|
||||
if ("TOKEN".equalsIgnoreCase(encryptBaseKeyType)) {
|
||||
clientSecret = inboundToken;
|
||||
} else if ( "SECRETKEY".equalsIgnoreCase(encryptBaseKeyType)) {
|
||||
OAuth2Manager manager = OAuth2Manager.getInstance();
|
||||
ClientDetails clientDetail = manager.getClientDeatilsStore().get(xElinkClientId);
|
||||
|
||||
if ( clientDetail != null ) {
|
||||
clientSecret = clientDetail.getClientSecret();
|
||||
}
|
||||
}
|
||||
|
||||
String encryptedMessage = null;
|
||||
encryptedMessage = doInboundPostEncrypt(eaiBody, decryptAlgorithm,clientSecret,secretAES256Iv, secretAES256Key );
|
||||
|
||||
if (encryptedMessage == null) {
|
||||
throw new Exception("[ApiAdapterService] Encrypt Error : Invalid PlainText message");
|
||||
}
|
||||
|
||||
return encryptedMessage;
|
||||
//String resultMessage = new String(encryptedMessage, StandardCharsets.UTF_8 );
|
||||
//return resultMessage;
|
||||
}
|
||||
|
||||
|
||||
private byte[] convertObjectToBytes(Object obj) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
oos.writeObject(obj);
|
||||
oos.flush();
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
private byte[] convertObjectToBase64Bytes(Object obj) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bos);
|
||||
oos.writeObject(obj);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
|
||||
// 직렬화된 byte[] → Base64 문자열 → 다시 byte[]로 변환
|
||||
String base64String = Base64.getEncoder().encodeToString(bos.toByteArray());
|
||||
return base64String.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static Object convertBytesToObject(byte[] bytes) throws IOException, ClassNotFoundException {
|
||||
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
|
||||
ObjectInputStream ois = new ObjectInputStream(bis)) {
|
||||
return ois.readObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private byte[] doInboundPreDecrypt(String eaiStringBody, String decryptAlgorithm, String clientSecretKey, String secretAES256Iv, String secretAES256Key) throws Exception {
|
||||
|
||||
byte[] decryptedMessage = null;
|
||||
//String eaiStringBody = new String(eaiBody, StandardCharsets.UTF_8);
|
||||
|
||||
eaiStringBody = extractBodyMsg(decryptAlgorithm, eaiStringBody);
|
||||
|
||||
if (eaiStringBody == null) {
|
||||
throw new Exception("[ApiAdapterService] Cannot decrypt Error : input is plain text");
|
||||
}
|
||||
|
||||
//test source
|
||||
logger.debug("Base64 문자열: " + eaiStringBody);
|
||||
logger.debug("Base64 문자열 길이: " + eaiStringBody.length());
|
||||
logger.debug("Base64 문자열 끝: " + eaiStringBody.substring(eaiStringBody.length() - 10));
|
||||
|
||||
// Base64 디코딩 테스트
|
||||
try {
|
||||
byte[] decoded = Base64.getDecoder().decode(eaiStringBody);
|
||||
logger.debug("디코딩 성공, 길이: " + decoded.length);
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.debug("Base64 디코딩 실패: " + e.getMessage());
|
||||
}
|
||||
// end test source
|
||||
|
||||
switch (decryptAlgorithm) {
|
||||
case "AES128":
|
||||
case "AES128-TOSS":
|
||||
try {
|
||||
String key128 = clientSecretKey.substring(22,38); //togetherEncoder 경우는 substring(44,60) 이네??
|
||||
//String decryptedStrMessage = AESCipher.decrypt(eaiStringBody, key128);
|
||||
String decryptedStrMessage = AESCipher.decryptExistException(eaiStringBody, key128);
|
||||
decryptedMessage = decryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES128 Decryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "AES128-TOGETHER":
|
||||
try {
|
||||
String key128 = clientSecretKey.substring(44,60); //togetherEncoder 경우는 substring(44,60) 이네??
|
||||
//String decryptedStrMessage = AESCipher.decrypt(eaiStringBody, key128);
|
||||
String decryptedStrMessage = AESCipher.decryptExistException(eaiStringBody, key128);
|
||||
decryptedMessage = decryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES128 Decryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "AES256":
|
||||
try {
|
||||
String key = clientSecretKey.substring(10,42);
|
||||
String decryptedStrMessage = AES256Cipher.decrypt(eaiStringBody, key);
|
||||
decryptedMessage = decryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES256 Decryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "AES256-KAKAO":
|
||||
try {
|
||||
String decryptedStrMessage = AES256Cipher.decrypt(eaiStringBody, secretAES256Iv, secretAES256Key);
|
||||
decryptedMessage = decryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES256 Decryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "AES256-TOSS":
|
||||
try {
|
||||
String decryptedStrMessage = AES256Cipher.decrypt(eaiStringBody, secretAES256Iv, secretAES256Key);
|
||||
decryptedMessage = decryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES256 Decryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
|
||||
case "AES256GCM":
|
||||
try {
|
||||
byte[] key = AES256GCMCipher.generateKey();
|
||||
AES256GCMCipher cipher = new AES256GCMCipher(key);
|
||||
byte[] aad = "metadata".getBytes();
|
||||
|
||||
String decryptedStrMessage = cipher.decrypt(eaiStringBody , aad);
|
||||
decryptedMessage = decryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES256GCM Encryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
decryptedMessage = eaiStringBody.getBytes();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] doOutboundPostFilter Array copy error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return decryptedMessage;
|
||||
}
|
||||
|
||||
private String extractBodyMsg(String decryptAlgorithm, String eaiStringBody) {
|
||||
|
||||
String decryptedJsonKey = "";
|
||||
String decryptedBodyMessage = "";
|
||||
|
||||
decryptedJsonKey = getJsonKey(decryptAlgorithm);
|
||||
|
||||
try {
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject jsonObject = (JSONObject) parser.parse(eaiStringBody);
|
||||
decryptedBodyMessage = (String) jsonObject.get(decryptedJsonKey);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClient5AdapterServiceRest] extractBodyMsg error : " + e.getMessage());
|
||||
}
|
||||
|
||||
return decryptedBodyMessage;
|
||||
|
||||
}
|
||||
|
||||
private String getJsonKey(String Algorithm) {
|
||||
|
||||
String jsonKey = "";
|
||||
|
||||
switch (Algorithm) {
|
||||
case "AES128":
|
||||
case "AES128-TOSS":
|
||||
jsonKey = "preScreeningRequest";
|
||||
break;
|
||||
case "AES128-TOGETHER":
|
||||
jsonKey = "obpTxData";
|
||||
break;
|
||||
case "AES256":
|
||||
jsonKey = "preScreeningRequest";
|
||||
break;
|
||||
case "AES256-KAKAO":
|
||||
jsonKey = "encrypted_data";
|
||||
break;
|
||||
case "AES256-TOSS":
|
||||
jsonKey = "encryptedData";
|
||||
break;
|
||||
case "AES256-NICEON":
|
||||
jsonKey = "enc_data";
|
||||
break;
|
||||
case "AES256GCM":
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return jsonKey;
|
||||
}
|
||||
|
||||
private String doInboundPostEncrypt(String eaiStringBody, String encryptAlgorithm, String clientSecretKey, String secretAES256Iv, String secretAES256Key) {
|
||||
|
||||
//byte[] encryptedMessage = null;
|
||||
String encryptedStrMessage = null;
|
||||
String encryptedJsonKey = "";
|
||||
|
||||
encryptedJsonKey = getJsonKey(encryptAlgorithm);
|
||||
|
||||
switch (encryptAlgorithm) {
|
||||
case "AES128":
|
||||
case "AES128-TOSS":
|
||||
try {
|
||||
String key128 = clientSecretKey.substring(22,38); //togetherEncoder 경우는 substring(44,60) 이네??
|
||||
encryptedStrMessage = AESCipher.encrypt(eaiStringBody, key128);
|
||||
//encryptedMessage = encryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES128 Encryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "AES128-TOGETHER":
|
||||
try {
|
||||
String key128 = clientSecretKey.substring(44,60); //togetherEncoder 경우는 substring(44,60) 이네??
|
||||
encryptedStrMessage = AESCipher.encrypt(eaiStringBody, key128);
|
||||
//encryptedMessage = encryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES128 Encryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "AES256":
|
||||
try {
|
||||
String key = clientSecretKey.substring(10,42);
|
||||
encryptedStrMessage = AES256Cipher.encrypt(eaiStringBody, key);
|
||||
//encryptedMessage = encryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES256 Encryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "AES256-KAKAO":
|
||||
try {
|
||||
encryptedStrMessage = AES256Cipher.encrypt(eaiStringBody, secretAES256Iv, secretAES256Key);
|
||||
//encryptedMessage = encryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES256 Encryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
case "AES256-TOSS":
|
||||
try {
|
||||
encryptedStrMessage = AES256Cipher.encrypt(eaiStringBody, secretAES256Iv, secretAES256Key);
|
||||
//encryptedMessage = encryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES256 Encryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
|
||||
case "AES256GCM":
|
||||
try {
|
||||
byte[] key = AES256GCMCipher.generateKey();
|
||||
AES256GCMCipher cipher = new AES256GCMCipher(key);
|
||||
byte[] aad = "metadata".getBytes();
|
||||
|
||||
encryptedStrMessage = cipher.encrypt(eaiStringBody , aad);
|
||||
//encryptedMessage = encryptedStrMessage.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] AES256GCM Encryption error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
try {
|
||||
encryptedStrMessage = eaiStringBody;
|
||||
//encryptedMessage = eaiStringBody.getBytes();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("HttpClientAdapterServiceRest] doOutboundPostFilter Array copy error=" + e.getMessage());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put(encryptedJsonKey, encryptedStrMessage);
|
||||
JSONObject json = new JSONObject();
|
||||
json.putAll(map);
|
||||
return json.toJSONString();
|
||||
//return encryptedMessage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String JwtTokenExtractor(HttpServletRequest request) {
|
||||
|
||||
String Token = "";
|
||||
try {
|
||||
Token = JwtAuthFilter.extractJWTToken(request);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
|
||||
logger.debug("Token is: " + Token);
|
||||
return Token;
|
||||
|
||||
}
|
||||
|
||||
private String JwtClientIdExtractor(String inboundToken) {
|
||||
|
||||
String tokenClientId ="";
|
||||
try {
|
||||
SignedJWT signedJWT = SignedJWT.parse(inboundToken);
|
||||
tokenClientId = (String) signedJWT.getJWTClaimsSet().getClaim(PAYLOAD_PARAM_NAME_CLIENT_ID);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
tokenClientId = "";
|
||||
}
|
||||
|
||||
logger.debug("Token Client ID: " + tokenClientId);
|
||||
return tokenClientId;
|
||||
|
||||
}
|
||||
|
||||
// jwhong until here
|
||||
|
||||
|
||||
private Map<String, String[]> assignParameterMap(HttpServletRequest request, String adptGrpName, String adptName,
|
||||
Object requestBytes, Properties prop) {
|
||||
// PathVariable 체크
|
||||
if (StringUtils.equalsAnyIgnoreCase(request.getMethod(), HttpMethod.GET.name(), HttpMethod.DELETE.name())
|
||||
&& StringUtils.isBlank(request.getQueryString())) {
|
||||
try {
|
||||
String actionName = prop.getProperty(Processor.REQUEST_ACTION);
|
||||
RequestAction action = ActionFactory.createAction(actionName);
|
||||
action.setAdapterInfo(adptGrpName, adptName, prop);
|
||||
String[] keys = action.perform(requestBytes);
|
||||
String requestPath = keys[0];
|
||||
|
||||
// PathVariable 지원 추가
|
||||
String ruledPath = StandardMessageUtil.getMatchedKey(requestPath, actionName);
|
||||
if (!StringUtils.equals(requestPath, ruledPath) && StringUtils.contains(ruledPath, "{")) {
|
||||
Map<String, String> paramMap = new AntPathMatcher().extractUriTemplateVariables(ruledPath,
|
||||
requestPath);
|
||||
if (paramMap != null && paramMap.size() > 0) {
|
||||
Map<String, String[]> returnMap = new HashMap<>();
|
||||
for (String key : paramMap.keySet()) {
|
||||
if (StringUtils.equalsIgnoreCase(key, "method")) {
|
||||
continue;
|
||||
}
|
||||
returnMap.put(key, new String[] { paramMap.get(key) });
|
||||
}
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return request.getParameterMap();
|
||||
}
|
||||
|
||||
private Properties getHeaders(HttpServletRequest request) {
|
||||
Properties prop = new Properties();
|
||||
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
while (headerNames.hasMoreElements()) {
|
||||
String key = headerNames.nextElement();
|
||||
String value = request.getHeader(key);
|
||||
prop.setProperty(key, value);
|
||||
}
|
||||
|
||||
return prop;
|
||||
}
|
||||
|
||||
private String getExtUri(HttpServletRequest request) {
|
||||
String orgUri = request.getRequestURI().replaceAll(request.getContextPath(), "");
|
||||
String uri = getExtUri(orgUri, 3);
|
||||
if (uri != null && uri.trim().length() > 0) {
|
||||
return "/" + uri;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getExtUri(String url, int length) {
|
||||
String[] urls = url.split("/");
|
||||
List<String> newUrls = new ArrayList<>();
|
||||
Collections.addAll(newUrls, urls);
|
||||
return StringUtils.join(newUrls.subList(length, urls.length).toArray(), "/");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void service(String adptGrpName, String adptName, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP 요청에서 클라이언트 IP를 추출합니다.
|
||||
* X-Forwarded-For 헤더가 있는 경우 이를 우선적으로 사용하고,
|
||||
* 없는 경우 remoteAddr을 사용합니다.
|
||||
*/
|
||||
private String getClientIp(HttpServletRequest request) {
|
||||
String ipAddress = request.getHeader("X-Forwarded-For");
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
|
||||
ipAddress = request.getRemoteAddr();
|
||||
}
|
||||
return ipAddress;
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
package com.eactive.eai.custom.transformer.message;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.eactive.eai.transformer.message.ISO8583Message;
|
||||
import com.solab.iso8583.IsoMessage;
|
||||
import com.solab.iso8583.IsoType;
|
||||
import com.solab.iso8583.MessageFactory;
|
||||
import com.solab.iso8583.parse.FieldParseInfo;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* ISO 8583 H2H(전문) 형식의 데이터를 변환하기 위한 메시지.(For KB Bukopin)
|
||||
*
|
||||
* [참조]
|
||||
* https://en.wikipedia.org/wiki/ISO_8583
|
||||
* </pre>
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ISO8583H2HMessage extends ISO8583Message {
|
||||
private static HashMap<Integer, FieldParseInfo> fullSpecMap = null;
|
||||
private static HashMap<Integer, String> fullFieldNameMap = null;
|
||||
|
||||
@Override
|
||||
public MessageFactory<IsoMessage> createMessageFactory() {
|
||||
MessageFactory<IsoMessage> mf = new MessageFactory<>();
|
||||
mf.setCharacterEncoding(System.getProperty("file.encoding"));
|
||||
mf.setForceStringEncoding(false);
|
||||
return mf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Integer, FieldParseInfo> getFullSpecMap(String encode) {
|
||||
if (fullSpecMap != null) {
|
||||
return fullSpecMap;
|
||||
}
|
||||
|
||||
fullSpecMap = new HashMap<>();
|
||||
|
||||
fullSpecMap.put(2, FieldParseInfo.getInstance(IsoType.LLVAR, 19, encode));
|
||||
fullSpecMap.put(3, FieldParseInfo.getInstance(IsoType.NUMERIC, 6, encode));
|
||||
fullSpecMap.put(4, FieldParseInfo.getInstance(IsoType.NUMERIC, 12, encode));
|
||||
fullSpecMap.put(6, FieldParseInfo.getInstance(IsoType.NUMERIC, 12, encode));
|
||||
fullSpecMap.put(7, FieldParseInfo.getInstance(IsoType.DATE10, 10, encode));
|
||||
fullSpecMap.put(11, FieldParseInfo.getInstance(IsoType.NUMERIC, 6, encode));
|
||||
fullSpecMap.put(12, FieldParseInfo.getInstance(IsoType.TIME, 6, encode));
|
||||
fullSpecMap.put(13, FieldParseInfo.getInstance(IsoType.DATE4, 4, encode));
|
||||
fullSpecMap.put(14, FieldParseInfo.getInstance(IsoType.DATE_EXP, 4, encode));
|
||||
fullSpecMap.put(15, FieldParseInfo.getInstance(IsoType.DATE4, 4, encode));
|
||||
fullSpecMap.put(18, FieldParseInfo.getInstance(IsoType.NUMERIC, 4, encode));
|
||||
fullSpecMap.put(22, FieldParseInfo.getInstance(IsoType.NUMERIC, 3, encode));
|
||||
fullSpecMap.put(24, FieldParseInfo.getInstance(IsoType.NUMERIC, 3, encode));
|
||||
fullSpecMap.put(25, FieldParseInfo.getInstance(IsoType.NUMERIC, 2, encode));
|
||||
fullSpecMap.put(26, FieldParseInfo.getInstance(IsoType.NUMERIC, 2, encode));
|
||||
fullSpecMap.put(32, FieldParseInfo.getInstance(IsoType.LLVAR, 11, encode));
|
||||
fullSpecMap.put(33, FieldParseInfo.getInstance(IsoType.LLVAR, 11, encode));
|
||||
fullSpecMap.put(35, FieldParseInfo.getInstance(IsoType.LLVAR, 37, encode));
|
||||
fullSpecMap.put(37, FieldParseInfo.getInstance(IsoType.ALPHA, 12, encode));
|
||||
fullSpecMap.put(38, FieldParseInfo.getInstance(IsoType.ALPHA, 6, encode));
|
||||
fullSpecMap.put(39, FieldParseInfo.getInstance(IsoType.ALPHA, 2, encode));
|
||||
fullSpecMap.put(40, FieldParseInfo.getInstance(IsoType.ALPHA, 3, encode));
|
||||
fullSpecMap.put(41, FieldParseInfo.getInstance(IsoType.ALPHA, 8, encode));
|
||||
fullSpecMap.put(42, FieldParseInfo.getInstance(IsoType.ALPHA, 15, encode));
|
||||
fullSpecMap.put(43, FieldParseInfo.getInstance(IsoType.ALPHA, 40, encode));
|
||||
fullSpecMap.put(48, FieldParseInfo.getInstance(IsoType.LLLVAR, 999, encode));
|
||||
fullSpecMap.put(49, FieldParseInfo.getInstance(IsoType.ALPHA, 3, encode));
|
||||
// fullSpecMap.put(52, FieldParseInfo.getInstance(IsoType.BINARY, 64, encode));
|
||||
fullSpecMap.put(52, FieldParseInfo.getInstance(IsoType.ALPHA, 16, encode)); // 표준X
|
||||
fullSpecMap.put(54, FieldParseInfo.getInstance(IsoType.LLLVAR, 120, encode));
|
||||
fullSpecMap.put(55, FieldParseInfo.getInstance(IsoType.LLLVAR, 765, encode));
|
||||
fullSpecMap.put(60, FieldParseInfo.getInstance(IsoType.LLLVAR, 999, encode));
|
||||
fullSpecMap.put(61, FieldParseInfo.getInstance(IsoType.LLLVAR, 999, encode));
|
||||
fullSpecMap.put(62, FieldParseInfo.getInstance(IsoType.LLLVAR, 999, encode));
|
||||
fullSpecMap.put(63, FieldParseInfo.getInstance(IsoType.LLLVAR, 999, encode));
|
||||
fullSpecMap.put(70, FieldParseInfo.getInstance(IsoType.NUMERIC, 3, encode));
|
||||
fullSpecMap.put(90, FieldParseInfo.getInstance(IsoType.NUMERIC, 42, encode));
|
||||
fullSpecMap.put(98, FieldParseInfo.getInstance(IsoType.ALPHA, 25, encode));
|
||||
fullSpecMap.put(102, FieldParseInfo.getInstance(IsoType.LLVAR, 28, encode));
|
||||
fullSpecMap.put(103, FieldParseInfo.getInstance(IsoType.LLVAR, 28, encode));
|
||||
fullSpecMap.put(120, FieldParseInfo.getInstance(IsoType.LLLVAR, 999, encode));
|
||||
// fullSpecMap.put(126, FieldParseInfo.getInstance(IsoType.LLLVAR, 999,
|
||||
// encode));
|
||||
fullSpecMap.put(126, FieldParseInfo.getInstance(IsoType.LLLLVAR, 9999, encode)); // 표준X
|
||||
fullSpecMap.put(127, FieldParseInfo.getInstance(IsoType.LLLVAR, 999, encode));
|
||||
fullSpecMap.put(128, FieldParseInfo.getInstance(IsoType.BINARY, 64, encode));
|
||||
|
||||
return fullSpecMap;
|
||||
}
|
||||
|
||||
public String getFieldName(int key) {
|
||||
if (fullFieldNameMap == null) {
|
||||
fullFieldNameMap = new HashMap<>();
|
||||
fullFieldNameMap.put(1, "Bitmap, Secondary");
|
||||
fullFieldNameMap.put(2, "Primary Account Number");
|
||||
fullFieldNameMap.put(3, "Processing Code");
|
||||
fullFieldNameMap.put(4, "Amount, Transaction");
|
||||
fullFieldNameMap.put(6, "Amount, Cardholder Billing");
|
||||
fullFieldNameMap.put(7, "Transmission Date and Time");
|
||||
fullFieldNameMap.put(11, "System Trace Audit Number");
|
||||
fullFieldNameMap.put(12, "Time, Local Transaction");
|
||||
fullFieldNameMap.put(13, "Date, Local Transaction");
|
||||
fullFieldNameMap.put(14, "Date, Expiration");
|
||||
fullFieldNameMap.put(15, "Date, Settlement");
|
||||
fullFieldNameMap.put(18, "Merchant Type");
|
||||
|
||||
fullFieldNameMap.put(22, "Point of Service Entry Mode");
|
||||
fullFieldNameMap.put(24, "Network/Function Indentification Id");
|
||||
fullFieldNameMap.put(25, "Point-Of-Service Condition Code");
|
||||
|
||||
fullFieldNameMap.put(26, "Point-Of-Service PIN Capture Code");
|
||||
fullFieldNameMap.put(32, "Acquiring Institution Identification Code");
|
||||
fullFieldNameMap.put(33, "Forwarding Institution Identification Code");
|
||||
|
||||
fullFieldNameMap.put(35, "Track 2 Data");
|
||||
fullFieldNameMap.put(37, "Retrieval Reference Number");
|
||||
fullFieldNameMap.put(38, "Authorization Identification Response");
|
||||
|
||||
fullFieldNameMap.put(39, "Response Code");
|
||||
fullFieldNameMap.put(40, "Service Restriction Code");
|
||||
fullFieldNameMap.put(41, "Card Acceptor Terminal Identification");
|
||||
|
||||
fullFieldNameMap.put(42, "Card Acceptor Identification");
|
||||
fullFieldNameMap.put(43, "Card Acceptor Name and Location");
|
||||
fullFieldNameMap.put(48, "Additional Data – Private");
|
||||
|
||||
fullFieldNameMap.put(49, "Transaction Currency Code");
|
||||
fullFieldNameMap.put(52, "Personal Identification Number");
|
||||
fullFieldNameMap.put(54, "Amount, Additional");
|
||||
|
||||
fullFieldNameMap.put(55, "Integrated Circuit Card (ICC) System Related Data");
|
||||
|
||||
fullFieldNameMap.put(60, "Reserved Private F60");
|
||||
fullFieldNameMap.put(61, "Reserved Private F61");
|
||||
fullFieldNameMap.put(62, "Reserved Private F62");
|
||||
|
||||
fullFieldNameMap.put(63, "Reserved Private F63");
|
||||
fullFieldNameMap.put(70, "Network Management Information Code");
|
||||
fullFieldNameMap.put(90, "Original Data Element");
|
||||
|
||||
fullFieldNameMap.put(98, "Payee");
|
||||
fullFieldNameMap.put(102, "Account Identification 1");
|
||||
fullFieldNameMap.put(103, "Account Identification 2");
|
||||
|
||||
fullFieldNameMap.put(120, "Reserved Private F120");
|
||||
fullFieldNameMap.put(126, "Reserved Private F126");
|
||||
fullFieldNameMap.put(127, "Destination Institution Identification Code");
|
||||
fullFieldNameMap.put(128, "Message Authentication Code Field");
|
||||
}
|
||||
|
||||
return fullFieldNameMap.get(new Integer(key));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(
|
||||
"[ISO8583H2H message]");
|
||||
sb.append("\n" + super.toString());
|
||||
sb.append(
|
||||
"\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
-134
@@ -1,134 +0,0 @@
|
||||
package com.eactive.eai.custom.transformer.message;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.eactive.eai.transformer.message.ISO8583Message;
|
||||
import com.solab.iso8583.IsoMessage;
|
||||
import com.solab.iso8583.IsoType;
|
||||
import com.solab.iso8583.MessageFactory;
|
||||
import com.solab.iso8583.parse.FieldParseInfo;
|
||||
|
||||
/**
|
||||
* @formatter:off
|
||||
* ISO 8583 Silverlake(전문) 형식의 데이터를 변환하기 위한 메시지.(For KB Bukopin)
|
||||
* - Binary, EBCDIC
|
||||
*
|
||||
* [참조] https://en.wikipedia.org/wiki/ISO_8583
|
||||
* @formatter:on
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ISO8583SilverlakeMessage extends ISO8583Message {
|
||||
private static HashMap<Integer, FieldParseInfo> fullSpecMap = null;
|
||||
private static HashMap<Integer, String> fullFieldNameMap = null;
|
||||
private static String encode = "Cp1047"; // EBCDIC(1047)
|
||||
|
||||
public MessageFactory<IsoMessage> createMessageFactory() {
|
||||
MessageFactory<IsoMessage> mf = new MessageFactory<>();
|
||||
mf.setUseBinaryMessages(true);
|
||||
mf.setUseBinaryBitmap(true);
|
||||
mf.setVariableLengthFieldsInHex(false);
|
||||
mf.setCharacterEncoding(encode);
|
||||
mf.setForceStringEncoding(true);
|
||||
return mf;
|
||||
}
|
||||
|
||||
public HashMap<Integer, FieldParseInfo> getFullSpecMap(String enc) {
|
||||
if (fullSpecMap != null) {
|
||||
return fullSpecMap;
|
||||
}
|
||||
|
||||
fullSpecMap = new HashMap<>();
|
||||
|
||||
fullSpecMap.put(2, FieldParseInfo.getInstance(IsoType.LLBCDBIN, 10, encode));
|
||||
fullSpecMap.put(3, FieldParseInfo.getInstance(IsoType.BINARY, 3, encode));
|
||||
fullSpecMap.put(4, FieldParseInfo.getInstance(IsoType.BINARY, 6, encode));
|
||||
fullSpecMap.put(7, FieldParseInfo.getInstance(IsoType.BINARY, 5, encode));
|
||||
fullSpecMap.put(11, FieldParseInfo.getInstance(IsoType.BINARY, 3, encode));
|
||||
fullSpecMap.put(12, FieldParseInfo.getInstance(IsoType.BINARY, 3, encode));
|
||||
fullSpecMap.put(13, FieldParseInfo.getInstance(IsoType.BINARY, 2, encode));
|
||||
fullSpecMap.put(14, FieldParseInfo.getInstance(IsoType.BINARY, 2, encode));
|
||||
fullSpecMap.put(18, FieldParseInfo.getInstance(IsoType.BINARY, 2, encode));
|
||||
fullSpecMap.put(22, FieldParseInfo.getInstance(IsoType.BINARY, 2, encode));
|
||||
fullSpecMap.put(23, FieldParseInfo.getInstance(IsoType.BINARY, 2, encode));
|
||||
fullSpecMap.put(25, FieldParseInfo.getInstance(IsoType.BINARY, 1, encode));
|
||||
fullSpecMap.put(35, FieldParseInfo.getInstance(IsoType.LLBCDBIN, 19, encode));
|
||||
fullSpecMap.put(37, FieldParseInfo.getInstance(IsoType.ALPHA, 12, encode));
|
||||
fullSpecMap.put(38, FieldParseInfo.getInstance(IsoType.ALPHA, 6, encode));
|
||||
fullSpecMap.put(39, FieldParseInfo.getInstance(IsoType.ALPHA, 2, encode));
|
||||
fullSpecMap.put(41, FieldParseInfo.getInstance(IsoType.ALPHA, 8, encode));
|
||||
fullSpecMap.put(42, FieldParseInfo.getInstance(IsoType.ALPHA, 15, encode));
|
||||
fullSpecMap.put(43, FieldParseInfo.getInstance(IsoType.ALPHA, 40, encode));
|
||||
fullSpecMap.put(47, FieldParseInfo.getInstance(IsoType.LLLVAR, 256, encode));
|
||||
fullSpecMap.put(48, FieldParseInfo.getInstance(IsoType.LLLVAR, 256, encode));
|
||||
fullSpecMap.put(52, FieldParseInfo.getInstance(IsoType.BINARY, 8, encode));
|
||||
fullSpecMap.put(54, FieldParseInfo.getInstance(IsoType.LLLVAR, 120, encode));
|
||||
fullSpecMap.put(55, FieldParseInfo.getInstance(IsoType.LLLVAR, 255, encode));
|
||||
fullSpecMap.put(57, FieldParseInfo.getInstance(IsoType.LLLVAR, 255, encode));
|
||||
fullSpecMap.put(58, FieldParseInfo.getInstance(IsoType.LLLVAR, 255, encode));
|
||||
fullSpecMap.put(60, FieldParseInfo.getInstance(IsoType.LLLVAR, 120, encode));
|
||||
fullSpecMap.put(61, FieldParseInfo.getInstance(IsoType.LLLVAR, 120, encode));
|
||||
fullSpecMap.put(62, FieldParseInfo.getInstance(IsoType.LLLVAR, 512, encode));
|
||||
fullSpecMap.put(63, FieldParseInfo.getInstance(IsoType.LLLVAR, 512, encode));
|
||||
fullSpecMap.put(120, FieldParseInfo.getInstance(IsoType.LLLVAR, 700, encode));
|
||||
fullSpecMap.put(121, FieldParseInfo.getInstance(IsoType.LLLVAR, 500, encode));
|
||||
fullSpecMap.put(122, FieldParseInfo.getInstance(IsoType.LLLVAR, 350, encode));
|
||||
fullSpecMap.put(123, FieldParseInfo.getInstance(IsoType.LLLVAR, 999, encode));
|
||||
fullSpecMap.put(124, FieldParseInfo.getInstance(IsoType.LLLVAR, 450, encode));
|
||||
fullSpecMap.put(125, FieldParseInfo.getInstance(IsoType.LLLVAR, 255, encode));
|
||||
|
||||
return fullSpecMap;
|
||||
}
|
||||
|
||||
public String getFieldName(int key) {
|
||||
if (fullFieldNameMap == null) {
|
||||
fullFieldNameMap = new HashMap<>();
|
||||
fullFieldNameMap.put(1, "Secondary Bit Map");
|
||||
fullFieldNameMap.put(2, "Primary Account Number");
|
||||
fullFieldNameMap.put(3, "Processing code");
|
||||
fullFieldNameMap.put(4, "Amount,transaction");
|
||||
fullFieldNameMap.put(7, "Transmission date & time");
|
||||
fullFieldNameMap.put(11, "System audit trace number");
|
||||
fullFieldNameMap.put(12, "Time, local transaction");
|
||||
fullFieldNameMap.put(13, "Date, local transaction");
|
||||
fullFieldNameMap.put(14, "Date, expiration");
|
||||
fullFieldNameMap.put(18, "Merchant type");
|
||||
fullFieldNameMap.put(22, "POS entry mode");
|
||||
fullFieldNameMap.put(23, "Card sequence number");
|
||||
fullFieldNameMap.put(25, "POS condition code");
|
||||
fullFieldNameMap.put(35, "Track 2 data");
|
||||
fullFieldNameMap.put(37, "Retrieval reference number");
|
||||
fullFieldNameMap.put(38, "Authorisation ID response");
|
||||
fullFieldNameMap.put(39, "Response code");
|
||||
fullFieldNameMap.put(41, "Terminal ID");
|
||||
fullFieldNameMap.put(42, "Card acceptor ID");
|
||||
fullFieldNameMap.put(43, "Card acceptor name/location");
|
||||
fullFieldNameMap.put(47, "Private Use");
|
||||
fullFieldNameMap.put(48, "Request header");
|
||||
fullFieldNameMap.put(52, "PIN data");
|
||||
fullFieldNameMap.put(54, "Private Use");
|
||||
fullFieldNameMap.put(55, "ICC system related data");
|
||||
fullFieldNameMap.put(57, "Private Use");
|
||||
fullFieldNameMap.put(58, "Private Use");
|
||||
fullFieldNameMap.put(60, "Private Use");
|
||||
fullFieldNameMap.put(61, "Private Use");
|
||||
fullFieldNameMap.put(62, "Private Use");
|
||||
fullFieldNameMap.put(63, "Private Use");
|
||||
fullFieldNameMap.put(120, "Private Use");
|
||||
fullFieldNameMap.put(121, "Private Use");
|
||||
fullFieldNameMap.put(122, "Response detail");
|
||||
fullFieldNameMap.put(123, "Response detail");
|
||||
fullFieldNameMap.put(124, "Private Use");
|
||||
fullFieldNameMap.put(125, "Private Use");
|
||||
}
|
||||
|
||||
return fullFieldNameMap.get(new Integer(key));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("[ISO8583 Silverlake message]");
|
||||
sb.append("\n" + super.toString());
|
||||
sb.append("\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user