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;
import java.io.InputStream;
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) {
e.printStackTrace();
}
}
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.setPackager(packager);
isoMsg.setMTI("0200");
isoMsg.set(3, "000010");
isoMsg.set(4, "1500");
isoMsg.set(7, "1206041200");
isoMsg.set(11, "000001");
isoMsg.set(41, "12340001");
isoMsg.set(49, "840");
printISOMessage(isoMsg);
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) {
e.printStackTrace();
}
}
}
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
<dependency>
<groupId>org.jpos</groupId>
<artifactId>jpos</artifactId>
<version>2.1.8</version>
</dependency>
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024
I get error:
Hi Tony,
Can you post a complete error stack trace?
Hi Tony,
I think the error because it cannot find the
fields.xml
file. I am using Maven, in this case I place thefields.xml
file inside theresources
directory (src/main/resources/fields.xml
).Instead of loading the packager file as a resource you can also do something like this:
I created a project named mavenproject2 and placed the
fields.xml
incfg/packager
but the error still there.Error while compiling sample ISO Message Program:
Hi Vijaykumar, make sure you are compiling the code using JDK 8.
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.
Hi Sonali, can you show any code that you are working on?
Hi Sonali, can you also provide the string data to be unpacked?
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?
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.
Hi Sonali, can you show me the bit mapping of your message?
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
0085
9bcb28c2e08d11ee000000000000000054455354494e47205445414d205448414e4520202020205448414e452020202020202020204d48202020202020202020202020202020202020202020202020202020202020
003600344b509bcb28c2e08d11eebbe04de6eb78a79c48bbb4f43f0f759171846d85cd4d584d00000000000000000000000000000000000000000000000000000000000000000000000000000000
Hi Sonali,
I am processing the following message:
I remove the length (
00b2
) and the header (6000000041
). And here is the result I got: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 isIFA_LLLCHAR
it means that the message if prefixed with three digits length. For example00859bcb28c
,008
is the length and59bcb28c
is the data.Hi, how to add ISO header in ISO message?
How to make a field mandatory from xml?
Muchas gracias me ha sido de gran utilidad!
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
Hi Rohini.
Can you share the bitmap / message example?
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?
How to add header 2 bytes in ISO8583?
Hi Wayan. Can you please help me resolve below error. I am using the same code and fields.xml file.
Hi Wayan, I am facing one issues I am doing socket connection with one service also ISO8583 message but when I send the payload they can’t see. Means it’s not moving there. I need your help, because I am m new with this.
Hi Soumya,
Do you have any error during this process? any exception message for example. Maybe you can show me the code on how you do it?
When I send dynamics data to them they are not seeing my message.
Hi Wayan, Actually I’m facing issues, when I try to unpack my ISO8583 message. I’m giving the error and response and code for your reference please help me to solve this.
And normal String is:
And the issues is “org.jpos.iso.IFA_NUMERIC: Problem unpacking field 7 (java.lang.RuntimeException: Required 10 but just got 2 bytes) unpacking field=7, consumed=72”
And my XML file is: