Skip to content



ISO 8583 Tutorial – Build and Parse ISO Message using JPOS library



05 May 20121 comment Java Posts

4,341 Total Views

JPOs printed clone legs

OK after my article about ISO 8583 let’s go deeper into programming using Java + JPOS library.

Quote from JPOS website:

jPOS is a Java® platform-based, mission-critical, ISO-8583 based financial transaction library/framework that can be customized and extended in order to implement financial interchanges.

So first thing to do is download JPOS from it website.

Then we setup our development environment by creating Java Project using your favorites IDE. Add to the project all jar in JPOS library.
Here’s my Eclipse package explorer looks like.

package explorer

package explorer

Create Data Elements (DE) types XML

Like I said that ISO 8583 is a ’standard’ which mean can be different between one implementation and another :D
To put it simple, although there’s a (some) standard for DE list sometime we need to change it.
Either way, we need to tell JPOS how our DE will be formatted or packaged.

Since in the complete XML there’s 128 DE, I’ll quote only the DE # we used. Full xml can be downloaded here (basic.xml)



  MESSAGE TYPE INDICATOR"
      class="org.jpos.iso.IFA_NUMERIC"/>

The XML should easily understand in each isofield tag we define:

  • id : the DE number
  • length : the max/fixed length of the DE
  • name : yes, it’s the name or description
  • class : this define the type of the DE, which in this case represent by the JPOS class. You can see the whole class list here. I only list some of it.
    • IFA_NUMERIC : Numeric – Left padder with zeros.
    • IFA_BITMAP : For ISO Bitmap
    • IFA_LLCHAR : ASCII variable len CHAR – 2 digit length info
    • IFA_LLLCHAR : ASCII variable len CHAR – 3 digit length info

So this XML will be used for build (pack) ISO Message or parse (unpack) ISO Message.

You will need the XML data schema (genericpackager.dtd) to be put on same directory with basic.xml

Build (pack) ISO Message

Below is the code. The code is quite straight forward, review it first and I’ll discuss a bit afterward.

package gnu.jimmod.iso8583.utility;

import java.io.IOException;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.packager.GenericPackager;

public class BuildISOMessage {

	public static void main(String[] args) throws IOException, ISOException {
		// Create Packager based on XML that contain DE type
		GenericPackager packager = new GenericPackager("basic.xml");

		// Create ISO Message
		ISOMsg isoMsg = new ISOMsg();
		isoMsg.setPackager(packager);
		isoMsg.setMTI("0200");
		isoMsg.set(3, "201234");
		isoMsg.set(4, "10000");
		isoMsg.set(7, "110722180");
		isoMsg.set(11, "123456");
		isoMsg.set(44, "A5DFGR");
		isoMsg.set(105, "ABCDEFGHIJ 1234567890");

		// print the DE list
		logISOMsg(isoMsg);

		// Get and print the output result
		byte[] data = isoMsg.pack();
		System.out.println("RESULT : " + new String(data));
	}

	private static void logISOMsg(ISOMsg msg) {
		System.out.println("----ISO MESSAGE-----");
		try {
			System.out.println("  MTI : " + msg.getMTI());
			for (int i=1;i<=msg.getMaxField();i++) {
				if (msg.hasField(i)) {
					System.out.println("    Field-"+i+" : "+msg.getString(i));
				}
			}
		} catch (ISOException e) {
			e.printStackTrace();
		} finally {
			System.out.println("--------------------");
		}

	}

}

The output:

----ISO MESSAGE-----
  MTI : 0200
    Field-3 : 201234
    Field-4 : 10000
    Field-7 : 110722180
    Field-11 : 123456
    Field-44 : A5DFGR
    Field-105 : ABCDEFGHIJ 1234567890
--------------------
RESULT : 0200B2200000001000000000000000800000201234000000010000011072218012345606A5DFGR021ABCDEFGHIJ 1234567890

The program flow:

  1. Create ISO packager based on the xml file.
  2. Set the DE values. I use the previous article examples.
  3. Print the DE values set.
  4. Pack the message.
  5. Print the formatted ISO message. As you can see the result is the same with the previous article examples.

Parse (unpack) ISO Message

On this case it’s reversed. We have the ISO Message, and we need to see the DE values of it.
Like the previous code this one also similar and should be easy to understand.

package gnu.jimmod.iso8583.utility;

import java.io.IOException;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.packager.GenericPackager;

public class ParseISOMessage {

	public static void main(String[] args) throws IOException, ISOException {
		// Create Packager based on XML that contain DE type
		GenericPackager packager = new GenericPackager("basic.xml");

		// Print Input Data
		String data = "0200B2200000001000000000000000800000201234000000010000011072218012345606A5DFGR021ABCDEFGHIJ 1234567890";
		System.out.println("DATA : " + data);

		// Create ISO Message
		ISOMsg isoMsg = new ISOMsg();
		isoMsg.setPackager(packager);
		isoMsg.unpack(data.getBytes());

		// print the DE list
		logISOMsg(isoMsg);
	}

	private static void logISOMsg(ISOMsg msg) {
		System.out.println("----ISO MESSAGE-----");
		try {
			System.out.println("  MTI : " + msg.getMTI());
			for (int i=1;i<=msg.getMaxField();i++) {
				if (msg.hasField(i)) {
					System.out.println("    Field-"+i+" : "+msg.getString(i));
				}
			}
		} catch (ISOException e) {
			e.printStackTrace();
		} finally {
			System.out.println("--------------------");
		}

	}}

The output:

DATA : 0200B2200000001000000000000000800000201234000000010000011072218012345606A5DFGR021ABCDEFGHIJ 1234567890
----ISO MESSAGE-----
  MTI : 0200
    Field-3 : 201234
    Field-4 : 000000010000
    Field-7 : 0110722180
    Field-11 : 123456
    Field-44 : A5DFGR
    Field-105 : ABCDEFGHIJ 1234567890
--------------------

The program flow:

  1. Create ISO packager based on the xml file.
  2. Set ISO Message.
  3. Print the ISO Message.
  4. Unpack the message.
  5. Print the DE values. As you can see the result is correct, just like the DE set in first example.

In the end

Ok, like always I hope I make it clear for you.

Spread The Love, Share Our Article

  • Delicious
  • Digg
  • Newsvine
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter

Related Posts

  • Pingback: Rifftype()

  • Ochonma

    When i run the app it complains of “Error reading basic.xml” can someone pls help

Facebook Iconfacebook like buttonTwitter Icontwitter follow buttonFollow Us
Follow

Get every new post delivered to your Inbox

Join other followers