How do I pack an ISO 8583 message?

The code snippet below show you how to pack an ISO 8583 message.

package org.kodejava.jpos;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.packager.GenericPackager;


public class PackISOMessage {
    public static void main(String[] args) {
        PackISOMessage iso = new PackISOMessage();
        try {
            String message = iso.buildISOMessage();
            System.out.printf("Message = %s", message);
        } catch (Exception e) {

    private String buildISOMessage() throws Exception {
        try {
            // Load package from resources directory.
            InputStream is = getClass().getResourceAsStream("/fields.xml");
            GenericPackager packager = new GenericPackager(is);

            ISOMsg isoMsg = new ISOMsg();

            isoMsg.set(3, "000010");
            isoMsg.set(4, "1500");
            isoMsg.set(7, "1206041200");
            isoMsg.set(11, "000001");
            isoMsg.set(41, "12340001");
            isoMsg.set(49, "840");

            byte[] result = isoMsg.pack();
            return new String(result);
        } catch (ISOException e) {
            throw new Exception(e);

    private void printISOMessage(ISOMsg isoMsg) {
        try {
            System.out.printf("MTI = %s%n", isoMsg.getMTI());
            for (int i = 1; i <= isoMsg.getMaxField(); i++) {
                if (isoMsg.hasField(i)) {
                    System.out.printf("Field (%s) = %s%n", i, isoMsg.getString(i));
        } catch (ISOException e) {

When you run the program you’ll get the following output:

MTI = 0200
Field (3) = 000010
Field (4) = 1500
Field (7) = 1206041200
Field (11) = 000001
Field (41) = 12340001
Field (49) = 840
Message = 02003220000000808000000010000000001500120604120000000112340001840

The xml packager (fields.xml) can be downloaded from the following link: fields.xml.

Maven Dependency


Maven Central



  1. I get error:

    at com.mycompany.mavenproject2.PackISOMessage.buildISOMessage(
        at com.mycompany.mavenproject2.PackISOMessage.main(
    • java.lang.Exception: org.jpos.iso.ISOException: (
          at com.mycompany.mavenproject2.PackISOMessage.buildISOMessage(
          at com.mycompany.mavenproject2.PackISOMessage.main(
      Caused by: org.jpos.iso.ISOException: (
    • Hi Tony,

      I think the error because it cannot find the fields.xml file. I am using Maven, in this case I place the fields.xml file inside the resources directory (src/main/resources/fields.xml).

      Instead of loading the packager file as a resource you can also do something like this:

      String filename = "D:/jpos/fields.xml";
      GenericPackager packager = new GenericPackager(filename);
  2. I created a project named mavenproject2 and placed the fields.xml in cfg/packager but the error still there.

    InputStream is = getClass().getResourceAsStream("mavenproject2/cfg/packager/fields.xml");
    GenericPackager packager = new GenericPackager(is);
  3. Error while compiling sample ISO Message Program:

    Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jpos/iso/ISOException : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(
        at Method)
        at java.lang.ClassLoader.loadClass(
        at sun.misc.Launcher$AppClassLoader.loadClass(
        at java.lang.ClassLoader.loadClass(
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(
        at java.lang.Class.getMethod0(
        at java.lang.Class.getMethod(
        at sun.launcher.LauncherHelper.getMainMethod(
        at sun.launcher.LauncherHelper.checkAndLoadMain(
  4. Hi,

    We are getting response but that response we pass to the parseISoData using “iso87ascii.xml” so we are are not getting proper field data 62 and 63 can please help us.

      • public void parseISoData(String data) throws ISOException, IOException {
            CustomXmlReader packager;
            InputStream inputstream = getApplicationContext().getAssets().open("iso87ascii.xml");
            packager = new CustomXmlReader(inputstream);
            ISOMsg isoMsg = new ISOMsg();
            // print the DE list
      • 00b2600000004108102038010002c0000692000014927514512207220041303038303030303036382020202020202020202020202020200085894f96d55d7421d9000000000000000054455354494e47205445414d205448414e4520202020205448414e452020202020202020204d48202020202020202020202020202020202020202020202020202020202020003600344b50894f96d55d7421d9ef349aa6cc0fe6173f03e4ce8dcaa3a9d62e12b21ff3c32d

    • Hi Sonali,

      I found that your message doesn’t contain the MTI information and also are you correctly calculate the message bitmap and supply the content for data element 62 and 63 in your message?

  5. MTI 0810, if we are parsing the data in parseIsoData method using (“iso87ascii.xml”); but we are not getting the proper data element 62 and 63.

      • 00b2 length
        6000000041 header
        0810 MTI
        2038010002c00006 Bitmap
        920000 processing
        683279 stan
        1129030722 date and time
        0041 nii
        3030 respose code
        3830303030303638 TID
        202020202020202020202020202020 MID

    • Hi Sonali,

      I am processing the following message:


      I remove the length (00b2) and the header (6000000041). And here is the result I got:

      MTI = 0810
      Field (3) = 920000
      Field (11) = 683279
      Field (12) = 112903
      Field (13) = 0722
      Field (24) = 004
      Field (39) = 13
      Field (41) = 03038303
      Field (42) = 030303036382020
      Field (62) = 0202020202020202020202000859bcb28c2e08d11ee000000000000000054455354494e47205445414d205448414e4520202020205448414e452020202020202020204d4820202020202020202020202020202020202020202020202020202020202000360
      Field (63) = 4b509bcb28c2e08d11eebbe04de6eb78a7
    • Hi, Sonali, based on the last example of message break down you have modified the iso87ascii.xml right? And for the data element 62 and 63 make sure you add the correct length of the data element contents. Field 62 and 63 type is IFA_LLLCHAR it means that the message if prefixed with three digits length. For example 00859bcb28c, 008 is the length and 59bcb28c is the data.

  6. Hi , I am using this parser for long. It works fine when the bitmap is readable. But when the bitmap comes in non-readable format in ASCII, I am unable to get the bitmap bytes and unpack the iso msg . can u help

  7. Hi Wayan,

    Can you please help on how to add the SSL certificated if any host requires, how can we implement this in above code?

  8. Hi Wayan .. Can you pls help me resolve below error. I am using the same code and fields.xml file
    java.lang.Exception: org.jpos.iso.ISOException: org.xml.sax.SAXParseException; systemId: file:///c:/Users/apochir/Desktop/Logs/fields.xml; lineNumber: 3; columnNumber: 13; Document is invalid: no grammar found. (org.xml.sax.SAXParseException; systemId: file:///c:/Users/apochir/Desktop/Logs/fields.xml; lineNumber: 3; columnNumber: 13; Document is invalid: no grammar found.)
    at com.test.PackISOMessage.buildISOMessage(
    at com.test.PackISOMessage.main(


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.