Commit 67f5ec3e by chengzhuoshen

增加pacs00900108.xsd,pacs00400109.xsd,pacs00200110.xsd文件,并测试校验对应的报文

parent ce5d7794
...@@ -6,6 +6,7 @@ import com.brilliance.swift.mx2map.Mx2MapCreatorManager; ...@@ -6,6 +6,7 @@ import com.brilliance.swift.mx2map.Mx2MapCreatorManager;
import com.brilliance.swift.mx2mt.Mx2MtCreatorManager; import com.brilliance.swift.mx2mt.Mx2MtCreatorManager;
import com.brilliance.swift.swiftdto2mx.SwiftDto2MxCreatorManager; import com.brilliance.swift.swiftdto2mx.SwiftDto2MxCreatorManager;
import com.brilliance.swift.util.StringUtil; import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.brilliance.swift.util.XmlUtil; import com.brilliance.swift.util.XmlUtil;
import com.brilliance.swift.vo.SwiftDto; import com.brilliance.swift.vo.SwiftDto;
import com.prowidesoftware.swift.model.MxId; import com.prowidesoftware.swift.model.MxId;
...@@ -15,17 +16,9 @@ import org.apache.commons.io.FileUtils; ...@@ -15,17 +16,9 @@ import org.apache.commons.io.FileUtils;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.xml.sax.SAXException;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.regex.Matcher; import java.util.regex.Matcher;
...@@ -148,7 +141,7 @@ public class SwiftTransfer { ...@@ -148,7 +141,7 @@ public class SwiftTransfer {
+ appHdrMxId.getVersion(); + appHdrMxId.getVersion();
} }
if (StringUtil.isNotEmpty(appHdrXsdName) && StringUtil.isNotEmpty(appHdrXml)) { if (StringUtil.isNotEmpty(appHdrXsdName) && StringUtil.isNotEmpty(appHdrXml)) {
schemaValidate(appHdrXsdName, appHdrXml); SwiftTransferUtil.schemaValidate(appHdrXsdName, appHdrXml);
} }
//2.获取Document报文内容,根据@xmlns获取版本对应的xsd文件 //2.获取Document报文内容,根据@xmlns获取版本对应的xsd文件
regex = "(\\<Document[\\w\\W]*\\<\\/Document\\>)"; regex = "(\\<Document[\\w\\W]*\\<\\/Document\\>)";
...@@ -168,31 +161,13 @@ public class SwiftTransfer { ...@@ -168,31 +161,13 @@ public class SwiftTransfer {
+ documentMxId.getVersion(); + documentMxId.getVersion();
} }
if (StringUtil.isNotEmpty(documentXsdName) && StringUtil.isNotEmpty(documentXml)) { if (StringUtil.isNotEmpty(documentXsdName) && StringUtil.isNotEmpty(documentXml)) {
schemaValidate(documentXsdName, documentXml); SwiftTransferUtil.schemaValidate(documentXsdName, documentXml);
} }
return true; return true;
} }
public static void schemaValidate(String xsdName, String xml) {
try {
//建立schema工厂
SchemaFactory schemaFactory = SchemaFactory
.newInstance("http://www.w3.org/2001/XMLSchema");
URL url = SwiftTransfer.class.getResource("/xsd/"+xsdName+".xsd");
//利用schema工厂,接收验证文档文件对象生成Schema对象
Schema schema = schemaFactory.newSchema(url);
// 开始验证
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))));
} catch (SAXException e) {
throw new SwiftException("Error", e.getMessage());
} catch (IOException e) {
throw new SwiftException("Error", e.getMessage());
}
}
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxPacs00800108.xml"); File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxPacs00200110_Pacs009.xml");
String xmlStr = FileUtils.readFileToString(file); String xmlStr = FileUtils.readFileToString(file);
validateMx(xmlStr); validateMx(xmlStr);
} }
......
...@@ -12,9 +12,9 @@ public class SwiftException ...@@ -12,9 +12,9 @@ public class SwiftException
private Exception exception; private Exception exception;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public SwiftException(String id) { public SwiftException(String message) {
super(); super();
this.id = id; this.message = message;
} }
public SwiftException(String id, String message) { public SwiftException(String id, String message) {
......
...@@ -2,15 +2,25 @@ package com.brilliance.swift.util; ...@@ -2,15 +2,25 @@ package com.brilliance.swift.util;
import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.vo.MxMtReasonCodeInfo; import com.brilliance.swift.vo.MxMtReasonCodeInfo;
import com.brilliance.swift.vo.SwiftTransferErrorInfo; import com.brilliance.swift.vo.SwiftTransferErrorInfo;
import com.brilliance.swift.vo.common.*; import com.brilliance.swift.vo.common.*;
import org.xml.sax.SAXException;
import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -757,4 +767,25 @@ public class SwiftTransferUtil { ...@@ -757,4 +767,25 @@ public class SwiftTransferUtil {
} }
return flag; return flag;
} }
public static void schemaValidate(String xsdName, String xml) {
try {
//建立schema工厂
SchemaFactory schemaFactory = SchemaFactory
.newInstance("http://www.w3.org/2001/XMLSchema");
URL url = SwiftTransferUtil.class.getResource("/xsd/"+xsdName+".xsd");
if (url == null) {
throw new SwiftException("找不到对应的schema文件-"+xsdName+".xsd");
}
//利用schema工厂,接收验证文档文件对象生成Schema对象
Schema schema = schemaFactory.newSchema(url);
// 开始验证
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))));
} catch (SAXException e) {
throw new SwiftException("Validate " + xsdName + ".xsd Error;" + e.getMessage());
} catch (IOException e) {
throw new SwiftException("Validate " + xsdName + ".xsd Error;" + e.getMessage());
}
}
} }
...@@ -60,7 +60,7 @@ Change Log ...@@ -60,7 +60,7 @@ Change Log
<CreDtTm>2020-01-11T13:00:00.960-05:00</CreDtTm> <CreDtTm>2020-01-11T13:00:00.960-05:00</CreDtTm>
<NbOfTxs>1</NbOfTxs> <NbOfTxs>1</NbOfTxs>
<SttlmInf> <SttlmInf>
<SttlmMtd>INGA</SttlmMtd> <SttlmMtd>INGA</SttlmMtd>
</SttlmInf> </SttlmInf>
</GrpHdr> </GrpHdr>
<TxInf> <TxInf>
...@@ -73,7 +73,7 @@ Change Log ...@@ -73,7 +73,7 @@ Change Log
<OrgnlUETR>174c245f-2682-4291-ad67-2a41e530cd27</OrgnlUETR> <OrgnlUETR>174c245f-2682-4291-ad67-2a41e530cd27</OrgnlUETR>
<OrgnlIntrBkSttlmAmt Ccy="USD">39980</OrgnlIntrBkSttlmAmt> <OrgnlIntrBkSttlmAmt Ccy="USD">39980</OrgnlIntrBkSttlmAmt>
<OrgnlIntrBkSttlmDt>2020-01-11</OrgnlIntrBkSttlmDt> <OrgnlIntrBkSttlmDt>2020-01-11</OrgnlIntrBkSttlmDt>
<RtrdIntrBkSttlmAmt Ccy="USD">39980</RtrdIntrBkSttlmAmt> <RtrdIntrBkSttlmAmt Ccy="USD">39980</RtrdIntrBkSttlmAmt>
<IntrBkSttlmDt>2020-01-11</IntrBkSttlmDt> <IntrBkSttlmDt>2020-01-11</IntrBkSttlmDt>
<ChrgBr>SHAR</ChrgBr> <ChrgBr>SHAR</ChrgBr>
<InstgAgt> <InstgAgt>
......
...@@ -53,12 +53,13 @@ Change Log ...@@ -53,12 +53,13 @@ Change Log
<CreDt>2021-05-03T12:45:41.960+00:00</CreDt> <CreDt>2021-05-03T12:45:41.960+00:00</CreDt>
</Rltd> </Rltd>
</AppHdr> </AppHdr>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.004.001.09"> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:pacs.004.001.09">
<PmtRtr> <PmtRtr>
<GrpHdr> <GrpHdr>
<MsgId>P4C2B-005</MsgId> <MsgId>P4C2B-005</MsgId>
<CreDtTm>2021-05-03T13:00:41.960+00:00</CreDtTm> <CreDtTm>2021-05-03T13:00:41.960+00:00</CreDtTm>
<NbOfTxs>1</NbOfTxs> <NbOfTxs>1</NbOfTxs>
<GrpRtr>true</GrpRtr>
<SttlmInf> <SttlmInf>
<SttlmMtd>INGA</SttlmMtd> <SttlmMtd>INGA</SttlmMtd>
</SttlmInf> </SttlmInf>
...@@ -78,9 +79,19 @@ Change Log ...@@ -78,9 +79,19 @@ Change Log
<ChrgBr>SHAR</ChrgBr> <ChrgBr>SHAR</ChrgBr>
<ChrgsInf> <ChrgsInf>
<Amt Ccy="GBP">1000</Amt> <Amt Ccy="GBP">1000</Amt>
<Agt>
<FinInstnId>
<BICFI>CHASGB2LXXX</BICFI>
</FinInstnId>
</Agt>
</ChrgsInf> </ChrgsInf>
<ChrgsInf> <ChrgsInf>
<Amt Ccy="GBP">980</Amt> <Amt Ccy="GBP">980</Amt>
<Agt>
<FinInstnId>
<BICFI>CHASGB2LXXX</BICFI>
</FinInstnId>
</Agt>
</ChrgsInf> </ChrgsInf>
<InstgAgt> <InstgAgt>
<FinInstnId> <FinInstnId>
......
...@@ -37,7 +37,7 @@ Change Log ...@@ -37,7 +37,7 @@ Change Log
<FICdtTrf> <FICdtTrf>
<GrpHdr> <GrpHdr>
<MsgId>pacs9bizmsgidr02</MsgId> <MsgId>pacs9bizmsgidr02</MsgId>
<CreDtTm>2021-05-17T10:23:41.00+01:00</CreDtTm> <CreDtTm>2021-05-17T10:23:41.00+00:00</CreDtTm>
<NbOfTxs>1</NbOfTxs> <NbOfTxs>1</NbOfTxs>
<SttlmInf> <SttlmInf>
<SttlmMtd>INDA</SttlmMtd> <SttlmMtd>INDA</SttlmMtd>
......
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