feature: DJErp OAuth bypass 지원을 위한 공통 모듈 개선
- UnkownMessageLogUtils 추가: unknown 메시지 발생 시 DB 에러 로그 기록 - HttpAdapterServiceSupport: transactionId 추출을 try 블록 외부로 이동, 예외 분기 처리(HttpStatusException/JwtAuthException/Exception) 및 UnkownMessageLogUtils 연동 - ApiAuthFilter: eaiSvcCd 강제 덮어쓰기 로직 주석처리 (STDMessage 조회값 우선 사용) - MessageUtil: ERROR_MESSAGE_DEFAULT_FORMAT을 표준 OAuth2 에러 형식으로 변경 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,29 +10,35 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
import com.eactive.eai.adapter.AdapterManager;
|
||||
import com.eactive.eai.adapter.RequestDispatcher;
|
||||
import com.eactive.eai.adapter.http.HttpStatusException;
|
||||
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
||||
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.HttpAdapterFilterType;
|
||||
import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthException;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
|
||||
public abstract class HttpAdapterServiceSupport implements HttpAdapterService, HttpAdapterServiceKey {
|
||||
private static final String LOG_PREFIX = "HttpAdapterServiceSupport] ";
|
||||
protected long slowTranTime = 2000L;
|
||||
public static final String HEADER_NAME_CLIENT_ID = "x-elink-client-id";
|
||||
public static final String PROPERTIES_NAME_CLIENT_ID = "clientId";
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
|
||||
|
||||
public Object service(String adptGrpName, String adptName, Object message, Properties prop,
|
||||
HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
String transactionId = request.getHeader(HttpClientAdapterServiceKey.TRANSACTION_ID);
|
||||
if (StringUtils.isNotBlank(transactionId)) {
|
||||
prop.put(HttpClientAdapterServiceKey.TRANSACTION_ID, transactionId);
|
||||
}
|
||||
|
||||
try {
|
||||
String clientId = request.getHeader(HEADER_NAME_CLIENT_ID);
|
||||
if (StringUtils.isNotBlank(clientId)) {
|
||||
prop.put(PROPERTIES_NAME_CLIENT_ID, clientId);
|
||||
}
|
||||
|
||||
String transactionId = request.getHeader(HttpClientAdapterServiceKey.TRANSACTION_ID);
|
||||
if (StringUtils.isNotBlank(transactionId)) {
|
||||
prop.put(HttpClientAdapterServiceKey.TRANSACTION_ID, transactionId);
|
||||
}
|
||||
|
||||
String instanceId = request.getHeader(HttpClientAdapterServiceKey.INSTANCE_ID);
|
||||
if (StringUtils.isNotBlank(instanceId)) {
|
||||
prop.put(HttpClientAdapterServiceKey.INSTANCE_ID, instanceId);
|
||||
@@ -40,9 +46,26 @@ public abstract class HttpAdapterServiceSupport implements HttpAdapterService, H
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
message = doPreFilters(adptGrpName, adptName, message, prop, request, response);
|
||||
Object obj = RequestDispatcher.getRequestDispatcher(adptGrpName).handle(adptName, message, prop);
|
||||
obj = doPostFilters(adptGrpName, adptName, obj, prop, request, response);
|
||||
Object obj = null;
|
||||
try {
|
||||
message = doPreFilters(adptGrpName, adptName, message, prop, request, response);
|
||||
obj = RequestDispatcher.getRequestDispatcher(adptGrpName).handle(adptName, message, prop);
|
||||
obj = doPostFilters(adptGrpName, adptName, obj, prop, request, response);
|
||||
} catch (HttpStatusException e) { // inbound error
|
||||
logger.warn(LOG_PREFIX + transactionId + "-" + adptGrpName + "-" + adptName + ">>" + e.getMessage(), e);
|
||||
throw e;
|
||||
} catch (JwtAuthException e) { // filter error
|
||||
logger.error(LOG_PREFIX + transactionId + "-" + adptGrpName + "-" + adptName + ">>" + e.getMessage(), e);
|
||||
UnkownMessageLogUtils.logUnkownMessage(adptGrpName, adptName, message, prop, request, response,
|
||||
"RECEAIIRP202", e);
|
||||
throw e;
|
||||
} catch (Exception e) { // filter error
|
||||
logger.error(LOG_PREFIX + transactionId + "-" + adptGrpName + "-" + adptName + ">>" + e.getMessage(), e);
|
||||
UnkownMessageLogUtils.logUnkownMessage(adptGrpName, adptName, message, prop, request, response,
|
||||
"RECEAIIRP201", e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (obj == null) {
|
||||
return null;
|
||||
} else if (obj instanceof byte[]) {
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.eactive.eai.adapter.http.dynamic;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
import com.eactive.eai.adapter.AdapterManager;
|
||||
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
import com.eactive.eai.common.server.EAIServerManager;
|
||||
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.UUIDGenerator;
|
||||
import com.eactive.eai.inbound.error.InboundErrorInfoVO;
|
||||
import com.eactive.eai.inbound.error.InboundErrorKeys;
|
||||
import com.eactive.eai.util.HexaConverter;
|
||||
|
||||
public class UnkownMessageLogUtils {
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
private UnkownMessageLogUtils() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static void logUnkownMessage(String adptGrpName, String adptName, Object message, Properties prop,
|
||||
HttpServletRequest request, HttpServletResponse response, String errCode, Exception e) {
|
||||
try {
|
||||
EAIServerManager eaiServerManager = EAIServerManager.getInstance();
|
||||
String serverName = eaiServerManager.getLocalServerName();
|
||||
String txId = prop.getProperty(HttpClientAdapterServiceKey.TRANSACTION_ID);
|
||||
if(StringUtils.isEmpty(txId)) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
String instanceid1 = serverName.substring(0,2);
|
||||
String instanceid2 = serverName.substring(serverName.length()-2, serverName.length());
|
||||
String instid = instanceid1 + instanceid2;
|
||||
txId = instid + UUIDGenerator.getUUID();
|
||||
}
|
||||
String clientId = prop.getProperty("clientId");
|
||||
String hexClientId = clientId != null ? HexaConverter.bytesToHexa(clientId.getBytes()) : "";
|
||||
String errorMsg = ExceptionUtil.make(e, errCode);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(errorMsg).append("\n").append("Remote Addr : ").append(request.getRemoteAddr()).append("\n").append("Request URI : ")
|
||||
.append(request.getRequestURI()).append("\n").append("clientId=").append(clientId).append(",hexClientId=").append(hexClientId).append(",txProp=").append(prop).append("\n").append("Exception : ").append(e.getMessage());
|
||||
UnkownMessageLogUtils.logUnknownMessage(txId, adptGrpName, adptName,
|
||||
"", "", false, errCode, sb.toString(), System.currentTimeMillis(),
|
||||
serverName, InboundErrorKeys.IN_UNKNOWN, message);
|
||||
} catch (Exception ex) {
|
||||
logger.warn("unkown log fail.", ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public static void logUnkownMessage(String uuid, String adapterGroupName, String adapterName, String errCode,
|
||||
// String errMsg, Object message) {
|
||||
// UnkownMessageLogUtils.logUnknownMessage(uuid, adapterGroupName, adapterName,
|
||||
// "", "", false, errCode, errMsg, System.currentTimeMillis(),
|
||||
// EAIServerManager.getInstance().getInstId(), InboundErrorKeys.IN_UNKNOWN, message);
|
||||
// }
|
||||
|
||||
private static void logUnknownMessage(String uuid, String adapterGroupName, String adapterName,
|
||||
String bzwkSvcKeyName, String eaiSvcCd, boolean isTasStarted, String errCode, String errMsg, long errTm,
|
||||
String svcInstNm, String errDstCd, Object message) {
|
||||
String msg = null;
|
||||
|
||||
if(errDstCd == null || errDstCd.length() ==0) {
|
||||
errDstCd = "ND";
|
||||
}
|
||||
|
||||
if(isTasStarted) {
|
||||
errDstCd = InboundErrorKeys.TAS_START;
|
||||
}
|
||||
|
||||
InboundErrorInfoVO errorInfoVO = new InboundErrorInfoVO();
|
||||
errorInfoVO.setEaiSvcSno(uuid); // EAI서비스일련번호
|
||||
errorInfoVO.setAdptBwkGrpNm(adapterGroupName); // 어댑터업무그룹명
|
||||
errorInfoVO.setEaiSvcCd(eaiSvcCd);
|
||||
errorInfoVO.setErrCd(errCode); // 에러코드
|
||||
errorInfoVO.setErrTxt(errMsg); // 에러내용
|
||||
errorInfoVO.setErrTm(DatetimeUtil.getCurrentTime(errTm)); // 에러발생시각
|
||||
errorInfoVO.setErrDstcd(errDstCd);
|
||||
errorInfoVO.setBzwkSvcKeyName(bzwkSvcKeyName);
|
||||
|
||||
if(message == null) {
|
||||
msg = "null";
|
||||
}
|
||||
else {
|
||||
if(message instanceof byte[]) {
|
||||
AdapterManager adapterManager = AdapterManager.getInstance();
|
||||
AdapterGroupVO srcAdapterGrpVO = adapterManager.getAdapterGroupVO(adapterGroupName);
|
||||
|
||||
// TAS 거래일 경우 NULL일 수 있음
|
||||
if(srcAdapterGrpVO == null) {
|
||||
msg = new String((byte[])message);
|
||||
}
|
||||
else {
|
||||
// String srcAdapterMsgType = srcAdapterGrpVO.getMessageType();
|
||||
// if( MessageUtil.isUTF8(srcAdapterMsgType) ) {
|
||||
// try {
|
||||
// msg = new String((byte[])message, UJSONMessage.encode);
|
||||
// } catch (UnsupportedEncodingException e) {
|
||||
// logger.warn("msg encode error", e);
|
||||
// msg = new String((byte[])message); }
|
||||
// }
|
||||
// else {
|
||||
// msg = new String((byte[])message);
|
||||
// }
|
||||
|
||||
String charset = StringUtils.defaultIfBlank(srcAdapterGrpVO.getMessageEncode(), Charset.defaultCharset().name());
|
||||
try {
|
||||
msg = new String((byte[])message, charset);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.warn("msg encode error", e);
|
||||
msg = new String((byte[])message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(message instanceof String) {
|
||||
msg = (String)message;
|
||||
}
|
||||
else {
|
||||
msg = "invaild message ["+message.getClass().getName()+"] "+message.toString();
|
||||
}
|
||||
}
|
||||
|
||||
errorInfoVO.setBwkDataTxt(msg); // 업무데이터내용
|
||||
errorInfoVO.setEaiSvrInstNm(svcInstNm); // EAI서버인스턴스명
|
||||
|
||||
InboundErrorLogger.error(errorInfoVO);
|
||||
|
||||
if (logger.isError()) {
|
||||
logger.error("======================================================================" );
|
||||
logger.error(" RequestDispatcher] GET UNKNOWN MESSAGE");
|
||||
logger.error(" ADAPTER GROUP NAME [" + adapterGroupName + "]");
|
||||
logger.error(" EAISVCNAME [" + eaiSvcCd + "]");
|
||||
logger.error(" ADAPTER NAME [" + adapterName + "]");
|
||||
logger.error("======================================================================" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,8 @@ public class ApiAuthFilter implements HttpAdapterFilter {
|
||||
*/
|
||||
StandardMessage standardMessage = STDMessageManager.getInstance().getSTDMessage(apiId);
|
||||
String eaiSvcCd = StandardMessageManager.getInstance().getMapper().getEaiSvcCode(standardMessage);
|
||||
if(!StringUtils.equals(eaiSvcCd, prop.getProperty("API_SERVICE_CODE"))) eaiSvcCd = prop.getProperty("API_SERVICE_CODE");
|
||||
// if (StringUtils.isNotEmpty(eaiSvcCd) && !StringUtils.equals(eaiSvcCd, ))
|
||||
// eaiSvcCd = prop.getProperty("API_SERVICE_CODE");
|
||||
EAIMessage eaiMessage = EAIMessageManager.getInstance().getEAIMessage(eaiSvcCd);
|
||||
|
||||
if(StringUtils.isBlank(eaiMessage.getAuthType())){
|
||||
|
||||
@@ -35,7 +35,8 @@ public final class MessageUtil {
|
||||
static Logger logger = LoggerFactory.getLogger(MessageUtil.class);
|
||||
|
||||
//public static final String ERROR_MESSAGE_DEFAULT_FORMAT = "{\"error\":{\"code\":\"%s\",\"message\":\"%s\"}}";
|
||||
public static final String ERROR_MESSAGE_DEFAULT_FORMAT = "{\"code\":\"%s\",\"message\":\"%s\"}";
|
||||
// public static final String ERROR_MESSAGE_DEFAULT_FORMAT = "{\"code\":\"%s\",\"message\":\"%s\"}";
|
||||
public static final String ERROR_MESSAGE_DEFAULT_FORMAT = "{\"error\":\"%s\",\"error_description\":\"%s\"}";
|
||||
|
||||
public static final String ERROR_CODE_AP_ERROR = "E.GW.AP_ERROR";
|
||||
public static final String ERROR_CODE_AUTH_FAIL = "E.GW.AUTH_FAIL";
|
||||
|
||||
Reference in New Issue
Block a user