AlexanderTest
AlexanderTest

Reputation: 43

How to parse a hex iso8583 line?

here is the code:

import org.jpos.iso.packager.ISO87BPackager;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;

public class ParseISOMsg {
    public static void main(String[] args) throws ISOException {
        String hexmsg = "3038313082200000020000000400000000000000111312532012345630300301";
        // convert hex string to byte array
        byte[] bmsg =ISOUtil.hex2byte(hexmsg);
        ISOMsg m = new ISOMsg();
        // set packager, change ISO87BPackager for the matching one.
        m.setPackager(new ISO87BPackager());
        //unpack the message using the packager
        m.unpack(bmsg);
        //dump the message to standar output
        m.dump(System.out, "");
    }
}

now an exception is issued:

Exception in thread "main" org.jpos.iso.ISOException: org.jpos.iso.IFB_NUMERIC: Problem unpacking field 23 (java.lang.ArrayIndexOutOfBoundsException: 32) unpacking field=23, consumed=31
    at org.jpos.iso.ISOBasePackager.unpack(ISOBasePackager.java:340)
    at org.jpos.iso.ISOMsg.unpack(ISOMsg.java:468)
    at ParseISOMsg.main(ParseISOMsg.java:17)

Tell me why I can’t distribute this line - 3038313082200000020000000400000000000000111312532012345630300301 ?

Upvotes: 4

Views: 1927

Answers (1)

apr
apr

Reputation: 1343

This seems to be a weird packager that uses BCD to encode most fields, but ASCII to encode the MTI. I suggest you create your own field packager based on iso87binary.xml. You want to change field 0 definition from IFB_NUMERIC to IFA_NUMERIC, then you'll get something like this:

<isomsg>
  <field id="0" value="0810"/>
  <field id="7" value="1113125320"/>
  <field id="11" value="123456"/>
  <field id="39" value="00"/>
  <field id="70" value="301"/>
</isomsg>

In order to create your packager, you want to use code like this:

ISOPackager p = new GenericPackager("yourpackager.xml");

Upvotes: 5

Related Questions