How to disable the BASE24TCPChannel channel the last character that is placed in the iso message

45 views Asked by At

Good morning, I am new to jpos, the problem I have is I am sending a message with a header, but when sending it, it always adds a character at the end 03 in hexadecimal.

code of how I send it

code of how I send it

   // Create Packager based on XML that contain DE type
   GenericPackager packager = new GenericPackager("PackISO.xml");

   // Crea una instancia de la clase BASE24TCPChannel
   BASE24TCPChannel c = new BASE24TCPChannel("localhost", 5000,packager);
   c.setHeader("ISO008000099");
       
   // Create ISO Message
   ISOMsg isoMsg = new ISOMsg();        
   isoMsg.setPackager(packager);
 
   isoMsg.setMTI("0800");
   isoMsg.set(7, "1088110140");
   isoMsg.set(11, "087478");
   isoMsg.set(70, "999");

   c.connect();
   c.send(isoMsg);

This is what send sends, I capture this using netcat nc -l -p 5000 | xxd

00000000: 0044 4953 4f30 3038 3030 3030 3939 3038  .DISO00800009908
00000010: 3030 3832 3230 3030 3030 3030 3030 3030  0082200000000000
00000020: 3030 3034 3030 3030 3030 3030 3030 3030  0004000000000000
00000030: 3030 3130 3838 3131 3031 3430 3038 3734  0010881101400874
00000040: 3738 3939 3903                           78999.

"03" always arrives at the end of each message, how do I disable it so that it is not sent? 00000040: 3738 3939 39**03** 78999**.**

2

There are 2 answers

0
Andrés Alcarraz On

If you don't want that trailer, you need to use another channel.

PostChannel or NACChannel do essentially the same, but doesn't send the trailer.

   ...
   PostChannel c = new PostChannel("localhost", 5000,packager);
   c.setHeader("ISO008000099".getBytes(ISOUtil.ENCODING));
   ...

You have to set the header as bytes also, because the string setHeader overload expects a hex representation.

0
nacadev On

Just create new class extending BASE24TCPChannel and override bellow methods:

protected void sendMessageTrailler(ISOMsg m, int len) throws IOException {
    // serverOut.write (3);
}

above method will not sending the trailler '03' char.

protected void sendMessageLength(int len) throws IOException {
    //len++;  // one byte trailler
    serverOut.write (len >> 8);
    serverOut.write (len);
}

above method will not including trailler on the message length

protected int getMessageLength() throws IOException, ISOException {
    int l = 0;
    byte[] b = new byte[2];
    Logger.log (new LogEvent (this, "get-message-length"));
    while (l == 0) {
        serverIn.readFully(b,0,2);
        l = ((int)b[0] &0xFF) << 8 | (int)b[1] &0xFF;
        if (l == 0) {
            serverOut.write(b);
            serverOut.flush();
        }
    }
    Logger.log (new LogEvent (this, "got-message-length", Integer.toString(l)));
    //return l - 1;   // trailler length
    return l;
}

above method will exclude trailler when getting message length.

protected void getMessageTrailler() throws IOException {
    //Logger.log (new LogEvent (this, "get-message-trailler"));
    //byte[] b = new byte[1];
    //serverIn.readFully(b,0,1);
    //Logger.log (new LogEvent (this, "got-message-trailler", ISOUtil.hexString(b)));
}

and the last, above method will not get message trailler from the message.