Search code examples
javasocketsiso8583

How to fix Java ISO8583 socket error: TRANSMISSION ERROR


I am working on a project and this error have been giving me headache. I am making use of Java J8583 library to construct an ISO8583 message and send to a remote server. The server's response is a hex value: 5452414E53414354494F4E204552524F52 which when converted to ASCII: TRANSMISSION ERROR.

// function to construct Message
public IsoMessage createLoadRequest(String tag) {
IsoMessage nManagementMsg = messageFactory.newMessage(0x0800);
Date date = new Date();

String terminalID = new Utils().retrieveTerminalID(); 


nManagementMsg.setField(3, new IsoValue<Object>(IsoType.ALPHA, tag, 6));
nManagementMsg.setField(7, new IsoValue<Object>(IsoType.NUMERIC, utcTime.format(date), 10));
lastTransactionAuditCode = Utils.randomAlphaNumeric(6);
nManagementMsg.setField(11, new IsoValue<Object>(IsoType.NUMERIC, lastTransactionAuditCode, 6)); // System Trace Audit Number
nManagementMsg.setField(12, new IsoValue<>(IsoType.NUMERIC, localTime.format(date), 6));
nManagementMsg.setField(13, new IsoValue<>(IsoType.DATE_EXP, localDate.format(date), 4));
nManagementMsg.setField(41, new IsoValue<Object>(IsoType.ALPHA, terminalID, 8));

return nManagementMsg;
}

//function to make send Message to server
public boolean retrieveData() throws UnsupportedEncodingException {

IsoMessage networkManagementMsg = this.createLoadRequest("567YUY");

String strToSend = new String(networkManagementMsg.writeData());

if (!start()) {
    return false;
}

try {

        logger.info(strToSend);

    outputStream.writeUTF(strToSend);
    IsoMessage response = readMessage();
    final String result = response.getAt(39).toString();

    if (!result.equals("00")) {
        logger.log(Level.WARNING, "Network Management Response contains a non-zero result code {0}", result);
        return false;
    }

    // parse and get required data
    String value = response.getAt(62).toString();
    System.out.println(value);


    return true;
 } catch (Exception ex) {
    logger.severe("Exception while loading terminal info");
    ex.printStackTrace();
    return false;
} finally {
    stop();
}
}

I was expecting an ISOMessage back got error:

INFO: 08002238000000800000567YUY0515135835Q56U46135835051520390013

INFO: Received response: 5452414E53414354494F4E204552524F52

INFO: IsoMessage: null

java.io.IOException: Failed to parse iso message string: 

5452414E53414354494F4E204552524F52


Solution

  • It's hard to say without larger context of your project and values of each field you want to pack, but your request looks strange. STAN (field 11) was supposed to be numeric, but contains alpha. Also, you should check encoding of Terminal ID (field 41) as it may be 8 bytes directly as you had it built it but in some systems I've seen 16 bytes using hex encoding.