JPOS Channel Sender exposed as a Jersey Rest Endpoint (duplicating messages)

116 views
Skip to first unread message

valentine ofili

unread,
Oct 19, 2017, 6:47:58 PM10/19/17
to jPOS Users
Hi all,

I implemented an iso client which builds an ISOMsg and packages this message with a Finacle Packager and connects to an ISO Interface to FINACLE

The channel implementation is  then wrapped as a method in a java class and exposed as a REST service which i implement with jersey rest library

I have and issue when testing the service from POSTMAN client.

When i make an initial request, the first ISO msg is built like this.

Enter code here...

import org.jpos.iso.ISOChannel;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.jpos.iso.ISOChannel;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMUX;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOPackager;
import org.jpos.iso.ISORequest;
import org.jpos.iso.channel.PostChannel;
import org.jpos.iso.packager.GenericPackager;
import org.jpos.iso.packager.PostPackager;
import org.jpos.space.SpaceFactory;
import org.jpos.util.LogEvent;
import org.jpos.util.LogSource;
import org.jpos.util.Logger;
import org.jpos.util.SimpleLogListener;
import java.util.UUID;
public class IsoServerConnectorProd {
    static ISOChannel channel = null;
    static ISOPackager packgr = null;
    static Logger logger = new Logger();
    static SimpleDateFormat sdf =  new SimpleDateFormat("ddMMyykkmmss");
    static SimpleDateFormat sdffulldatetime =  new SimpleDateFormat("yyyyMMddkkmmss");
    static SimpleDateFormat sdftime  =new SimpleDateFormat("kkmmss");
    static SimpleDateFormat sdfmonthdaytime= new SimpleDateFormat("MMddkkmmss");
    static SimpleDateFormat sdfmonthday = new SimpleDateFormat("MMdd");
    static SimpleDateFormat sdfyearmonthday = new SimpleDateFormat("yyyyMMdd");
    static Date currts = new Date();
    static String fixDate = sdfyearmonthday.format(new Date());  // String fixDate= sdfyearmonthday.format(currts);
    static SimpleDateFormat sdfrrn = new SimpleDateFormat("yyyyMMddhhss");
    
    static String dd = "";

    public static boolean isConnectedIsoServer(String address, String port) throws IOException,ISOException {
        if (channel == null) {
            logger.addListener(new SimpleLogListener(System.out));
           // packgr = new FinaclePackager();
           packgr = new FinaclePackager();
           org.apache.log4j.Logger flogger = org.apache.log4j.Logger.getLogger(IsoServerConnectorProd.class);
      //  ("E:\\projects\\settings\\finpack\\postpack_fin.xml");
                    //("E:\\projects\\settings\\finpack\\finacle.xml");
            channel = new PostChannel(address, Integer.parseInt(port), packgr);
           // channel.setPackager(new FinaclePackager());
           flogger.info("Establish a channel connection");
            ((LogSource) channel).setLogger(logger, "channel.web-channel-adaptor");
            channel.connect();

            if (!(channel.isConnected())) {
                Logger.log(new LogEvent("IsoServerConnector",
                        "Channel Error: Unable to establish connection to IsoServer Channel."));
                return false;
            }else{
                  flogger.info("Connected a channel connection");
                System.out.println("is channel Connected? "+channel.isConnected());
            }
        }

        return true;
    }

    public static void disconnect() {
        if (channel == null)
            return;
        try {
            if (channel.isConnected())
                channel.disconnect();
        } catch (IOException e) {
            Logger.log(new LogEvent("IsoServerConnector:disconnect", e));
        }
        channel = null;
    }


 public static ISOMsg sendIsoMessage(ISOMsg m, String timeout) throws IOException, ISOException {
        ISOMsg IsoMsgResponse = null;
        try {
            ISOMUX mux = new ISOMUX(channel);
            new Thread(mux).start();
            ISORequest r = new ISORequest(m);
            mux.queue(r);
            //channel.send(m);
            
            //IsoMsgResponse = channel.receive();
            IsoMsgResponse = r.getResponse(Integer.parseInt(timeout));
            mux.terminate();
            channel.disconnect();
        } catch (Exception e) {
            Logger.log(new LogEvent("IsoServerConnector:sendIsoMessage", e));
        }
       
        disconnect();
        return IsoMsgResponse;
    }


        public static ISOMsg doAccountransfer(String fromaccount, String toaccount,String amount, String narration){
        ISOMsg response = new ISOMsg();
        ISOMsg netMsg = new ISOMsg();
        String timestamp = sdftime.format(currts);
        BigDecimal dramount = new BigDecimal(amount).multiply(new BigDecimal("100"));
        String debitamount =  String.format("%016d",dramount.intValue());
        System.out.println("debit account "+fromaccount+" with "+    debitamount+ " credit account "+toaccount);
        try{
  
            isConnectedIsoServer("10.12.13.20", "4099");
            
           
                    netMsg.setMTI("1200");
                    netMsg.set(2,"1511345300004922");
                    netMsg.set(3,"400000");
                    netMsg.set(4,debitamount);
                    netMsg.set(11,timestamp);
                    netMsg.set(12,fixDate+timestamp);
                    //netMsg.set(15,"20170609");
                    netMsg.set(17,fixDate);
                    netMsg.set(24,"200");
                    netMsg.set(32,"667030");
                    netMsg.set(33,"111111");
                    netMsg.set(37,sdfrrn.format(new Date()));
                    netMsg.set(41,"000000003DIG0001");
                    netMsg.set(42,"DIGITAL BANKING");
                    netMsg.set(43,narration);
                    netMsg.set(46,"70000000000000000000000001D0000000000000000");
                    netMsg.set(49,"566");
                    netMsg.set(102,fromaccount);
                    netMsg.set(103,toaccount);
                    netMsg.set(123,"BNK");
                    netMsg.set(124,"ACD");
                    
                   
                 response = sendIsoMessage(netMsg, "0");
                 disconnect();
          
             
        }catch(Exception e){
            e.printStackTrace();
            disconnect();
        }
        return response;
        
    }



}

when this code executes the for the first time method doAccounttransfer the Outgoing and Inmessages sent are below:


Enter code here...
<log realm="channel.web-channel-adaptor/10.12.13.14:4999" at="Thu Oct 1 10:03:03 PST 2017.680">
Info:   <connect>
Info:   </connect>
Info:   </log>
Info:   2017-10-1 15:03:03 INFO  IsoServerConnectorProd:59 - Connected a channel connection
Info:   is channel Connected? true
Info:   <log realm="channel.web-channel-adaptor/10.12.13.14:4999" at="Thu Oct 1 10:03:03 PST 2017.680"">
Info:   <send>
Info:   <isomsg
Info:   direction="outgoing"
Info:   >
Info:   <field id="0" value="1200"/>
Info:   <field id="2" value="79999345300004922"/>
Info:   <field id="3" value="821000"/>
Info:   <field id="4" value="0000000000000000"/>
Info:   <field id="11" value="150303"/>
Info:   <field id="12" value="20171019150303"/>
Info:   <field id="17" value="20171019"/>
Info:   <field id="24" value="200"/>
Info:   <field id="32" value="667030"/>
Info:   <field id="33" value="111111"/>
Info:   <field id="37" value="201710190303"/>
Info:   <field id="41" value="F XXXXXXXXXXXX"/>
Info:   <field id="43" value="FUND TRANSFER"/>
Info:   <field id="46" value="D000000000000000000000001D000000000000000"/>
Info:   <field id="49" value="566"/>
Info:   <field id="102" value="5999970003"/>
Info:   <field id="123" value="DIG"/>
Info:   <field id="124" value="ACT"/>
Info:   </isomsg>
Info:   </send>
Info:   </log>
Info:   <log realm="channel.web-channel-adaptor/10.0.0.133:48057" at="Thu Oct 19 15:03:03 WAT 2017.888">
Info:   <receive>
Info:   <isomsg
Info:   direction="incoming"
Info:   >
Info:   <field id="0" value="1210"/>
Info:   <field id="2" value="XXXXXXXXXXXXXXX"/>
Info:   <field id="3" value="821000"/>
Info:   <field id="4" value="0000000000000000"/>
Info:   <field id="11" value="150303      "/>
Info:   <field id="12" value="20171019150303"/>
Info:   <field id="17" value="20171019"/>
Info:   <field id="32" value="667030"/>
Info:   <field id="33" value="111111"/>
Info:   <field id="37" value="XXXXXXXXX"/>
Info:   <field id="38" value="UNI000"/>
Info:   <field id="39" value="00"/>
Info:   <field id="41" value="000000003DIG0001"/>
Info:   <field id="42" value="XXXXXXXXXXXX"/>
Info:   <field id="46" value="70NGND000000000000000000000001D0000000000000000NGN"/>
Info:   <field id="48" value="+0000000002030450+0000000002030450+0000000000000000+0000000000000000+0000000002030450NGN              "/>
Info:   <field id="49" value="566"/>
Info:   <field id="123" value="BNK"/>
Info:   <field id="124" value="ACT"/>
Info:   <field id="125" value="C0181644 0"/>
Info:   <field id="126" value="209999190303"/>
Info:   <field id="127" value="XXXXXXXXXXXXSL01749;"/>
Info:   </isomsg>
Info:   </receive>
Info:   </log>
Info:   <log realm="channel.web-channel-adaptor/10.12.13.14:4999"" at="Thu Oct 19 15:03:03 WAT 2017.982">
Info:   <receive/>
Info:   </log>
Info:   <log realm="channel.web-channel-adaptor/10.12.13.14:4999"" at="Thu Oct 19 15:03:03 WAT 2017.982">
Info:   <disconnect>
Info:   </disconnect>
Info:   </log>
Info:   



This is a Normal Response

Now here is the ISSUE:
 When i call the web service method a second time

the request is duplicated and so is the response

<log realm="channel.web-channel-adaptor/10.0.0.133:48057" at="Thu Oct 19 15:03:33 WAT 2017.309">
Info:   <connect>
Info:   </connect>
Info:   </log>
Info:   2017-10-1 15:03:33 INFO  IsoServerConnectorProd:59 - Connected a channel connection
Info:   is channel Connected? true
Info:   <log realm="channel.web-channel-adaptor/10.12.13.14:49999" at="Thu Oct 1 15:03:33 WAT 2017.391">
Info:   <send>
Info:   <isomsg
Info:   direction="outgoing"
Info:   >
Info:   <field id="0" value="1200"/>
Info:   <field id="2" value="70999995300004922"/>
Info:   <field id="3" value="821000"/>
Info:   <field id="4" value="0000000000000000"/>
Info:   <field id="11" value="150303"/>
Info:   <field id="12" value="20171019150303"/>
Info:   <field id="17" value="20171019"/>
Info:   <field id="24" value="200"/>
Info:   <field id="32" value="667030"/>
Info:   <field id="33" value="111111"/>
Info:   <field id="37" value="201710190333"/>
Info:   <field id="41" value="000000003DIG0001"/>
Info:   <field id="42" value="FINANCIAL"/>
Info:   <field id="43" value="NAME ENQUIRY"/>
Info:   <field id="46" value="70NGND000000000000000000000001D0000000000000000NGN"/>
Info:   <field id="49" value="566"/>
Info:   <field id="102" value="50999994873"/>
Info:   <field id="123" value="BNK"/>
Info:   <field id="124" value="ACT"/>
Info:   </isomsg>
Info:   </send>
Info:   </log>
Info:   <log realm="channel.web-channel-adaptor/10.0.0.133:48057" at="Thu Oct 19 15:03:33 WAT 2017.395">
Info:   <send>
Info:   <isomsg
Info:   direction="outgoing"
Info:   >
Info:   <field id="0" value="1200"/>
Info:   <field id="2" value="8809999999904922"/>
Info:   <field id="3" value="821000"/>
Info:   <field id="4" value="0000000000000000"/>
Info:   <field id="11" value="150303"/>
Info:   <field id="12" value="20171019150303"/>
Info:   <field id="17" value="20171019"/>
Info:   <field id="24" value="200"/>
Info:   <field id="32" value="667030"/>
Info:   <field id="33" value="111111"/>
Info:   <field id="37" value="201710190333"/>
Info:   <field id="41" value="000000000001"/>
Info:   <field id="42" value="FINANCIAL"/>
Info:   <field id="43" value="NAMeNQU"/>
Info:   <field id="46" value="7D00000000000000000000000D0000000000000000N"/>
Info:   <field id="49" value="566"/>
Info:   <field id="102" value="518889994873"/>
Info:   <field id="123" value="BNK/>
Info:   <field id="124" value="ACT"/>
Info:   </isomsg>
Info:   </send>
Info:   </log>
Info:   <log realm="channel.web-channel-adaptor/10.0.0.133:48057" at="Thu Oct 19 15:03:33 WAT 2017.511">
Info:   <receive>
Info:   <isomsg
Info:   direction="incoming"
Info:   >
Info:   <field id="0" value="1210"/>
Info:   <field id="2" value="7500345300004922"/>
Info:   <field id="3" value="821000"/>
Info:   <field id="4" value="0000000000000000"/>
Info:   <field id="11" value="150303      "/>
Info:   <field id="12" value="20171019150303"/>
Info:   <field id="17" value="20171019"/>
Info:   <field id="32" value="667030"/>
Info:   <field id="33" value="111111"/>
Info:   <field id="37" value="201710190333"/>
Info:   <field id="38" value="UNI000"/>
Info:   <field id="39" value="000"/>
Info:   <field id="41" value="000000003DIG0001"/>
Info:   <field id="42" value="FINANCIAL TRANSFER"/>
Info:   <field id="46" value="70NGND000000000000000000000001D0000000000000000NGN"/>
Info:   <field id="48" value="+0000000002030450+0000000002030450+0000000000000000+0000000000000000+0000000002030450NGN              "/>
Info:   <field id="49" value="566"/>
Info:   <field id="123" value="BNK"/>
Info:   <field id="124" value="ACT"/>
Info:   <field id="125" value="C0181644AA  0000000000000000"/>
Info:   <field id="126" value="201710190333"/>
Info:   <field id="127" value="5100UCBO749;"/>
Info:   </isomsg>
Info:   </receive>
Info:   </log>
Info:   <log realm="channel.web-channel-adaptor/10.12.13:4999" at="Thu Oct 1 15:03:33 WAT 2017.511">
Info:   <receive>
Info:   <isomsg
Info:   direction="incoming"
Info:   >
Info:   <field id="0" value="1210"/>
Info:   <field id="2" value="7999945300004922"/>
Info:   <field id="3" value="821000"/>
Info:   <field id="4" value="0000000000000000"/>
Info:   <field id="11" value="150303      "/>
Info:   <field id="12" value="20171019150303"/>
Info:   <field id="17" value="20171019"/>
Info:   <field id="32" value="667030"/>
Info:   <field id="33" value="111111"/>
Info:   <field id="37" value="201710190333"/>
Info:   <field id="38" value="UNI000"/>
Info:   <field id="39" value="000"/>
Info:   <field id="41" value="000000003DIG0001"/>
Info:   <field id="42" value="FINANCIAL"/>
Info:   <field id="46" value="70000000000000000000000000000000000000"/>
Info:   <field id="48" value="+0000000002030450+0000000002030450+0000000000000000+0000000000000000+0000000002030450NGN              "/>
Info:   <field id="49" value="566"/>
Info:   <field id="123" value="BNK"/>
Info:   <field id="124" value="ACT"/>
Info:   <field id="125" value="C01816DAA                                                                                                                                                                                                                                                     31300001     +0000000000000000+0000000000000000"/>
Info:   <field id="126" value="201710190333"/>
Info:   <field id="127" value="510027"/>
Info:   </isomsg>
Info:   </receive>
Info:   </log>




I'm looking forward to a response.

Thanks you






Reply all
Reply to author
Forward
0 new messages