如何使用 jreactive-8583 将ISO8583消息从客户端发送到服务器?



我已经使用 jreactive-8583 设置了客户端和服务器。 客户端成功连接到服务器。但是我无法将ISO8583消息从客户端发送到服务器。我正在新学到这一点,发现很难找出问题并解决它。

客户端代码

package com.jreactive.demo;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.concurrent.TimeUnit;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.kpavlov.jreactive8583.IsoMessageListener;
import com.github.kpavlov.jreactive8583.client.Iso8583Client;
import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.MessageFactory;
import com.solab.iso8583.impl.SimpleTraceGenerator;
import com.solab.iso8583.parse.ConfigParser;
import io.netty.channel.ChannelHandlerContext;
public class HelloMessage {
public static IsoMessage createMessage() {
MessageFactory<IsoMessage> mf = new MessageFactory<IsoMessage>();
try {
String path="j8583.xml";
ConfigParser.configureFromUrl(mf, new File(path).toURI().toURL());
} catch (IOException e) {
e.printStackTrace();
}
mf.setForceSecondaryBitmap(true);
mf.setUseBinaryBitmap(true);
mf.setAssignDate(true); // This sets field 7 automatically
mf.setTraceNumberGenerator(new SimpleTraceGenerator((int)  (System.currentTimeMillis() % 100000)));
IsoMessage m = mf.newMessage(0x200); // You must use 0x200, 0x400, etc.
m.setValue(3, "000000", IsoType.ALPHA, 6);
m.setValue(11, "000001", IsoType.ALPHA, 6);
m.setValue(41, "3239313130303031", IsoType.ALPHA, 16);
m.setValue(60, "001054455354204D45535347", IsoType.ALPHA, 24);
m.setValue(70, "0301", IsoType.ALPHA, 4);
m.setForceSecondaryBitmap(true);
System.out.println(m.debugString());
return m;
}
@SuppressWarnings("deprecation")
public static void main(String[] args) throws InterruptedException, IOException {
MessageFactory<IsoMessage> messageFactory = ConfigParser.createDefault();// [1]
//@SuppressWarnings("deprecation")
//Iso8583Client<IsoMessage> client = new Iso8583Client<>(messageFactory);// [2]
System.out.println("hello*************");
System.out.println(createMessage().debugString());
System.out.println("hello**************");
SocketAddress socketAddress = new InetSocketAddress("127.0.0.1", 8090);
Iso8583Client<IsoMessage> client = new Iso8583Client<>(socketAddress, messageFactory);
client.addMessageListener((IsoMessageListener<IsoMessage>) new IsoMessageListener<IsoMessage>() { // [3]
public boolean applies(IsoMessage arg0) {
return false;
}
public boolean onMessage(ChannelHandlerContext arg0, IsoMessage arg1) {
return false;
}
});
client.getConfiguration().setReplyOnError(true);// [4]
client.init();// [5]
client.connect("127.0.0.1", 8090);// [6]
if (client.isConnected()) { // [7]
System.out.println("hello****************************8");
IsoMessage message = createMessage();
System.out.println(message.debugString());
//...
client.sendAsync(message);// [8]
// or
client.send(message);// [9]
// or
client.send(message, 1, TimeUnit.SECONDS);// [10]
}
//...
//client.shutdown();// [11]
}
}

服务器端代码

package com.jreactive.demo;
import java.io.File;
import java.io.IOException;
import com.github.kpavlov.jreactive8583.IsoMessageListener;
import com.github.kpavlov.jreactive8583.server.Iso8583Server;
import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.MessageFactory;
import com.solab.iso8583.parse.ConfigParser;
import io.netty.channel.ChannelHandlerContext;
public class JreactiveServer {
public static void main(String[] args) throws InterruptedException, IOException {
System.out.println("hello*****************************");
MessageFactory<IsoMessage> messageFactory = ConfigParser.createDefault();// [1]
Iso8583Server<IsoMessage> server = new Iso8583Server<>(8090, messageFactory);// [2]
server.addMessageListener((IsoMessageListener<IsoMessage>) new IsoMessageListener<IsoMessage>() { // [3]
@Override
public boolean applies(IsoMessage isoMessage) {
return isoMessage.getType() ==  0x200;
}
@Override
public boolean onMessage(ChannelHandlerContext ctx, IsoMessage isoMessage) {
IsoMessage capturedRequest = isoMessage;
System.out.println(capturedRequest);
System.out.println("we got a message ***********************");
final IsoMessage response = server.getIsoMessageFactory().createResponse(isoMessage);
response.setField(39, IsoType.ALPHA.value("00", 2));
response.setField(60, IsoType.LLLVAR.value("XXX", 3));
ctx.writeAndFlush(response);
return false;
}
});
server.getConfiguration().setReplyOnError(true);// [4]
server.init();// [5]
server.start();// [6]
if (server.isStarted()) { // [7]
System.out.println("server has started");
}
//server.shutdown();// [8]

}
}

这是我正在使用的j8583.xml文件的链接。 https://github.com/kpavlov/jreactive-8583/blob/master/src/test/resources/j8583.xml

我从客户端和服务器收到以下错误。

18:30:29.435 [nioEventLoopGroup-2-1] 错误 com.solab.iso8583.MessageFactory - ISO8583 MessageFactory 没有 消息类型 0800 的分析指南 [08000000000000000000000] 18:30:29.436 [nioEventLoopGroup-2-1] 警告 io.netty.channel.DefaultChannelPipeline - An exceptionCaught(( event 被发射,它到达了管道的尾部。它通常 表示管道中的最后一个处理程序未处理异常。 io.netty.handler.codec.DecoderException: java.text.ParseException: ISO8583 消息工厂没有消息类型 0800 的分析指南 [0800000000000000000000] 在 io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:473( 在 io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:281( 在 io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374( 在 io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360( 在 io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352( 在 io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:326( 在 io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:300( 在 io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374( 在 io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360( 在 io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352( 在 io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422( 在 io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374( 在 io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360( 在 io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931( 在 io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163( 在 io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700( 在 io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635( 在 io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552( at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514( at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050( 在 io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74( 在 io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30( at java.base/java.lang.Thread.run(Thread.java:834( 由以下原因引起: java.text.ParseException: ISO8583 MessageFactory 没有解析指南 对于消息,键入 0800 [080000000000000000000] 在 com.solab.iso8583.MessageFactory.parseMessage(MessageFactory.java:503( 在 com.solab.iso8583.MessageFactory.parseMessage(MessageFactory.java:366( 在 com.github.kpavlov.jreactive8583.netty.codec.Iso8583Decoder.decode(Iso8583Decoder.java:37( 在 io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:503( 在 io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:442( ...省略 22 个常见帧

默认情况下,jreactive 客户端和服务器在连接时每 30 秒发送一次回显消息。因此,您确实缺少此类消息的解析指南(0800,这是ISO 8583标准中的回显消息(。

您有两种选择:

  1. 通过将空闲超时设置为 0 来禁用回显消息。代码示例:
server.getConfiguration().setIdleTimeout(0);

但我敦促您使用 Builder 进行配置,因为您的某些代码现已弃用。例:

val serverConfiguration = ServerConfiguration.newBuilder()
.logSensitiveData(false)
.replyOnError(true)
.idleTimeout(0)
.build();
val server = new Iso8583Server<IsoMessage>(port, serverConfiguration, messageFactory);
  1. 提供j8583.xml消息的解析指南,在反应测试中有一个示例。在此处阅读更多相关信息。

最新更新