Reputation: 93
How could I print packed ISO messages for example in the following code?
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
isoMsg.setMTI("0200");
isoMsg.set(2, "16");
isoMsg.set(2, "5421287475388412");
isoMsg.set(3, "000000 ");
isoMsg.set(4, "400.0");
isoMsg.set(7, "0716070815");
isoMsg.set(11, "844515");
logISOMsg(isoMsg);
byte[] data = isoMsg.pack();
System.out.println("RESULT : " + new String(data));
Upvotes: 3
Views: 9252
Reputation: 606
If you want to print the raw message this is what worked for me:
ISOBasePackager packager = new Reliance93APackagerBBitmap();
org.jpos.util.Logger jPosLogger = new org.jpos.util.Logger();
jPosLogger.addListener(new SimpleLogListener(System.out));
packager.setLogger(jPosLogger, "deb
Upvotes: 0
Reputation: 1865
Hi if you want to print field by field, the easiest way is to use the ISOMsg.dump() method, in your code would be:
isoMsg.dump(Sytsem.out, "");
If you want an hex dump representation you can use ISOUtil.hexDump() method, in your example:
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;
public class JposExamples {
/**
*
*/
public JposExamples() {
// TODO Auto-generated constructor stub
}
/**
* @param args
*/
public static void main(String[] args) throws ISOException{
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(new ISO87BPackager());
isoMsg.setMTI("0200");
isoMsg.set(2, "16");
isoMsg.set(2, "5421287475388412");
isoMsg.set(3, "000000");
isoMsg.set(4, "400.0");
isoMsg.set(7, "0716070815");
isoMsg.set(11, "844515");
byte[] data = isoMsg.pack();
System.out.println(ISOUtil.hexdump(data));
}
}
This would use ISO87BPackager and print this:
0000 02 00 72 20 00 00 00 00 00 00 16 54 21 28 74 75 ..r .......T!(tu
0010 38 84 12 00 00 00 00 00 00 04 00 E0 07 16 07 08 8...............
0020 15 84 45 15 ..E.
If you use ISO87APackager instead output would be like this:
0000 30 32 30 30 37 32 32 30 30 30 30 30 30 30 30 30 0200722000000000
0010 30 30 30 30 31 36 35 34 32 31 32 38 37 34 37 35 0000165421287475
0020 33 38 38 34 31 32 30 30 30 30 30 30 30 30 30 30 3884120000000000
0030 30 30 30 34 30 30 2E 30 30 37 31 36 30 37 30 38 000400.007160708
0040 31 35 38 34 34 35 31 35 15844515
Hope this answer your question.
Upvotes: 9
Reputation: 76
If you mean you want to print the message field by field, you can see the article in this link.
I refer his code here:
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("--------------------");
}
}
}
Upvotes: 2