发送 ISO8583 请求时出现 NullPointerException
NullPointerException when sending ISO8583 request
我正在尝试使用以下代码向终端发送 ISO8583 请求:
try {
XMLParser packager = new XMLParser(this.xmlFile);
final ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
isoMsg.setMTI("0800");
isoMsg.set(3, "xxxxxx");
isoMsg.set(7, "xxxxxxxxxx"); //MMDDhhmmss
isoMsg.set(11, "xxxxxx");
isoMsg.set(12, "084500"); //Time of the message HHmmss
isoMsg.set(13, "0621"); //Date MMDD
isoMsg.set(41, "xxxxxxxx");
isoMsg.set(62,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
isoMsg.set(63,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
BaseChannel channel = new BaseChannel() {};
channel.setLogger(logger, "server-request-channel");
channel.setHeader(isoMsg.pack());
channel.setHost("xx.xx.xx.xx", xxxxx);
ISOMUX isoMux = new ISOMUX(channel) {
@Override
protected String getKey(ISOMsg m) throws ISOException {
return super.getKey(m);
}
};
isoMux.setLogger(logger, "server-request-mux");
new Thread(isoMux).start();
ISORequest req = new ISORequest(isoMsg);
isoMux.queue(req);
req.setLogger(logger, "server-request-logger");
ISOMsg response = req.getResponse(50 * 1000);
if (response != null) {
System.out.println("Req ["+ new String(isoMsg.pack()) + "]");
System.out.println("Res ["+ new String(response.pack()) + "]");
}else{
System.out.println("Timeout");
}
}catch (Exception e) {
e.printStackTrace();
}
}
执行代码后,出现以下异常:
<log realm="server-request-mux" at="Fri Aug 14 00:26:43 WAT 2015.995">
<muxreceiver>
<exception name="null">
java.lang.NullPointerException
at org.jpos.iso.BaseChannel.createISOMsg(BaseChannel.java:561)
at org.jpos.iso.BaseChannel.createMsg(BaseChannel.java:558)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:585)
at org.jpos.iso.ISOMUX$Receiver.run(ISOMUX.java:263)
at java.lang.Thread.run(Thread.java:856)
</exception>
</muxreceiver>
</log>
为了找出异常所在的行,我添加了断点,发现只要遇到语句就会异常:
ISORequest req = new ISORequest(isoMsg);
我对 ISO8583 jpos 金融编程比较陌生,我想在 android 平台上构建应用程序。
如何克服这个异常?
您不能创建 BaseChannel
的实例 -- 它是一个抽象 class (see it on GitHub)。
如果您只想将 XML 格式的 ISO-8583 消息发送到端点并等待响应,您可以这样做:
XMLPackager packager = new XMLPackager();
XMLChannel channel = new XMLChannel("localhost", 11000, packager);
channel.setPackager(packager);
channel.setTimeout(30000);
channel.connect();
Date now = new Date();
ISOMsg m = new ISOMsg();
m.setMTI("2100");
m.set("3", "000000");
m.set(new ISOAmount(4, 840, new BigDecimal(10.00)));
m.set("7", ISODate.formatDate(now, "MMddHHmmss"));
m.set("11", "1111");
m.set("12", ISODate.formatDate(now, "yyyyMMddHHmmss"));
m.set("22", "KEY.UNK.ECO.APP");
m.set("26", "5999");
m.set("27", "00100000000000001000000000000000");
m.set("32", "00000000001");
m.set("41", "59991515");
m.set("42", "888000003518");
m.set("43.2", "Shegda Electronics");
m.set("43.4", "Richardson");
m.set("43.5", "TX");
m.set("43.6", "63105");
m.set("43.7", "USA");
m.set("49.1", "1");
m.set("49.3", "121 First Street");
m.set("49.4", "85284");
m.set("104.4", "1");
channel.send(m);
ISOMsg resp = channel.receive();
我正在尝试使用以下代码向终端发送 ISO8583 请求:
try {
XMLParser packager = new XMLParser(this.xmlFile);
final ISOMsg isoMsg = new ISOMsg();
isoMsg.setPackager(packager);
isoMsg.setMTI("0800");
isoMsg.set(3, "xxxxxx");
isoMsg.set(7, "xxxxxxxxxx"); //MMDDhhmmss
isoMsg.set(11, "xxxxxx");
isoMsg.set(12, "084500"); //Time of the message HHmmss
isoMsg.set(13, "0621"); //Date MMDD
isoMsg.set(41, "xxxxxxxx");
isoMsg.set(62,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
isoMsg.set(63,"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
BaseChannel channel = new BaseChannel() {};
channel.setLogger(logger, "server-request-channel");
channel.setHeader(isoMsg.pack());
channel.setHost("xx.xx.xx.xx", xxxxx);
ISOMUX isoMux = new ISOMUX(channel) {
@Override
protected String getKey(ISOMsg m) throws ISOException {
return super.getKey(m);
}
};
isoMux.setLogger(logger, "server-request-mux");
new Thread(isoMux).start();
ISORequest req = new ISORequest(isoMsg);
isoMux.queue(req);
req.setLogger(logger, "server-request-logger");
ISOMsg response = req.getResponse(50 * 1000);
if (response != null) {
System.out.println("Req ["+ new String(isoMsg.pack()) + "]");
System.out.println("Res ["+ new String(response.pack()) + "]");
}else{
System.out.println("Timeout");
}
}catch (Exception e) {
e.printStackTrace();
}
}
执行代码后,出现以下异常:
<log realm="server-request-mux" at="Fri Aug 14 00:26:43 WAT 2015.995">
<muxreceiver>
<exception name="null">
java.lang.NullPointerException
at org.jpos.iso.BaseChannel.createISOMsg(BaseChannel.java:561)
at org.jpos.iso.BaseChannel.createMsg(BaseChannel.java:558)
at org.jpos.iso.BaseChannel.receive(BaseChannel.java:585)
at org.jpos.iso.ISOMUX$Receiver.run(ISOMUX.java:263)
at java.lang.Thread.run(Thread.java:856)
</exception>
</muxreceiver>
</log>
为了找出异常所在的行,我添加了断点,发现只要遇到语句就会异常:
ISORequest req = new ISORequest(isoMsg);
我对 ISO8583 jpos 金融编程比较陌生,我想在 android 平台上构建应用程序。
如何克服这个异常?
您不能创建 BaseChannel
的实例 -- 它是一个抽象 class (see it on GitHub)。
如果您只想将 XML 格式的 ISO-8583 消息发送到端点并等待响应,您可以这样做:
XMLPackager packager = new XMLPackager();
XMLChannel channel = new XMLChannel("localhost", 11000, packager);
channel.setPackager(packager);
channel.setTimeout(30000);
channel.connect();
Date now = new Date();
ISOMsg m = new ISOMsg();
m.setMTI("2100");
m.set("3", "000000");
m.set(new ISOAmount(4, 840, new BigDecimal(10.00)));
m.set("7", ISODate.formatDate(now, "MMddHHmmss"));
m.set("11", "1111");
m.set("12", ISODate.formatDate(now, "yyyyMMddHHmmss"));
m.set("22", "KEY.UNK.ECO.APP");
m.set("26", "5999");
m.set("27", "00100000000000001000000000000000");
m.set("32", "00000000001");
m.set("41", "59991515");
m.set("42", "888000003518");
m.set("43.2", "Shegda Electronics");
m.set("43.4", "Richardson");
m.set("43.5", "TX");
m.set("43.6", "63105");
m.set("43.7", "USA");
m.set("49.1", "1");
m.set("49.3", "121 First Street");
m.set("49.4", "85284");
m.set("104.4", "1");
channel.send(m);
ISOMsg resp = channel.receive();