Reputation: 21
I am using NACChannel of JPOS v2.1.0. I am using GenericPackager for packing my message. I am able to successfully send message to my ISO application. But while receiving incoming message my NACChannel.receive() throws parsing error.
My incoming message has a custom Header. I suspect this is causing the parsing error. So my questions are:
My JPOS client code I am using:
public class BuildISOMessage {
public static void main(String[] args) throws IOException, ISOException {
createISOMessage();
}
public static byte[] createISOMessage() throws ISOException {
String HOST = "localhost";
int PORT = 40021;
// Create Packager based on XML that contain DE type
ISOBasePackager packager = new GenericPackager("800_fields.xml");
NACChannel testchannel = new NACChannel();
testchannel.setHost(HOST, PORT);
ISOMsg isoMsg = build200ISOMessage(packager);
// print the DE list
logISOMsg(isoMsg);
// Get and print the output result
byte[] data = isoMsg.pack();
try {
testchannel.setPackager(isoMsg.getPackager());
testchannel.setHeader(("ISO01" + String.format("%04d", data.length)).getBytes());
testchannel.connect();
testchannel.send(isoMsg);
if (testchannel.isConnected()) {
ISOMsg response = testchannel.receive();
}
testchannel.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
private static ISOMsg build200ISOMessage(ISOBasePackager packager)
throws ISOException {
// Create ISO Message
ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
isoMsg.setMTI("200");
isoMsg.set(2, "4622871000060891");
isoMsg.set(3, "300000");
isoMsg.set(4, "100");
isoMsg.set(7, "1026043633");
isoMsg.set(11, "999901");
isoMsg.set(12, "113633");
isoMsg.set(13, "1026");
isoMsg.set(15, "1116");
isoMsg.set(16, "1116");
isoMsg.set(18, "6011");
isoMsg.set(22, "21");
isoMsg.set(32, "0000004");
isoMsg.set(33, "0000004");
isoMsg.set(35, "4622871000060891=22082211963393100000");
isoMsg.set(37, "829911364035");
isoMsg.set(43, "TBNKTAS2B065B999P999300501000050 TH");
isoMsg.set(48, "00000000040000000002000000013000000000005000000000007000TYRIONLANNISER ARYA STARK000000003334000000000202 00000000000000000000");
isoMsg.set(49, "764");
isoMsg.set(52, "FFFFFFFFFFFFFFFF");
isoMsg.set(62, "221000000000");
return 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("--------------------");
}
}
}
Upvotes: 0
Views: 1158
Reputation: 21
Thanks all for your help. While looking for an answer for debug purpose, I created a subclass of NACChannel and put some debug statements. By doing that I realized the issue was with my field definition and nothing to do with JPOS framework.
I was setting a header(e.g. ISO010200 where message length is 200) of length '9' by the below code.
testchannel.setHeader(("ISO01" + String.format("%04d", data.length)).getBytes());
My response also had a similar header of length '9'. So the NACChanel receive() method was able to extract the 9 digit Header correctly. But failed to parse the response message, my field definition was not correct.
Once that was fixed, JPOS was able to parse the response message coorectly.
Upvotes: 1