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
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 ![]()
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:
- Create ISO packager based on the xml file.
- Set the DE values. I use the previous article examples.
- Print the DE values set.
- Pack the message.
- 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:
- Create ISO packager based on the xml file.
- Set ISO Message.
- Print the ISO Message.
- Unpack the message.
- 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.
Related articles
- Parser (daniweb.com)
- Standards & Compliance Briefing: ISO 50001, USDA Organic, LEED (leeddaily.com)
- Technipaq Earns ISO 9001 and ISO 13485 Certifications (prweb.com)











I am new to cryptography, could you please provide me a sample for DUPKT algorithm in java
https://www.google.com.pk/search?hl=en&client=firefox-a&hs=TMe&rls=org.mozilla:en-US:official&sa=X&ei=IQDHT-YJharRBbCK-f0O&ved=0CAcQvwUoAQ&q=DUKPT+algorithm+in+java&spell=1&biw=1366&bih=516
http://jpos.1045706.n5.nabble.com/help-can-you-provide-sample-code-for-DUKPT-td2244924.html
i hope these links help you and if i am not wrong its DUKPT not DUPKT
J POS seams to be quite powerful library. I wonder if EMV standard and EMV field are already supported or you need to develop EMV additionally? Also, is there similar library for ACI SPDH protocol?
hmmm JPOS is quite powerful
anyway for SPDH i hope you got something there http://stackoverflow.com/questions/601746/an-analyzer-for-spdh-frame
I am new to JPOS, could you please provide me a sample for connecting JPOS to device like HSM in java
sorry dear for late reply ….. anyway i didn’t try JPOS with HSM … PLZ Do GOOGLE FOR THAT …..
You have to create your own implementation for HSM
its depend on the work wht you are Doing …
if i use Standard then its better to use JPOS instead of creating ur own standard….
org.apache.crimson.parser.XMLReaderImpl in loader dalvik.system.PathClassLoader exception when using JPOS in android. Already tried setting system property to sax driver but not working.
I have tried this application in Android but i got error.
Error is:
org.jpos.iso.ISOException: java.lang.ClassNotFoundException: org.apache.crimson.parser.XMLReaderImpl in loader dalvik.system.PathClassLoader[/data/app/com.sample.androidisomessage-1.apk] (java.lang.ClassNotFoundException: org.apache.crimson.parser.XMLReaderImpl in loader dalvik.system.PathClassLoader[/data/app/com.sample.androidisomessage-1.apk])
Please anybody help me.
Pls
wht you want to do in android ……
I want to do mobile banking.
These are function need to do
Log – Authentication
Balance inquiry.
When I try this code in android , trouble in read xml(build.xml) file. I got error this line
// Create Packager based on XML that contain DE type
GenericPackager packager = new GenericPackager(“basic.xml”);
Please help me.
plz debug your code again , i didn’t know why this happens
Working in android industry I realized Mobile banking (on-us and off-us transactions ) is a complete failure.Track-ID and KSN numbers based on UID and biometrics can never happen in real time scenario.
dear i use that with that from implementation and i use that with spring framework in J2EE http://www.fundamo.com/index.shtml
i hope for mobile development iso 8583 implementation may me different.
Hi, Neat post. There is an issue together with your web site in web explorer, would test this? IE still is the marketplace chief and a good element of people will pass over your excellent writing because of this problem.