4

I am using jpos client (In one of the class of java Spring MVC Program) to connect the ISO8585 based server, however due to some reason server is not able to respond back, due to which my program keeps waiting for the response and results in hanging my program. So what is the proper way to implement connection timeout? My client program look like this:

public FieldsModal sendFundTransfer(FieldsModal field){
        try {
            JposLogger logger = new JposLogger(ISO_LOG_LOCATION);
            org.jpos.iso.ISOPackager customPackager = new GenericPackager(ISO_PACKAGER);
            ISOChannel channel = new PostChannel(ISO_SERVER_IP, Integer.parseInt(ISO_SERVER_PORT), customPackager);// live
            logger.jposlogconfig(channel);
            channel.connect();

            log4j.info("Connection established using PostChannel");

            ISOMsg m = new ISOMsg();
            m.set(0, field.getMti());
            //m.set(2, field.getField2());
            m.set(3, field.getField3());
            m.set(4, field.getField4());
            m.set(11, field.getField11());
            m.set(12, field.getField12());
            m.set(17, field.getField17());
            m.set(24, field.getField24());
            m.set(32, field.getField32());
            m.set(34, field.getField34());
            m.set(41, field.getField41());
            m.set(43, field.getField43());
            m.set(46, field.getField46());
            m.set(49, field.getField49());
            m.set(102,field.getField102());
            m.set(103,field.getField103());
            m.set(123, field.getField123());
            m.set(125, field.getField125());
            m.set(126, field.getField126());
            m.set(127, field.getField127());

            m.setPackager(customPackager);
            System.out.println(ISOUtil.hexdump(m.pack()));
            channel.send(m);
            log4j.info("Message has been send");

            ISOMsg r = channel.receive();
            r.setPackager(customPackager);
            System.out.println(ISOUtil.hexdump(r.pack()));

            channel.disconnect();

        }catch (Exception err) {
            System.out.println("sendFundTransfer : " + err);

        }
        return field;
    }

1 Answers1

2

Well the real proper way would be to use Q2. Given you don't need a persistent connection you coud just set a timeout for the channel.

PostChannel channel = new PostChannel(ISO_SERVER_IP, Integer.parseInt(ISO_SERVER_PORT), customPackager);// live
channel.setTimeout(timeout); //timeout in millies. 

This way channel will autodisconnect if nothing happens during the time specified by timeout , and your call to receive will throw an exception.

The alternative is using Q2 and a mux (see QMUX, for which you need to run Q2, or ISOMUX which is kind of deprecated).

Andrés Alcarraz
  • 1,570
  • 1
  • 12
  • 21
  • I have used Q2 for routing and as a server as a standalone server, however i havn't used Q2 only as client. However in existing code I am not able to find setTimeout method in ISOChannel interface. Kindly suggest if i can do any tweaking to implement the same. I am using jpos-1.9.2.jar – Diwas Sapkota Jul 11 '18 at 10:29
  • 1
    You need to access the channel as PostChannel to do that. so I would suggest declare channel as PostChannel or BaseChannel. – Andrés Alcarraz Jul 11 '18 at 11:00
  • Had a similar issue, however am using AsciiChannel. Running standalone jpos samples it works fine but combining with Spring boot still got 'Read timeout' – Duncan O. N. Oct 02 '19 at 08:30