[英]How to send an ISO8583 message from client to server using jreactive-8583?
I have set up both the client and server using jreactive-8583.我已经使用 jreactive-8583 设置了客户端和服务器。 The client connects to the server successfully.客户端成功连接到服务器。 But I can't send ISO8583 message from client to the server.但是我无法从客户端向服务器发送 ISO8583 消息。 I am newly learning this and finding it hard to figure out the issue and solve it.我刚开始学习这个,发现很难找出问题并解决它。
Client side code客户端代码
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]
}
}
Server side code服务端代码
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]
}
}
Here is the link to the j8583.xml file I am using.这是我正在使用的 j8583.xml 文件的链接。 https://github.com/kpavlov/jreactive-8583/blob/master/src/test/resources/j8583.xml https://github.com/kpavlov/jreactive-8583/blob/master/src/test/resources/j8583.xml
I am getting the following error from both the client and the server.我从客户端和服务器收到以下错误。
18:30:29.435 [nioEventLoopGroup-2-1] ERROR com.solab.iso8583.MessageFactory - ISO8583 MessageFactory has no parsing guide for message type 0800 [08000000000000000000] 18:30:29.436 [nioEventLoopGroup-2-1] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. 18:30:29.435 [nioEventLoopGroup-2-1] 错误 com.solab.iso8583.MessageFactory - ISO8583 MessageFactory 没有消息类型 0800 的解析指南 [08000000000000000000] 18:30:290000000000000000000000000000000000000036] .channel.DefaultChannelPipeline - 一个 exceptionCaught() 事件被触发,它到达管道的尾部。 It usually means the last handler in the pipeline did not handle the exception.这通常意味着管道中的最后一个处理程序没有处理异常。 io.netty.handler.codec.DecoderException: java.text.ParseException: ISO8583 MessageFactory has no parsing guide for message type 0800 [08000000000000000000] at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:473) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:281) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:326) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:300) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.i io.netty.handler.codec.DecoderException: java.text.ParseException: ISO8583 MessageFactory 没有消息类型 0800 [080000000000000000000] 的解析指南,位于 io.netty.handler.codec.ByteToMessageDecoder.callDecode.ByteToMessageDecoder.callDecode(ByteToMessageDecoder) .netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:281) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(Abstract3ChannelHandler.invokeChannelRead(AbstractChannelHandlerContext.java:374) ) 在 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.i nvokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514) at io.netty.util. nvokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422) at io.netty.channel .AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java.931. io. channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) 在 io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700) 在 io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.processSelectedKey(NioEventLoop.java:700) java:635) at 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) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.text.ParseException: ISO8583 MessageFactory has no parsing guide for message type 0800 [08000000000000000000] at com.solab.iso8583.MessageFactory.parseMessage(MessageFactory.java:503) at com.solab.iso8583.MessageFactory.parseMessage(MessageFactory.java:366) at com.github.kpavlov.jreactive8583.netty.codec.Iso8583Decoder.decode(Iso8583Decoder.java:37) at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:503) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:442) ... 22 common frames omitted concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java: 30) 在 java.base/java.lang.Thread.run(Thread.java:834) 引起:java.text.ParseException:ISO8583 MessageFactory 在 com.solab.iso8583 上没有消息类型 0800 [08000000000000000000] 的解析指南。 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 个常用帧
The jreactive client and server both send echo messages every 30 seconds by default, when they're connected. jreactive 客户端和服务器在默认情况下每 30 秒发送一次回显消息,当它们连接时。 So you truly are missing a parsing guide for this type of message (0800, which is an echo message in the ISO 8583 standard).因此,您确实缺少此类消息的解析指南(0800,这是 ISO 8583 标准中的回显消息)。
You have two choices:你有两个选择:
server.getConfiguration().setIdleTimeout(0);
but I urge you to use a Builder for the configuration since some of your code is now deprecated.但我强烈建议您使用 Builder 进行配置,因为您的某些代码现已弃用。 Example:例子:
val serverConfiguration = ServerConfiguration.newBuilder()
.logSensitiveData(false)
.replyOnError(true)
.idleTimeout(0)
.build();
val server = new Iso8583Server<IsoMessage>(port, serverConfiguration, messageFactory);
j8583.xml
, there is an example in jreactive tests .提供j8583.xml
消息的解析指南,在jreactive 测试中有一个示例。 Read more about it here .在此处阅读更多相关信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.