Rajiv
Rajiv

Reputation: 51

SWIFT MT Message Parsing using WIFE Java library

I am using the WIFE Java library to parse SWIFT messages into JSON format.

For messages that are "Output from Swift", it contains repeated blocks in the header for {1:..} and {4..} as part of acknowledgement. While parsing the message, there is no output/error thrown. How can this be handled?

Also, if I use the library function for respective MT class for say field 50k for MT103 and call a function say getcomponent1() or getName&Address1(), will it return the right value for this message with repeated 1 and 4 blocks?

Sample MT103 pasted below:

{1:F21XXXXXXBBAXXX9735415014}{4:{177:1410291057}{451:0}}{1:F01XXXXXNBBAXXX9735415014}{2:O1031057141029XXXXXNBBAXXX16235602381410291057U}{4:

:20:2039TT20W4407225

:23B:CRED

:32A:141029AUD844,00

:33B:AUD844,00

:50K:/XXXXXXXXXXXX XXXXXXXX

ABC LAW FIRM PTY LTD

19 MOORE STREET

TURNER

:52A:XXXXINBBXXX

:53A:NATAAU33

:57A:XXXXXNBBXXX

:59:/200006547541

ABC TECHNOLOGY SOLUTIONS PVT LT

LEVEL 2 BLOCK 1 TRANSASIA CORPORATE

PARK KAKKANAD

:70:ONLY BENEFICIARY BANK IS AUTHORIZED

TO CONVERT THE CURRENCY

:71A:OUR

:72:/REC/DAG29102014117

//INCOMPLETE INSTRUCTION PURPOSE CO

//DE CHARGES AUD 20 DEDUCTED

-}{5:{MAC:00000000}{CHK:8A860CBABFFD}}{S:{SAC:}{COP:S}}

Upvotes: 5

Views: 8441

Answers (2)

Sebastian Zubrinic
Sebastian Zubrinic

Reputation: 758

Another example for the same:

final String fin = "{1:F21FOOLHKH0AXXX0304009999}{4:{177:1608140809}{451:0}}{1:F01FOOLHKH0AXXX0304009999}{2:O9401609160814FOOLHKH0AXXX03040027341608141609N}{4:\n"+
            ":20:USD940NO1\n"+
            (...)
            "-}{5:{CHK:0FEC1E4AEC53}{TNG:}}{S:{COP:S}}";

        final SwiftParser parser = new SwiftParser();
        SwiftMessage sm = parser.parse(fin);
        if (StringUtils.equals(sm.getBlock1().getServiceId(), "21") && sm.getUnparsedTextsSize() > 0) {
            sm = sm.getUnparsedTexts().getTextAsMessage(0);
        }

        System.out.println("Message Type: "+ sm.getType());
        if (sm.isType(940)) {
            /*
             * Specialize the message to its specific model representation
             */
            MT940 mt = new MT940(sm);

            /*
             * Print details of a specific field
             */
            System.out.println("Reference: "+mt.getField20().getValue());
        }

Upvotes: 0

darioo
darioo

Reputation: 47203

The behaviour you're seeing is by design.

WIFE library will try to parse as much as possible of your input, until it detects that the rest of the input is no longer part of a single valid SWIFT message.

In your case,

{1:F21XXXXXXBBAXXX9735415014}{4:{177:1410291057}{451:0}}

is one valid SWIFT message. Everything after that is another valid SWIFT message, but the WIFE parser won't bother with it because it detects that there is no SWIFT block 5 after block 4 (as per the SWIFT standard), so it just treats the rest of the message as unparsed text.

Assuming input is your whole input string, you should have code similar to this:

IConversionService ics = new ConversionService();
SwiftMessage sm = ics.getMessageFromFIN(input);

Afterwards, you can check with

Integer unparsedSize = sm.getUnparsedTextsSize();

that you have one unparsed message and you can do whatever you want with it. In your case, you can retreive the unparsed part like this:

String unparsedInput = sm.getUnparsedTexts().getText(0);
SwiftMessage sm2 = ics.getMessageFromFIN(unparsedInput);

Now, sm2 is the real SWIFT message you're after, the one that starts with

{1:F01XXXXXNBBAXXX9735415014}{2:O103...

Do what you want with it and treat it as a separate message from the one in sm.

Now that you know how to parse everything correctly, you don't have to worry about the rest of your questions.

Upvotes: 3

Related Questions