Tutorial Customize JPos NACChannel with Tail

Today i want to share Tutorial Customize JPos NACChannel with Tail

Jpos Library comes with several channel implementation. Most channel implementation extend BaseChannel class and just override the sendMessageLength and getMessageLenght methods. every channel implementation have different message format, for example NACCHannel using LL LL [TPDU] ISO-Data message format, where:

  • LL LL represent the TPDU + ISO-Data length in network byte order
  • Optional TPDU(Transport protocol data unit)
  • ISO-Data: ISO-8583 image

in my experience for integration with Base24 they send ISO-8583 with format LL LL [TPDU] ISO-Data tail, so my JPos client cannot read the message with NACChannel. After searching the solution in JPos Group, i got information that i have to extend NACChannel and override getMessageTrailler, sendMessageTrailler, sendMessageLength, getMessageLength methods. Here is the complete code i call it NACTailChannel.

package com.didikhari.channel;

import java.io.IOException;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOPackager;
import org.jpos.iso.ISOUtil;
import org.jpos.iso.channel.NACChannel;
import org.jpos.util.LogEvent;
import org.jpos.util.Logger;

* Send and Read ISO-8583 Message with NACChannel that have Tail.
* @author Didik Hari
* @since 2014/12/17
public class NACTailChannel extends NACChannel {

public NACTailChannel(String hostname, int portNumber,
ISOPackager packager, byte[] bytes) {
super(hostname, portNumber, packager, bytes);

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

protected void sendMessageTrailler(ISOMsg m, int len) throws IOException {

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

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 } } [/java] Hope this Tutorial Customize JPos NACChannel with Tail can help somebody. Thanks for reading this post.
Any constructive comments are appreciated.


Hi! i’m Didik Hari, I am Backend Developer, System Integration and Web Developer mostly using Java. I use jPOS for ISO 8583 integration format, and Spring to create Rest API.

2 thoughts to “Tutorial Customize JPos NACChannel with Tail”

  1. Hi Didik, i have a problem with my jpos host, when i send message using NACChannel, there are some bytes message in hex before LL LL TPDU ISOMsg. What packager that you are using? Can you help to solve my problem please

Leave a Reply

Your email address will not be published.