TemplateAdapterErrorMsgHandler 를 이용하여 오류메시지 생성할 수 있도록 변경
This commit is contained in:
@@ -19,6 +19,8 @@ import com.eactive.eai.adapter.AdapterGroupVO;
|
|||||||
import com.eactive.eai.adapter.AdapterManager;
|
import com.eactive.eai.adapter.AdapterManager;
|
||||||
import com.eactive.eai.adapter.AdapterPropManager;
|
import com.eactive.eai.adapter.AdapterPropManager;
|
||||||
import com.eactive.eai.adapter.AdapterVO;
|
import com.eactive.eai.adapter.AdapterVO;
|
||||||
|
import com.eactive.eai.adapter.handler.AdapterErrorMessageHandler;
|
||||||
|
import com.eactive.eai.adapter.handler.AdapterErrorMessageHandlerFactory;
|
||||||
import com.eactive.eai.adapter.http.HttpStatusException;
|
import com.eactive.eai.adapter.http.HttpStatusException;
|
||||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
||||||
import com.eactive.eai.adapter.http.dynamic.HttpDynamicInAdapterManager;
|
import com.eactive.eai.adapter.http.dynamic.HttpDynamicInAdapterManager;
|
||||||
@@ -132,27 +134,18 @@ public class DJErpApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
|
|
||||||
String errorMsg = null;
|
String errorMsg = null;
|
||||||
|
|
||||||
if(e instanceof HttpStatusException ) {
|
errorMsg = genErrorResponseMessage(adapterGroupName, adapterName,
|
||||||
|
transactionProp, e, adptMsgType, encode, errorResponseFormat);
|
||||||
|
if (e instanceof HttpStatusException) {
|
||||||
logger.warn("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage());
|
logger.warn("ApiAdapterController] " + adapterGroupName + "-" + adapterName + ">>" + e.getMessage());
|
||||||
HttpStatusException e1 = (HttpStatusException) e;
|
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);
|
responseEntity = ResponseEntity.status(e1.getStatus()).contentType(mediaType).body(errorMsg);
|
||||||
}
|
} else if (e instanceof JwtAuthException) {
|
||||||
else if( e instanceof JwtAuthException )
|
|
||||||
{
|
|
||||||
logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
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);
|
responseEntity = ResponseEntity.status(HttpStatus.UNAUTHORIZED).contentType(mediaType).body(errorMsg);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
logger.error(adapterGroupName + "-" + adapterName + ">>" + e.getMessage(), e);
|
||||||
errorMsg = MessageUtil.makeErrorMessageByMessageType(adptMsgType, encode,
|
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(mediaType).body(errorMsg);
|
||||||
MessageUtil.ERROR_CODE_AP_ERROR, e.getMessage(), errorResponseFormat);
|
|
||||||
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(mediaType)
|
|
||||||
.body(errorMsg);
|
|
||||||
}
|
}
|
||||||
responseData = errorMsg;
|
responseData = errorMsg;
|
||||||
|
|
||||||
@@ -173,6 +166,29 @@ public class DJErpApiAdapterController implements HttpAdapterServiceKey {
|
|||||||
return responseEntity;
|
return responseEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String genErrorResponseMessage(String adapterGroupName, String adapterName,
|
||||||
|
Properties callProp, Throwable e, String adptMsgType, String encode, String errorResponseFormat) {
|
||||||
|
String errorHandlerClass = AdapterPropManager.getInstance().getProperty(adapterName, "ERR_MSG_HANDLER");
|
||||||
|
if (StringUtils.isNotBlank(errorHandlerClass)) {
|
||||||
|
if (logger.isInfo())
|
||||||
|
logger.info("ExceptionHandler] errorSyncSend ERR_MSG_HANDLER=" + errorHandlerClass);
|
||||||
|
AdapterErrorMessageHandler handler = AdapterErrorMessageHandlerFactory.createHandler(errorHandlerClass);
|
||||||
|
if (handler != null) {
|
||||||
|
Object resposne;
|
||||||
|
try {
|
||||||
|
resposne = handler.generateNonStandardInboundErrorResponseMessage(adapterGroupName, adapterName,
|
||||||
|
callProp, null, null, e);
|
||||||
|
return (String)resposne;
|
||||||
|
} catch (Exception e1) {
|
||||||
|
logger.warn("AdapterErrorMessageHandler error.", e);
|
||||||
|
// handler 실패시 아래에서 처리한
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MessageUtil.makeErrorMessageByMessageType(adptMsgType, encode,
|
||||||
|
MessageUtil.ERROR_CODE_AP_ERROR, e.getMessage(), errorResponseFormat);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* url에서 뒤쪽 /이후를 제거하면서 찾는다.<br>
|
* url에서 뒤쪽 /이후를 제거하면서 찾는다.<br>
|
||||||
* /api/v1/public/getUserInfo.svc
|
* /api/v1/public/getUserInfo.svc
|
||||||
|
|||||||
@@ -1,52 +1,52 @@
|
|||||||
package com.eactive.eai.custom.adapter.handler;
|
//package com.eactive.eai.custom.adapter.handler;
|
||||||
|
//
|
||||||
import java.util.Properties;
|
//import java.util.Properties;
|
||||||
|
//
|
||||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
//import com.eactive.eai.adapter.AdapterGroupVO;
|
||||||
import com.eactive.eai.adapter.AdapterManager;
|
//import com.eactive.eai.adapter.AdapterManager;
|
||||||
import com.eactive.eai.adapter.handler.AdapterErrorMessageHandler;
|
//import com.eactive.eai.adapter.handler.AdapterErrorMessageHandler;
|
||||||
import com.eactive.eai.common.message.MessageType;
|
//import com.eactive.eai.common.message.MessageType;
|
||||||
import com.eactive.eai.message.StandardMessage;
|
//import com.eactive.eai.message.StandardMessage;
|
||||||
import com.eactive.eai.message.manager.StandardMessageManager;
|
//import com.eactive.eai.message.manager.StandardMessageManager;
|
||||||
import com.eactive.eai.message.service.InterfaceMapper;
|
//import com.eactive.eai.message.service.InterfaceMapper;
|
||||||
import com.ext.eai.common.stdmessage.STDMessageKeys;
|
//import com.ext.eai.common.stdmessage.STDMessageKeys;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
//import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
//import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
//
|
||||||
public class LonErrorMsgHandler implements AdapterErrorMessageHandler {
|
//public class LonErrorMsgHandler implements AdapterErrorMessageHandler {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public Object generateNonStandardErrorResponseMessage(String inboudnAdapterGroupName, String inboudnAdapterName,
|
// public Object generateNonStandardErrorResponseMessage(String inboudnAdapterGroupName, String inboudnAdapterName,
|
||||||
Properties callProp, Object outboundRequestData, StandardMessage resStandardMessage) throws Exception{
|
// Properties callProp, Object outboundRequestData, StandardMessage resStandardMessage) throws Exception{
|
||||||
|
//
|
||||||
if(resStandardMessage != null && isErrorMessage(resStandardMessage)) {
|
// if(resStandardMessage != null && isErrorMessage(resStandardMessage)) {
|
||||||
AdapterGroupVO adapterGroupVO = AdapterManager.getInstance().getAdapterGroupVO(inboudnAdapterGroupName);
|
// AdapterGroupVO adapterGroupVO = AdapterManager.getInstance().getAdapterGroupVO(inboudnAdapterGroupName);
|
||||||
if(MessageType.JSON.equals(adapterGroupVO.getMessageType())) {
|
// if(MessageType.JSON.equals(adapterGroupVO.getMessageType())) {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
String requestMessage = (String) outboundRequestData;
|
// String requestMessage = (String) outboundRequestData;
|
||||||
JsonNode requestJson = objectMapper.readTree(requestMessage);
|
// JsonNode requestJson = objectMapper.readTree(requestMessage);
|
||||||
String alncInstCd = requestJson.get("dataCmn").get("alncInstCd").asText();
|
// String alncInstCd = requestJson.get("dataCmn").get("alncInstCd").asText();
|
||||||
|
//
|
||||||
ObjectNode responseJson = objectMapper.createObjectNode();
|
// ObjectNode responseJson = objectMapper.createObjectNode();
|
||||||
ObjectNode dataCmnNode = objectMapper.createObjectNode();
|
// ObjectNode dataCmnNode = objectMapper.createObjectNode();
|
||||||
responseJson.set("dataCmn", dataCmnNode);
|
// responseJson.set("dataCmn", dataCmnNode);
|
||||||
dataCmnNode.put("fnclInstCd", "KBK");
|
// dataCmnNode.put("fnclInstCd", "KBK");
|
||||||
dataCmnNode.put("alncInstCd", alncInstCd);
|
// dataCmnNode.put("alncInstCd", alncInstCd);
|
||||||
dataCmnNode.put("tlgrRspnsCd", "0210");
|
// dataCmnNode.put("tlgrRspnsCd", "0210");
|
||||||
|
//
|
||||||
return responseJson.toString();
|
// return responseJson.toString();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
return "";
|
// return "";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private boolean isErrorMessage(StandardMessage standardMessage) {
|
// private boolean isErrorMessage(StandardMessage standardMessage) {
|
||||||
InterfaceMapper mapper = StandardMessageManager.getInstance().getMapper();
|
// InterfaceMapper mapper = StandardMessageManager.getInstance().getMapper();
|
||||||
String responseType = mapper.getResponseType(standardMessage);
|
// String responseType = mapper.getResponseType(standardMessage);
|
||||||
return STDMessageKeys.RESPONSE_TYPE_CODE_E.equals(responseType);
|
// return STDMessageKeys.RESPONSE_TYPE_CODE_E.equals(responseType);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|||||||
Reference in New Issue
Block a user