Merge branch 'feature/error-response-format' into jenkins_with_weblogic

This commit is contained in:
pksup
2025-12-11 13:41:19 +09:00
@@ -1,5 +1,25 @@
package com.eactive.eai.common.util; package com.eactive.eai.common.util;
import java.io.BufferedInputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.tools.ant.filters.StringInputStream;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import com.eactive.eai.common.EAIKeys; import com.eactive.eai.common.EAIKeys;
import com.eactive.eai.common.message.MessageType; import com.eactive.eai.common.message.MessageType;
import com.eactive.eai.common.monitor.EAIServiceMonitor; import com.eactive.eai.common.monitor.EAIServiceMonitor;
@@ -10,30 +30,16 @@ import com.eactive.eai.transformer.util.ISO8583DumpUtil;
import com.ext.eai.common.stdmessage.STDMessageErrorKeys; import com.ext.eai.common.stdmessage.STDMessageErrorKeys;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import com.solab.iso8583.IsoMessage; import com.solab.iso8583.IsoMessage;
import org.apache.commons.lang3.StringUtils;
import org.apache.tools.ant.filters.StringInputStream;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import java.io.BufferedInputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public final class MessageUtil { public final class MessageUtil {
static Logger logger = LoggerFactory.getLogger(MessageUtil.class); 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_CODE_AP_ERROR = "E.GW.AP_ERROR";
public static final String ERROR_CODE_AUTH_FAIL = "E.GW.AUTH_FAIL";
public static final String ERROR_CODE_SERVICE_NOT_FOUND = "E.GW.SERVICE_NOT_FOUND";
private MessageUtil() { private MessageUtil() {
} }
@@ -492,12 +498,10 @@ public final class MessageUtil {
public static String makeErrorMessageByMessageType(String msgType, String msgCharset, String code, String msg, public static String makeErrorMessageByMessageType(String msgType, String msgCharset, String code, String msg,
String errorFormat) { String errorFormat) {
if (StringUtils.equals(msgType, MessageType.JSON)) { if (StringUtils.equals(msgType, MessageType.XML)) {
return makeJsonErrorMessage(code, msg, errorFormat);
} else if (StringUtils.equals(msgType, MessageType.XML)) {
return makeXmlErrorMessage(code, msg, msgCharset, errorFormat); return makeXmlErrorMessage(code, msg, msgCharset, errorFormat);
} else { } else {
return "[errCd]" + code + "[/errCd]" + "[errMsg]" + msg + "[/errMsg]"; return makeJsonErrorMessage(code, msg, errorFormat);
} }
} }
@@ -510,14 +514,17 @@ public final class MessageUtil {
} }
public static String makeJsonErrorMessage(String code, String msg, String errorFormat) { public static String makeJsonErrorMessage(String code, String msg, String errorFormat) {
if (StringUtils.isNotBlank(errorFormat)) { if (StringUtils.isBlank(errorFormat)) {
try { errorFormat = ERROR_MESSAGE_DEFAULT_FORMAT;
return String.format(errorFormat, code, JSONValue.escape(msg)); }
} catch (Exception e) {
logger.error(e.getMessage()); // errorFormat에 %s가 1개만 있으면 msg만, 2개 이상이면 code, msg 전달
} int paramCount = StringUtils.countMatches(errorFormat, "%s");
if (paramCount == 1) {
return String.format(errorFormat, JSONValue.escape(msg));
} else {
return String.format(errorFormat, code, JSONValue.escape(msg));
} }
return String.format("{\"error\":\"%s\",\"error_description\":\"%s\"}", code, JSONValue.escape(msg));
} }
public static String makeXmlErrorMessage(String code, String msg, String charset, String errorFormat) { public static String makeXmlErrorMessage(String code, String msg, String charset, String errorFormat) {