I am having a challenge. I am using Jpos and I am trying to set field 127 sub-element 033 as well as unpacking it. When packing, seems like its working fine but when trying to unpack I get the following exception.
Caused by: org.jpos.iso.ISOException: org.jpos.iso.IFA_LLCHAR: Problem unpacking field 11 (java.lang.NegativeArraySizeException) unpacking field=127, consumed=287
If i comment out the setting of field 127.033 as well as removing the isofield with id = 33 under field 127 in fields.xml everything works well. But when i uncomment the above, the error re-surfaces.
Packer:
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.packager.GenericPackager;
import java.io.InputStream;
import java.text.SimpleDateFormat;
public class PackerTest {
public static void main(String[] args) throws ISOException {
InputStream is = com.melah.Pack.class.getResourceAsStream("/fields.xml");
GenericPackager packager = new GenericPackager(is);
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
isoMsg.set(0, "0200");
isoMsg.set(2, "5000000000000000");
isoMsg.set(3, "317000");
isoMsg.set(4, "000000000000");
isoMsg.set(7, new SimpleDateFormat("MMddHHmmss").format(1221133630));
isoMsg.set(11, "594972");
isoMsg.set(12, "153630");
isoMsg.set(13, "1221");
isoMsg.set(14, "1912");
isoMsg.set(15, "1221");
isoMsg.set(18, "6012");
isoMsg.set(22, "020");
isoMsg.set(25, "27");
isoMsg.set(28, "C00000000");
isoMsg.set(30, "C00000000");
isoMsg.set(32, "588892");
isoMsg.set(37, "000540000000");
isoMsg.set(41, "11430000");
isoMsg.set(42, "000000011431143");
isoMsg.set(43, "XYZ Banking");
isoMsg.set(49, "840");
isoMsg.set(56, "1510");
isoMsg.set(59, "0540000000");
isoMsg.set(102, "5000000000000000");
isoMsg.set(123, "100000000000000");
isoMsg.set("127.003", "XYZ XYZ");
isoMsg.set("127.033", "6000");
isoMsg.set(54, "500000000");
byte[] bIsoMsg = isoMsg.pack();
String isoMessage = "";
for (int i = 0; i < bIsoMsg.length; i++) {
String a = "";
isoMessage += (char) bIsoMsg[i];
}
System.out.println(" Packed ISO8385 Message = '"+isoMessage+"'");
}
}
Unpacker:
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;
import org.jpos.iso.packager.GenericPackager;
import java.io.InputStream;
public class UnpackISOMessage {
public static void main(String[] args) {
UnpackISOMessage iso = new UnpackISOMessage();
try {
ISOMsg isoMsg = iso.parseISOMessage();
iso.printISOMessage(isoMsg);
} catch (Exception e) {
e.printStackTrace();
}
}
private ISOMsg parseISOMessage() throws Exception {
String message = "0200F23E449508E0852000000000040000221650000000000000003170000000000000000115051213594972153630122119121221601202027C00000000C000000000658889200054000000011430000000000011431143XYZ Banking 84000950000000000415100100540000000165000000000000000015100000000000000000060 タ XYZ XYZ 6000";
System.out.printf("Message = %s%n", message);
try {
InputStream is = getClass().getResourceAsStream("/fields.xml");
GenericPackager packager = new GenericPackager(is);
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
isoMsg.unpack(message.getBytes());
return isoMsg;
} catch (ISOException e) {
throw new Exception(e);
}
}
private void printISOMessage(ISOMsg isoMsg) {
try {
isoMsg.dump(System.out, "");
System.out.println(ISOUtil.hexdump(isoMsg.pack()));
System.out.printf("MTI = %s%n", isoMsg.getMTI());
System.out.println("127.003 : " + isoMsg.getString("127.003"));
System.out.println("127.033 : " + isoMsg.getString("127.033"));
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();
}
}
}
fields.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE isopackager SYSTEM "genericpackager.dtd">
<!--<isofield id="127" length="999" name="RESERVED PRIVATE USE" class="org.jpos.iso.IFA_LLLCHAR"/>-->
Exception:
Message = 0200F23E449508E0852000000000040000221650000000000000003170000000000000000115051213594972153630122119121221601202027C00000000C000000000658889200054000000011430000000000011431143XYZ Banking 84000950000000000415100100540000000165000000000000000015100000000000000000060 タ XYZ XYZ 6000
java.lang.Exception: org.jpos.iso.ISOException: org.jpos.iso.IFA_LLCHAR: Problem unpacking field 11 (java.lang.NegativeArraySizeException) unpacking field=127, consumed=287
at com.melah.UnpackISOMessage.parseISOMessage(UnpackISOMessage.java:32)
at com.melah.UnpackISOMessage.main(UnpackISOMessage.java:14)
Caused by: org.jpos.iso.ISOException: org.jpos.iso.IFA_LLCHAR: Problem unpacking field 11 (java.lang.NegativeArraySizeException) unpacking field=127, consumed=287
at org.jpos.iso.ISOBasePackager.unpack(ISOBasePackager.java:340)
at org.jpos.iso.ISOMsg.unpack(ISOMsg.java:468)
at com.melah.UnpackISOMessage.parseISOMessage(UnpackISOMessage.java:29)
... 1 more
Jpos Maven Dependency:
org.jpos
jpos
2.1.2
Code can be found on github:
https://github.com/melah500/jpos-field-127.003
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)