Commit 846d4656 by chengzhuoshen

如果出现异常,将静态配置文件对象置为空,以便下次解析配置文件,

parent bde01f91
...@@ -25,8 +25,9 @@ public class MessageUtil { ...@@ -25,8 +25,9 @@ public class MessageUtil {
return properties.getProperty(key, key); return properties.getProperty(key, key);
} }
return key; return key;
} catch (IOException e) { } catch (Exception e) {
throw new SwiftException("ERROR", e.getMessage()); properties = null;
throw new SwiftException(e.getMessage());
} }
} }
} }
...@@ -28,8 +28,6 @@ import java.util.*; ...@@ -28,8 +28,6 @@ import java.util.*;
public class SwiftTransferUtil { public class SwiftTransferUtil {
public static Properties properties = null;
public static List<SwiftTranslationErrorInfo> stErrorInfos = null; public static List<SwiftTranslationErrorInfo> stErrorInfos = null;
public static XMLGregorianCalendar getXMLGregorianCalendarNow() { public static XMLGregorianCalendar getXMLGregorianCalendarNow() {
...@@ -769,27 +767,32 @@ public class SwiftTransferUtil { ...@@ -769,27 +767,32 @@ public class SwiftTransferUtil {
*/ */
public static SwiftTranslationErrorInfo getSwiftTranslationErrorInfoByErrorCode(String key) { public static SwiftTranslationErrorInfo getSwiftTranslationErrorInfoByErrorCode(String key) {
if (stErrorInfos == null) { if (stErrorInfos == null) {
stErrorInfos = new ArrayList<>(); try {
InputStream resourceAsStream = SwiftTransferUtil.class.getResourceAsStream("/ErrorCodeList.xlsx"); stErrorInfos = new ArrayList<>();
ExcelReader reader = ExcelUtil.getReader(resourceAsStream, "CBPR+"); InputStream resourceAsStream = SwiftTransferUtil.class.getResourceAsStream("/ErrorCodeList.xlsx");
List<Map<String, Object>> content = reader.readAll(); ExcelReader reader = ExcelUtil.getReader(resourceAsStream, "CBPR+");
if (content.size() > 0) { List<Map<String, Object>> content = reader.readAll();
for (int i=0; i<content.size(); i++) { if (content.size() > 0) {
Map<String, Object> contentMaps = content.get(i); for (int i=0; i<content.size(); i++) {
String errorCode = (String)contentMaps.get("ErrorCode"); Map<String, Object> contentMaps = content.get(i);
String description = (String)contentMaps.get("Description"); String errorCode = (String)contentMaps.get("ErrorCode");
String errorType = (String)contentMaps.get("ErrorType"); String description = (String)contentMaps.get("Description");
if (StringUtil.isNotEmpty(errorCode) && StringUtil.isNotEmpty(description)) { String errorType = (String)contentMaps.get("ErrorType");
SwiftTranslationErrorInfo stErrorInfo = new SwiftTranslationErrorInfo(); if (StringUtil.isNotEmpty(errorCode) && StringUtil.isNotEmpty(description)) {
if (errorCode.indexOf("(") > -1) { SwiftTranslationErrorInfo stErrorInfo = new SwiftTranslationErrorInfo();
errorCode = errorCode.substring(0, errorCode.indexOf("(")); if (errorCode.indexOf("(") > -1) {
errorCode = errorCode.substring(0, errorCode.indexOf("("));
}
stErrorInfo.setErrorCode(errorCode.trim());
stErrorInfo.setDescription(description.trim());
stErrorInfo.setErrorType(errorType.trim());
stErrorInfos.add(stErrorInfo);
} }
stErrorInfo.setErrorCode(errorCode.trim());
stErrorInfo.setDescription(description.trim());
stErrorInfo.setErrorType(errorType.trim());
stErrorInfos.add(stErrorInfo);
} }
} }
} catch (Exception e) {
stErrorInfos = null;//如果出现异常,stErrorInfos=null,下次仍需初始化
throw e;
} }
} }
SwiftTranslationErrorInfo tmpErrorInfo = null; SwiftTranslationErrorInfo tmpErrorInfo = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment