Commit c8d7ade9 by chengzhuoshen

处理无效xml,提取AppHdr Document组有效xml

parent 32395c3b
......@@ -124,6 +124,7 @@ public class SwiftTransfer {
*/
public static Map<String, String> mx2MtMap(String xmlStr, Map<String, Object> extraMap) throws SwiftException {
try {
xmlStr = MxMessageReader.handingXml(xmlStr);
SwiftTranslationReport str = mx2MtPlus(xmlStr, null, extraMap);
Map<String, String> maps = MxMessageReader.getSwfMsgInfoViaMsg(str);
AbstractMX abstractMx = AbstractMX.parse(xmlStr);
......@@ -158,7 +159,7 @@ public class SwiftTransfer {
}
return maps;
} catch (DocumentException e) {
throw new SwiftException("ERROR", e.getMessage());
throw new SwiftException(e.getMessage());
}
}
......
......@@ -21,6 +21,11 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
protected Map<String, Object> maps = new LinkedHashMap<>();
/**
* MX103报文是否是单双报逻辑
*/
protected String doubleMessageFlag = "N";
public String getXmlStr() {
return xmlStr;
}
......@@ -37,6 +42,14 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
this.localCode = localCode;
}
public String getDoubleMessageFlag() {
return doubleMessageFlag;
}
public void setDoubleMessageFlag(String doubleMessageFlag) {
this.doubleMessageFlag = doubleMessageFlag;
}
protected String getPropertyValue(String key) {
return MessageUtil.getPropertyValue(localCode, key);
}
......@@ -104,6 +117,9 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
}
}
if (existFlag) {
if ("instgRmbrsmntAgt".equals(name) || "instdRmbrsmntAgt".equals(name)) {
doubleMessageFlag = "Y";
}
Map<String, Object> newMaps = new LinkedHashMap<>();
targetMaps.put(Mx2MtConstants.NEW_LINE + getPropertyValue(name+"Info"), newMaps);
for (String key : keys) {
......@@ -141,6 +157,9 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
}
}
if (existFlag) {
if ("instgRmbrsmntAgt".equals(name) || "instdRmbrsmntAgt".equals(name)) {
doubleMessageFlag = "Y";
}
Map<String, Object> newMaps = new LinkedHashMap<>();
targetMaps.put(Mx2MtConstants.NEW_LINE + getPropertyValue(subMapName), newMaps);
for (String key : keys) {
......@@ -195,6 +214,7 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
protected void buildInstgRmbrsmntAgtInfo(Map<String, Object> targetMaps, AbstractMT abstractMT) {
Tag tag = abstractMT.getSwiftMessage().getBlock4().getTagByName("53A");
if (tag != null) {
doubleMessageFlag = "Y";
Map<String, Object> newMaps = new LinkedHashMap<>();
targetMaps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("instgRmbrsmntAgtInfo"), newMaps);
Field53A field53A = (Field53A)tag.asField();
......@@ -209,6 +229,7 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName("53B");
if (tag != null) {
doubleMessageFlag = "Y";
Map<String, Object> newMaps = new LinkedHashMap<>();
targetMaps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("instgRmbrsmntAgtInfo"), newMaps);
Field53B field53B = (Field53B)tag.asField();
......
......@@ -42,12 +42,7 @@ public class Mx2MapPacs008Creator extends AbstractMx2MapCreator {
maps.put(getPropertyValue("uetr"), elementMaps.get("uetr"));
}
if (elementMaps.get("sttlmMtd") != null) {
String settlementMethod = (String) elementMaps.get("sttlmMtd");
if (SettlementMethodCode.COVE.value().equals(settlementMethod)) {
maps.put(getPropertyValue("settlement.method"), elementMaps.get("sttlmMtd") + "("+getPropertyValue("doubleMessage")+")");
} else {
maps.put(getPropertyValue("settlement.method"), elementMaps.get("sttlmMtd") + "("+getPropertyValue("simpleMessage")+")");
}
maps.put(getPropertyValue("settlement.method"), elementMaps.get("sttlmMtd"));
}
if (elementMaps.get("sttlmAcctIdIban") != null) {
maps.put(getPropertyValue("settlement.acct"), elementMaps.get("sttlmAcctIdIban"));
......@@ -130,6 +125,12 @@ public class Mx2MapPacs008Creator extends AbstractMx2MapCreator {
if (tag != null) {
maps.put(getPropertyValue("regulatoryReporting"), tag.getValue());
}
//判断MX103 是单报还是双报
if ("Y".equals(doubleMessageFlag)) {
maps.put(getPropertyValue("settlement.method"), elementMaps.get("sttlmMtd") + "("+getPropertyValue("doubleMessage")+")");
} else {
maps.put(getPropertyValue("settlement.method"), elementMaps.get("sttlmMtd") + "("+getPropertyValue("simpleMessage")+")");
}
return maps;
}
}
package com.brilliance.swift.util;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.constants.ERROR;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
......@@ -10,6 +11,8 @@ import com.prowidesoftware.swift.model.*;
import com.prowidesoftware.swift.model.field.*;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
......@@ -437,4 +440,24 @@ public class MxMessageReader {
throw new SwiftException(e.getMessage());
}
}
/**
* 如果传入的xml 没有报文头,导致dom4j无法解析
* 提取xml里面的AppHdr和Document,重新组装成有效的xml报文
*/
public static String handingXml(String xmlStr) {
boolean flag = true;
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
documentBuilder.parse(xmlStr);
} catch (Exception e) {
flag = false;
}
if (flag) { //如果是有效xml报文,直接返回
return xmlStr;
} else {
return SwiftTransfer.fetchXmlFromMixMessage(xmlStr);
}
}
}
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