I try to write a stub that emulate ISO server on socket. When I recieve the message, I get something like ths:
[pool-1-thread-5] ERROR com.solab.iso8583.MessageFactory - ISO8583 MessageFactory has no parsing guide for message type ffffff50 [ r$$? ??A??#9i.....
Message in console:
Parsing incoming message: r$$? ??A??#@& i?....
I don't know what message type I get..
Why does it have so strange encoding? How can I fix that?
server code:
public class SocketServer implements Runnable {
private static final Log log = LogFactory.getLog(SocketServer.class);
private static ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(5);
private static MessageFactory messageFactory;
private Socket socket;
public SocketServer(Socket socket){
this.socket = socket;
}
public void run() {
int count = 0;
byte[] bufferLenght = new byte[2];
try{
while (socket != null && socket.isConnected()
&& Thread.currentThread().isAlive()
&& !Thread.currentThread().isInterrupted()){
if (socket.getInputStream().read(bufferLenght) == 2){
int size = ((bufferLenght[0] & 0xff) << 8) | (bufferLenght[1] & 0xff);
byte[] buffer = new byte[size];
socket.getInputStream().read(buffer);
count++;
threadPool.schedule(new Processor(buffer, socket), 400, TimeUnit.MILLISECONDS);
}
}
} catch (IOException e) {
e.printStackTrace();
}
log.debug(String.format("Count of requests: %d", count));
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class processor which processes the message...
private class Processor implements Runnable{
private byte[] message;
private Socket socket;
public Processor(byte[] buffer, Socket socket){
this.message = buffer;
this.socket = socket;
}
public void run() {
try{
System.out.println(String.format("Parsing incoming message: %s", new String(message)));
IsoMessage request = messageFactory.parseMessage(message,4);
IsoMessage response = messageFactory.createResponse(request);
response.setField(11, request.getField(11));
response.setField(7, request.getField(7));
response.write(socket.getOutputStream(), 2);
} catch (ParseException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
main
public static void main(String[] args) throws IOException {
messageFactory = ConfigParser.createFromClasspathConfig("config.xml");
System.err.println("Setting up server socket...");
ServerSocket serverSocket = new ServerSocket(8583);
System.err.println("Waiting for connections...");
while (true){
Socket socket = serverSocket.accept();
System.err.println(String.format("New connection from %s:%d", socket.getInetAddress(), socket.getPort()));
new Thread(new SocketServer(socket),"iso8583 server").start();
}
}
}
part of my config.xml:
<parse type="0100">
<field num="2" type="NUMERIC" length="20" />
<field num="3" type="NUMERIC" length="6" />
<field num="4" type="AMOUNT" />
<field num="7" type="DATE10" />
..............
<field num="62" type="LLLVAR" />
<field num="63" type="LLLVAR" />
<field num="64" type="LLLVAR" />
</parse>
Thanks in advance!
Seems like the message is binary encoded and you weren't expecting that? Or the other way around, maybe (message is ASCII encoded and you're trying to read it as binary encoded)