How to send an ISO8583 message from client to server using jreactive-8583?

4.6k views Asked by At

I have set up both the client and server using jreactive-8583. The client connects to the server successfully. But I can't send ISO8583 message from client to the server. 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. 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. 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.invokeChannelRead(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.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

1

There are 1 answers

0
solnaranu On

The jreactive client and server both send echo messages every 30 seconds by default, when they're connected. So you truly are missing a parsing guide for this type of message (0800, which is an echo message in the ISO 8583 standard).

You have two choices:

  1. Disable echo messages by setting idleTimeout to 0. Example with your code:
server.getConfiguration().setIdleTimeout(0);

but I urge you to use a Builder for the configuration since some of your code is now deprecated. Example:

val serverConfiguration = ServerConfiguration.newBuilder()
  .logSensitiveData(false)
  .replyOnError(true)
  .idleTimeout(0)
  .build();

val server = new Iso8583Server<IsoMessage>(port, serverConfiguration, messageFactory);
  1. Provide a parsing guide for messages in j8583.xml, there is an example in jreactive tests. Read more about it here.