如何修复Java ISO8583套接字错误:传输错误

时间:2019-05-15 14:45:35

标签: java sockets iso8583

我正在做一个项目,这个错误使我头疼。我正在使用Java J8583库构造一条ISO8583消息并将其发送到远程服务器。服务器的响应是一个十六进制值:5452414E53414354494F4E204552524F52,将其转换为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();
}
}

我期望ISOMessage返回错误:

INFO: 08002238000000800000567YUY0515135835Q56U46135835051520390013

INFO: Received response: 5452414E53414354494F4E204552524F52

INFO: IsoMessage: null

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

5452414E53414354494F4E204552524F52

1 个答案:

答案 0 :(得分:0)

如果没有更大的项目上下文和要打包的每个字段的值,很难说,但是您的请求看起来很奇怪。 STAN(字段11)应该是数字,但包含字母。另外,您应该检查终端ID(字段41)的编码,因为它可能是构建时直接的8个字节,但是在某些系统中,我已经看到使用16进制编码的16个字节。