0

I am pretty new to processing swift messages in java, I am trying with prowide-iso20022 software java library to parse the SwiftMX messages (https://github.com/prowide/prowide-iso20022)

I want to extract UETR (OrgnlUETR) of a message and other similar required information from the message, these field I think can be in different locations/hierarchy in xml for different type of message (i.e no common hierarchy). Need help in how to extract the required fields, since there are lot type of messages in SwiftMX

Below is the sample/dummy SwiftMX message for reference.

<SwiftMx>
    <Header>
        <DestinationID>ABC</DestinationID>
        <SenderID>PQR</SenderID>
        <OperationOrganizationID/>
        <MessageType>ISO22IN</MessageType>
        <DateSent>20200321</DateSent>
        <TimeSent>0829</TimeSent>
        <MessageID>3190eee</MessageID>
    </Header>
    <SubHeader>
        <ReceiverAddress>ZYDFUS562WW</ReceiverAddress>
        <SenderAddress>NCBACATEEE</SenderAddress>
    </SubHeader>
    <Body>
        <ISOMessage>
            <AppHdr>
                <Fr>
                    <FIId>
                        <FinInstnId>
                            <BICFI>NCBACATEEE</BICFI>
                        </FinInstnId>
                    </FIId>
                </Fr>
                <To>
                    <FIId>
                        <FinInstnId>
                            <BICFI>ZYDFUS562WW</BICFI>
                        </FinInstnId>
                    </FIId>
                </To>
                <BizMsgIdr>IMDLC6928</BizMsgIdr>
                <MsgDefIdr>camt.029.001.09</MsgDefIdr> 
                <BizSvc>swift.cbprplus.02</BizSvc>
                <CreDt>2010-09-31T04:49:45+03:00</CreDt>
            </AppHdr>
            <Document>
                <RsltnOfInvstgtn>
                    <Assgnmt>
                        <Id>IMDLC69S01</Id>
                        <Assgnr>
                            <Agt>
                                <FinInstnId>
                                    <BICFI>SNDRCAXX</BICFI>
                                </FinInstnId>
                            </Agt>
                        </Assgnr>
                        <Assgne>
                            <Agt>
                                <FinInstnId>
                                    <BICFI>SNDXX</BICFI>
                                </FinInstnId>
                            </Agt>
                        </Assgne>
                        <CreDtTm>2010-09-29T04:49:45+03:00</CreDtTm>
                    </Assgnmt>
                    <Sts>
                        <Conf>RJCR</Conf>
                    </Sts>
                    <CxlDtls>
                        <TxInfAndSts>
                            <CxlStsId>TESTID</CxlStsId>
                            <RslvdCase>
                                <Id>123</Id>
                                <Cretr>
                                    <Pty>
                                        <Nm>XYZ LTD</Nm>
                                        <Id>
                                            <OrgId>
                                                <AnyBIC>SNDRCAXXX</AnyBIC>
                                            </OrgId>
                                        </Id>
                                        <CtryOfRes>IN</CtryOfRes>
                                    </Pty>
                                </Cretr>
                            </RslvdCase>
                            <OrgnlGrpInf>
                                <OrgnlMsgId>YT123</OrgnlMsgId>
                                <OrgnlMsgNmId>IEUW79</OrgnlMsgNmId>
                            </OrgnlGrpInf>
                            <OrgnlUETR>9de-aed0-16487c27b42d</OrgnlUETR>
                        </TxInfAndSts>
                    </CxlDtls>
                </RsltnOfInvstgtn>
            </Document>
        </ISOMessage>
    </Body>
    <Timestamp>
        <Date>20200327</Date>
        <Time>123424</Time>
    </Timestamp>
</SwiftMx>
  1. Not able to parse using below abstract class, getting null returned from parse method parse into generic structure AbstractMX mx = AbstractMX.parse(xml);

  2. I want to know the type of message which I was able to extract using below code. MxSwiftMessage mxSwiftMessage = MxSwiftMessage.parse(xml); String msgDefIdr = ((BusinessAppHdrV01) mxSwiftMessage.getAppHdr()).getMsgDefIdr();
    But this is working only for AppHdr, not sure how to parse when we have differently structured messages.

1 Answers1

1

It looks like you're trying to parse an unknown SWIFT MX type message. In this case, you might want to look at the provided examples in the official Prowide ISO20022 Github repository, which can be found here. You'll also find community support there.

An example of parsing an unknown message type might look something like this:

public class MxParseUnknownMessageType {
    public static void main(String[] args) {
        String xml = "YOUR_XML_MESSAGE_HERE";
        // parse into generic structure
        AbstractMX mx = AbstractMX.parse(xml);
        System.out.println("Parsed message type: " + mx.getMxId().id());
        // check the parsed type and cast to specific model
        if ("camt.048.001.03".equals(mx.getMxId().id())) {
            MxCamt04800103 camt = (MxCamt04800103) mx;
            System.out.println("Message id: " + camt.getModfyRsvatn().getMsgHdr().getMsgId());
        }
    }
}

Just replace "YOUR_XML_MESSAGE_HERE" with your XML string.

This code will parse the XML into a generic SWIFT MX structure. It then checks the type of the message and, if it matches the given type ("camt.048.001.03"), it casts it to the specific model class and extracts the required fields.

For fields that could appear in different locations, you'd have to check the parsed message for different potential paths. Each SWIFT MX type message has its own model class, and the field locations are defined according to the SWIFT MX Message Standard.

In regard to retrieving the UETR:

The primary capabilities of the iso-20022 project include offering a Java model for ISO 20022 MX (for instance, the MxPacs00800109 class), facilitating parsing from XML to Java model and building from Java to XML. Additionally, it also enables conversion to JSON.

Given this, you have the option to employ a standard XML parser and adapt the XML message at any stage of your process. Similarly, you can transform the message into JSON and perform equivalent operations. However, if you choose to utilize the Java model, each message will be unique, necessitating thorough knowledge of the structure to access that value.

new MxPacs01000103().getFIDrctDbt().getCdtInstr().getDrctDbtTxInf().getPmtId().getUETR()

new MxPacs00800108().getFIToFICstmrCdtTrf().getCdtTrfTxInf().get(0).getPmtId().getUETR();

Hope this helps!

Pablo
  • 11
  • 2