0

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:

  1. How can I handle this ISOMsg header in my incoming response?
  2. Is there any way I can disable the Parsing Step and Receive the byte[] response from the channel?

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("--------------------");
    }
}
}
James Z
  • 12,209
  • 10
  • 24
  • 44
Arijit B
  • 21
  • 3
  • 1
    Your setHeader doesn't make much sense for NACChannel, first of all, the length is handled automattically by the channel, so that "String.format(" seems wrong. Also header needs to be compressed of numbers since setHeader metthod of NACChannel converts it to a bcd byte array. Finally, I don't understand why you want to use a jpos channel if you want to parse message by yourself. In that case you can just establish a tcp connection and directly use packager to pack and unpack. – Andrés Alcarraz Oct 26 '18 at 17:18
  • 1
    We need more information in order to help you, what is the intended format of the header, and how the length is supposed to be transported, maybe NACChannel is no the suitable for you – Andrés Alcarraz Oct 26 '18 at 17:19
  • 1
    BTW, your `logISOMsg` method could be simplified with a one liner: `msg.dump (System.out, "");` – apr Oct 28 '18 at 23:34
  • Dear @apr. Thanks for the input. It was helpful. – Arijit B Oct 29 '18 at 12:34
  • Dear @AndrésAlcarraz I have used a separate client using Netty. Works fine, but parsing is challenging. So exploring JPOS channels. For analysis I created a Subclass of the NACChannel and put some debugs into receive() method and glad to find that header is actually parsed correctly. My application expects ISO01 this 9 byte Header in both request and response. I think issue is with field 32. I am using org.jpos.iso.IFA_LLNUM. Sample field in input `in[ 32: ]<7> in[ 32: ]<0000004>` and in output `out[ 32: ]<07> out[ 32: ]<0000004>`. – Arijit B Oct 29 '18 at 13:11
  • Message specs: **32, N, var-2, Required, 1, 11, Acquirer institution code,** – Arijit B Oct 29 '18 at 13:14
  • @ArijitB is hard to help you without your custom channel implementation. I'm not sure your concept of header matches the header concept of jPos, In jpos the header is what comes between the TCP message length and the MTI so to speak. The length is used by the channel to know how much bytes it has to read, and is not considered header in jPOS terminology that's why I'm not entirely sure you are not correctly handling the channel level logic. Anyway it's hard to say if you don't share that logic. – Andrés Alcarraz Oct 30 '18 at 16:42
  • @AndrésAlcarraz thanks for your response. Well looks like the `NACChannel.setHeader` was able to handle my header correctly. It was able to send message header and extract from the response. – Arijit B Nov 05 '18 at 14:07
  • My issue now is with field packager definition. REQUEST: `in[ 32: ]<7> in[ 32: ]<0000004> in[ 33: ]<7> in[ 33: ]<0000004>' RESPONSE: 'out[ 32: ]<07> out[ 32: ]<0000004> out[ 33: ]<07> out[ 33: ]<30303030303034>'. I tried `org.jpos.iso.IFA_LLNUM` for both fields, but its not working for response. Can you suggest which packager to use? – Arijit B Nov 05 '18 at 14:16
  • @ArijitB it is better to update the question than to put this stuff in coments, because they are not formatted, I'm pretty sure there is a problem with the way you are handling headers, because the header is used by the channel to know how many character belong to the header, if you make some custom logic to write length in the header (which is not the recommended jPOS way) then you have to do the opposite when reading the message length. Do the first fields of the message look ok? And please put what you wrote on the las comment in the answer better formatted because it's difficult to read. – Andrés Alcarraz Nov 06 '18 at 15:06

1 Answers1

1

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.

Arijit B
  • 21
  • 3