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.
[java]
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
.hexString(b)));
}
protected void sendMessageTrailler(ISOMsg m, int len) throws IOException {
serverOut.write(“.”.getBytes());
}
protected void sendMessageLength(int len) throws IOException {
len++; // one byte trailler
serverOut.write(len >> 8);
serverOut.write(len);
}
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.
Leave a Reply