Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
swiftMtMx
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
isc-v3.1-tmp
swiftMtMx
Commits
e61ee922
Commit
e61ee922
authored
Sep 28, 2022
by
chengzhuoshen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复mx2mt转换代码
parent
2ebeefb6
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
168 additions
and
9 deletions
+168
-9
SwiftTransfer.java
...ore/src/main/java/com/brilliance/swift/SwiftTransfer.java
+96
-2
AbstractMx2MtTagsGenerate.java
...com/brilliance/swift/mx2mt/AbstractMx2MtTagsGenerate.java
+5
-1
Mx2MtCreatorManager.java
.../java/com/brilliance/swift/mx2mt/Mx2MtCreatorManager.java
+24
-1
Field72Generate.java
...lliance/swift/mx2mt/mt202cov202/impl/Field72Generate.java
+2
-2
Field13DGenerate.java
...rilliance/swift/mx2mt/mt900910/impl/Field13DGenerate.java
+1
-1
Field61Generate.java
...brilliance/swift/mx2mt/mt941942/impl/Field61Generate.java
+2
-2
MT210.txt
swiftCore/src/main/resources/swiftTxt/MT210.txt
+10
-0
Mt2MxTest.java
swiftCore/src/test/java/com/brilliance/Mt2MxTest.java
+21
-0
MxXsdValidator.java
swiftCore/src/test/java/com/brilliance/MxXsdValidator.java
+7
-0
No files found.
swiftCore/src/main/java/com/brilliance/swift/SwiftTransfer.java
View file @
e61ee922
package
com
.
brilliance
.
swift
;
import
com.brilliance.swift.constants.Mx2MtConstants
;
import
com.brilliance.swift.exception.SwiftException
;
import
com.brilliance.swift.mt2mx.Mt2MxCreatorManager
;
import
com.brilliance.swift.mx2element.Mx2ElementCreatorManager
;
...
...
@@ -251,7 +252,7 @@ public class SwiftTransfer {
*/
public
static
boolean
validateMx
(
String
xml
)
{
//1.获取AppHdr报文内容,根据@xmlns获取版本对应的xsd文件
String
regex
=
"(\\<
AppHdr[\\w\\W]*\\<\\/
AppHdr\\>)"
;
String
regex
=
"(\\<
([\\w]*:)?AppHdr[\\w\\W]*\\<\\/([\\w]*:)?
AppHdr\\>)"
;
Pattern
p
=
Pattern
.
compile
(
regex
);
Matcher
m
=
p
.
matcher
(
xml
);
String
appHdrXml
=
""
;
...
...
@@ -271,7 +272,7 @@ public class SwiftTransfer {
SwiftTransferUtil
.
schemaValidate
(
appHdrXsdName
,
appHdrXml
);
}
//2.获取Document报文内容,根据@xmlns获取版本对应的xsd文件
regex
=
"(\\<
Document[\\w\\W]*\\<\\/
Document\\>)"
;
regex
=
"(\\<
([\\w]*:)?Document[\\w\\W]*\\<\\/([\\w]*:)?
Document\\>)"
;
p
=
Pattern
.
compile
(
regex
);
m
=
p
.
matcher
(
xml
);
String
documentXml
=
""
;
...
...
@@ -319,4 +320,97 @@ public class SwiftTransfer {
return
mx2Element
(
xmlFilePath
);
}
}
/**
* 从混合格式(MXMT)的报文中提取MX报文
* @param mixStr
* @return
*/
public
static
String
fetchXmlFromMixMessage
(
String
mixStr
)
{
String
regex
=
"(\\<([\\w]*:)?AppHdr[\\w\\W]*\\<\\/([\\w]*:)?AppHdr\\>)"
;
Pattern
p
=
Pattern
.
compile
(
regex
);
Matcher
m
=
p
.
matcher
(
mixStr
);
String
appHdrXml
=
""
;
if
(
m
.
find
())
{
appHdrXml
=
m
.
group
(
1
);
}
regex
=
"(\\<([\\w]*:)?Document[\\w\\W]*\\<\\/([\\w]*:)?Document\\>)"
;
p
=
Pattern
.
compile
(
regex
);
m
=
p
.
matcher
(
mixStr
);
String
documentXml
=
""
;
if
(
m
.
find
())
{
documentXml
=
m
.
group
(
1
);
}
return
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
+
Mx2MtConstants
.
NEW_LINE
+
"<RequestPayload>"
+
Mx2MtConstants
.
NEW_LINE
+
(
StringUtil
.
isNotEmpty
(
appHdrXml
)
?
appHdrXml
+
Mx2MtConstants
.
NEW_LINE
:
""
)
+
(
StringUtil
.
isNotEmpty
(
documentXml
)
?
documentXml
+
Mx2MtConstants
.
NEW_LINE
:
""
)
+
"</RequestPayload>"
;
}
public
static
String
fetchXmlFromMixMessage
(
File
mixFile
)
{
try
{
String
mixStr
=
FileUtils
.
readFileToString
(
mixFile
);
return
fetchXmlFromMixMessage
(
mixStr
);
}
catch
(
IOException
e
)
{
throw
new
SwiftException
(
e
.
getMessage
());
}
}
public
static
String
fetchXmlFromMixMessage
(
String
mixFilePath
,
boolean
filePathFlag
)
{
if
(
filePathFlag
)
{
File
mixFile
=
new
File
(
mixFilePath
);
return
fetchXmlFromMixMessage
(
mixFile
);
}
else
{
return
fetchXmlFromMixMessage
(
mixFilePath
);
}
}
/**
* 从混合格式(MXMT)的报文中提取MT报文
* @param mixStr
* @return
*/
public
static
String
fetchFinFromMixMessage
(
String
mixStr
)
{
String
regex
=
"<!--(.*?)-->"
;
Pattern
p
=
Pattern
.
compile
(
regex
,
Pattern
.
CASE_INSENSITIVE
|
Pattern
.
DOTALL
);
Matcher
m
=
p
.
matcher
(
mixStr
);
String
mt
=
""
;
while
(
m
.
find
())
{
String
message
=
m
.
group
(
1
);
if
(
message
.
indexOf
(
"{4:"
)
>
-
1
)
{
mt
=
message
;
}
}
mt
=
mt
.
trim
().
replace
(
"^~"
,
Mx2MtConstants
.
NEW_LINE
);
//去掉首行空格
String
[]
mts
=
mt
.
split
(
Mx2MtConstants
.
NEW_LINE
);
mt
=
""
;
for
(
int
i
=
0
;
i
<
mts
.
length
;
i
++)
{
mt
+=
mts
[
i
].
trim
();
if
(
i
<
(
mts
.
length
-
1
))
{
mt
+=
Mx2MtConstants
.
NEW_LINE
;
}
}
return
mt
;
}
public
static
String
fetchFinFromMixMessage
(
File
mixFile
)
{
try
{
String
mixStr
=
FileUtils
.
readFileToString
(
mixFile
);
return
fetchFinFromMixMessage
(
mixStr
);
}
catch
(
IOException
e
)
{
throw
new
SwiftException
(
e
.
getMessage
());
}
}
public
static
String
fetchFinFromMixMessage
(
String
mixFilePath
,
boolean
filePathFlag
)
{
if
(
filePathFlag
)
{
File
mixFile
=
new
File
(
mixFilePath
);
return
fetchFinFromMixMessage
(
mixFile
);
}
else
{
return
fetchFinFromMixMessage
(
mixFilePath
);
}
}
}
swiftCore/src/main/java/com/brilliance/swift/mx2mt/AbstractMx2MtTagsGenerate.java
View file @
e61ee922
...
...
@@ -2293,7 +2293,11 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
}
else
if
(
isAllowedClearingChannel
&&
"RTGS"
.
equals
(
clearingChannal
)){
partyIdentifier
=
mx_to_mtClearingIdentifierAndChannel
(
agentPath
,
clearingChannelPath
);
}
tag
=
new
Tag
(
tagName
+
"D"
,
partyIdentifier
+
Mx2MtConstants
.
NEW_LINE
+
nameAndAddress
);
if
(
StringUtil
.
isEmpty
(
partyIdentifier
))
{
tag
=
new
Tag
(
tagName
+
"D"
,
nameAndAddress
);
}
else
{
tag
=
new
Tag
(
tagName
+
"D"
,
partyIdentifier
+
Mx2MtConstants
.
NEW_LINE
+
nameAndAddress
);
}
}
return
tag
;
}
...
...
swiftCore/src/main/java/com/brilliance/swift/mx2mt/Mx2MtCreatorManager.java
View file @
e61ee922
package
com
.
brilliance
.
swift
.
mx2mt
;
import
com.brilliance.swift.SwiftTransfer
;
import
com.brilliance.swift.constants.Mx2MtConstants
;
import
com.brilliance.swift.exception.SwiftException
;
import
com.brilliance.swift.mx2mt.mt103.Mx2Mt103Creator
;
...
...
@@ -23,13 +24,15 @@ import org.dom4j.Document;
import
org.dom4j.DocumentException
;
import
org.dom4j.DocumentHelper
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
java.util.Map
;
public
class
Mx2MtCreatorManager
{
public
SwiftTranslationReport
mx2Mt
(
String
xml
,
String
fileOutputPath
,
Map
<
String
,
Object
>
extraMap
)
throws
SwiftException
{
try
{
Document
document1
=
DocumentHelper
.
parseText
(
xml
);
xml
=
handlingXml
(
xml
);
AbstractMX
abstractMX
=
AbstractMX
.
parse
(
xml
);
String
messageType
=
(
abstractMX
.
getMxId
().
getBusinessProcess
().
name
()
+
"."
...
...
@@ -145,4 +148,24 @@ public class Mx2MtCreatorManager {
}
return
messageType
;
}
/**
* 如果传入的xml 没有报文头,导致dom4j无法解析
* 提取xml里面的AppHdr和Document,重新组装成有效的xml报文
*/
private
String
handlingXml
(
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
);
}
}
}
swiftCore/src/main/java/com/brilliance/swift/mx2mt/mt202cov202/impl/Field72Generate.java
View file @
e61ee922
...
...
@@ -110,8 +110,8 @@ public class Field72Generate extends AbstractMx2MtTagsGenerate {
mt72List
.
addAll
(
mtCreditorAgts
);
}
//参数6
String
mxPurposeCode
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"
.
CdtTrfTxInf.Purp.Cd"
);
String
mxPurposeProprietary
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"
.
CdtTrfTxInf.Purp.Prtry"
);
String
mxPurposeCode
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"CdtTrfTxInf.Purp.Cd"
);
String
mxPurposeProprietary
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"CdtTrfTxInf.Purp.Prtry"
);
if
(
StringUtil
.
isNotEmpty
(
mxPurposeProprietary
))
{
mt72List
.
add
(
"/PURP/"
+
mxPurposeProprietary
);
}
else
if
(
StringUtil
.
isNotEmpty
(
mxPurposeCode
))
{
...
...
swiftCore/src/main/java/com/brilliance/swift/mx2mt/mt900910/impl/Field13DGenerate.java
View file @
e61ee922
...
...
@@ -21,7 +21,7 @@ public class Field13DGenerate extends AbstractMx2MtTagsGenerate {
try
{
SwiftMessage
swiftMessage
=
context
.
get
(
SwiftMessage
.
class
);
List
<
Tag
>
tags
=
swiftMessage
.
getBlock4
().
getTags
();
String
bookDateStr
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"Ntfctn.Ntry.BookgDt"
);
String
bookDateStr
=
getXmlNodeValue
(
bodyHdrParentElementName
,
document
,
"Ntfctn.Ntry.BookgDt
.DtTm
"
);
if
(
StringUtil
.
isNotEmpty
(
bookDateStr
))
{
SimpleDateFormat
fmt
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss"
);
Date
bookDate
=
fmt
.
parse
(
bookDateStr
);
...
...
swiftCore/src/main/java/com/brilliance/swift/mx2mt/mt941942/impl/Field61Generate.java
View file @
e61ee922
...
...
@@ -70,9 +70,9 @@ public class Field61Generate extends AbstractMx2MtTagsGenerate {
value
+=
"C"
;
}
}
}
else
if
(
EntryStatusCode
.
FUTR
.
value
().
equals
(
code
)
}
else
/*
if(EntryStatusCode.FUTR.value().equals(code)
|| EntryStatusCode.PDNG.value().equals(code)
||
EntryStatusCode
.
INFO
.
value
().
equals
(
code
)){
|| EntryStatusCode.INFO.value().equals(code))
*/
{
if
(
CdtDbtCode
.
DBIT
.
value
().
equals
(
creditDebitIndicator
))
{
value
+=
"ED"
;
}
else
{
...
...
swiftCore/src/main/resources/swiftTxt/MT210.txt
0 → 100644
View file @
e61ee922
{1:F01PSBCCNBJAXXX0000000000}{2:I210MSBCCNBJXXXXN}{3:{108:ZJQS01795275}}{4:
:20:QSM2105301108867
:25:301010467795
:30:211111
:21:QST2105301108866
:32B:EUR111111,00
:52A:PSBCCNBJXXX
:56A:DEUTDEFFXXX
-}
\ No newline at end of file
swiftCore/src/test/java/com/brilliance/Mt2MxTest.java
View file @
e61ee922
...
...
@@ -55,4 +55,25 @@ public class Mt2MxTest {
public
void
testCamt053001
()
{
test
(
"/swiftTxt/MT950.txt"
,
null
);
}
@Test
public
void
testCamt054001
()
{
test
(
"/swiftTxt/MT910.txt"
,
null
);
}
@Test
public
void
testCamt056001_1
()
{
test
(
"/swiftTxt/MT192.txt"
,
null
);
}
@Test
public
void
testCamt029001_1
()
{
test
(
"/swiftTxt/MT196.txt"
,
null
);
}
@Test
public
void
testCamt057001
()
{
test
(
"/swiftTxt/MT210.txt"
,
null
);
}
}
swiftCore/src/test/java/com/brilliance/MxXsdValidator.java
View file @
e61ee922
...
...
@@ -5,6 +5,7 @@ import org.apache.commons.io.FileUtils;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.IOException
;
public
class
MxXsdValidator
{
...
...
@@ -14,4 +15,10 @@ public class MxXsdValidator {
boolean
flag
=
SwiftTransfer
.
validateMx
(
file
);
System
.
out
.
println
(
flag
);
}
@Test
public
void
test
()
throws
IOException
{
File
file
=
FileUtils
.
toFile
(
Mx2MtTest
.
class
.
getResource
(
"/swiftXml/MxPacs00800108.xml"
));
System
.
out
.
println
(
SwiftTransfer
.
fetchFinFromMixMessage
(
file
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment