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.AdapterPropManager;
|
||||
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.dynamic.HttpAdapterServiceKey;
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpDynamicInAdapterManager;
|
||||
@@ -132,27 +134,18 @@ public class DJErpApiAdapterController implements HttpAdapterServiceKey {
|
||||
|
||||
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());
|
||||
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 )
|
||||
{
|
||||
} 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
|
||||
{
|
||||
} 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);
|
||||
responseEntity = ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).contentType(mediaType).body(errorMsg);
|
||||
}
|
||||
responseData = errorMsg;
|
||||
|
||||
@@ -172,6 +165,29 @@ public class DJErpApiAdapterController implements HttpAdapterServiceKey {
|
||||
}
|
||||
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>
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
package com.eactive.eai.custom.adapter.handler;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
import com.eactive.eai.adapter.AdapterManager;
|
||||
import com.eactive.eai.adapter.handler.AdapterErrorMessageHandler;
|
||||
import com.eactive.eai.common.message.MessageType;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.manager.StandardMessageManager;
|
||||
import com.eactive.eai.message.service.InterfaceMapper;
|
||||
import com.ext.eai.common.stdmessage.STDMessageKeys;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
public class LonErrorMsgHandler implements AdapterErrorMessageHandler {
|
||||
|
||||
@Override
|
||||
public Object generateNonStandardErrorResponseMessage(String inboudnAdapterGroupName, String inboudnAdapterName,
|
||||
Properties callProp, Object outboundRequestData, StandardMessage resStandardMessage) throws Exception{
|
||||
|
||||
if(resStandardMessage != null && isErrorMessage(resStandardMessage)) {
|
||||
AdapterGroupVO adapterGroupVO = AdapterManager.getInstance().getAdapterGroupVO(inboudnAdapterGroupName);
|
||||
if(MessageType.JSON.equals(adapterGroupVO.getMessageType())) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
String requestMessage = (String) outboundRequestData;
|
||||
JsonNode requestJson = objectMapper.readTree(requestMessage);
|
||||
String alncInstCd = requestJson.get("dataCmn").get("alncInstCd").asText();
|
||||
|
||||
ObjectNode responseJson = objectMapper.createObjectNode();
|
||||
ObjectNode dataCmnNode = objectMapper.createObjectNode();
|
||||
responseJson.set("dataCmn", dataCmnNode);
|
||||
dataCmnNode.put("fnclInstCd", "KBK");
|
||||
dataCmnNode.put("alncInstCd", alncInstCd);
|
||||
dataCmnNode.put("tlgrRspnsCd", "0210");
|
||||
|
||||
return responseJson.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private boolean isErrorMessage(StandardMessage standardMessage) {
|
||||
InterfaceMapper mapper = StandardMessageManager.getInstance().getMapper();
|
||||
String responseType = mapper.getResponseType(standardMessage);
|
||||
return STDMessageKeys.RESPONSE_TYPE_CODE_E.equals(responseType);
|
||||
}
|
||||
|
||||
}
|
||||
//package com.eactive.eai.custom.adapter.handler;
|
||||
//
|
||||
//import java.util.Properties;
|
||||
//
|
||||
//import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
//import com.eactive.eai.adapter.AdapterManager;
|
||||
//import com.eactive.eai.adapter.handler.AdapterErrorMessageHandler;
|
||||
//import com.eactive.eai.common.message.MessageType;
|
||||
//import com.eactive.eai.message.StandardMessage;
|
||||
//import com.eactive.eai.message.manager.StandardMessageManager;
|
||||
//import com.eactive.eai.message.service.InterfaceMapper;
|
||||
//import com.ext.eai.common.stdmessage.STDMessageKeys;
|
||||
//import com.fasterxml.jackson.databind.JsonNode;
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
//
|
||||
//public class LonErrorMsgHandler implements AdapterErrorMessageHandler {
|
||||
//
|
||||
// @Override
|
||||
// public Object generateNonStandardErrorResponseMessage(String inboudnAdapterGroupName, String inboudnAdapterName,
|
||||
// Properties callProp, Object outboundRequestData, StandardMessage resStandardMessage) throws Exception{
|
||||
//
|
||||
// if(resStandardMessage != null && isErrorMessage(resStandardMessage)) {
|
||||
// AdapterGroupVO adapterGroupVO = AdapterManager.getInstance().getAdapterGroupVO(inboudnAdapterGroupName);
|
||||
// if(MessageType.JSON.equals(adapterGroupVO.getMessageType())) {
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
// String requestMessage = (String) outboundRequestData;
|
||||
// JsonNode requestJson = objectMapper.readTree(requestMessage);
|
||||
// String alncInstCd = requestJson.get("dataCmn").get("alncInstCd").asText();
|
||||
//
|
||||
// ObjectNode responseJson = objectMapper.createObjectNode();
|
||||
// ObjectNode dataCmnNode = objectMapper.createObjectNode();
|
||||
// responseJson.set("dataCmn", dataCmnNode);
|
||||
// dataCmnNode.put("fnclInstCd", "KBK");
|
||||
// dataCmnNode.put("alncInstCd", alncInstCd);
|
||||
// dataCmnNode.put("tlgrRspnsCd", "0210");
|
||||
//
|
||||
// return responseJson.toString();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// return "";
|
||||
// }
|
||||
//
|
||||
// private boolean isErrorMessage(StandardMessage standardMessage) {
|
||||
// InterfaceMapper mapper = StandardMessageManager.getInstance().getMapper();
|
||||
// String responseType = mapper.getResponseType(standardMessage);
|
||||
// return STDMessageKeys.RESPONSE_TYPE_CODE_E.equals(responseType);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user