0

jpos : how to handle messages with different headers with different length for incoming request and response

I have a below custom channel - the intentions is to handle different header of different length

package org.jpos.iso.channel;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOPackager;
import org.jpos.iso.packager.GenericPackager;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;

public class GWMipChannel extends NACChannel {

    byte[] madaHeader = {(byte) 0x00, (byte) 0x18, (byte) 0xd6, (byte) 0xf3, (byte) 0xf6, (byte) 0xf8, (byte) 0xf7};
    byte[] nitmxHeader = {(byte) 0x00, (byte) 0x18, (byte) 0xd6, (byte) 0xf3, (byte) 0xf7, (byte) 0xf3, (byte) 0xf2};
    byte[] response_mada_header = {(byte) 0x00, (byte) 0x18, (byte) 0xc9, (byte) 0xf3, (byte) 0xf6, (byte) 0xf8, (byte) 0xf7};


    protected byte[] readHeader(int hLen) throws IOException {

        byte[] header = new byte[25];
        serverIn.readFully(header, 0, 25);

        boolean mada_header = ByteBuffer.wrap(header, 0, 7).equals(ByteBuffer.wrap(madaHeader));
        boolean nitmx_header = ByteBuffer.wrap(header, 0, 7).equals(ByteBuffer.wrap(nitmxHeader));
        boolean rsp_mada_header = ByteBuffer.wrap(header, 0, 7).equals(ByteBuffer.wrap(response_mada_header, 0, 7));

        if (mada_header) {

            return header;
        } else if (nitmx_header) {

            header = Arrays.copyOf(header, 47);

            serverIn.readFully(header, 25, 22);

            return header;
        } else if (rsp_mada_header) {

            //serverIn.readFully(header, 0, 50);

            header = Arrays.copyOf(header, 50);

            serverIn.readFully(header, 0, 50);

            return header;

        }

        return header;
    }

    protected void sendMessageHeader(ISOMsg m, int len) throws IOException {
        byte[] header = m.getHeader();
        //assume header is the one to send, and already has 22 or 44 length
        //or you can check
        serverOut.write(header);


    }

}

in the q2 log I can see the messages are parsed correctly as per to the headers

<log realm="org.jpos.transaction.TransactionManager" at="2020-04-16T18:37:55.662" lifespan="555ms">
  <commit>
    gwmip-1:idle:1
    <context>
      TIMESTAMP: Thu Apr 16 18:37:55 AEST 2020
      SOURCE: org.jpos.iso.channel.X9AChannel@102579c0
      REQUEST:
       <isomsg direction="outgoing">
         <!-- org.jpos.iso.packager.GenericPackager[cfg/packager/iso87ascii-backup.xml] -->
         <header>0018D6F3F6F8F7000000000000000000000000000000000002</header>
         <field id="0" value="0200"/>
         <field id="2" value="5000100100700010"/>
         <field id="3" value="000000"/>
         <field id="4" value="002167959991"/>
         <field id="7" value="0416083755"/>
         <field id="11" value="199682"/>
         <field id="12" value="183753"/>
         <field id="13" value="0416"/>
         <field id="14" value="1612"/>
         <field id="18" value="4900"/>
         <field id="22" value="812"/>
         <field id="32" value="588850"/>
         <field id="33" value="004601"/>
         <field id="37" value="123451234512"/>
         <field id="41" value="UTIS2I25"/>
         <field id="42" value="EUREKAAIR      "/>
         <field id="43" value="01007/S2M_txn_base.mat rix_/ Parel M XYZ"/>
         <field id="48" value="54363130353030303031393230333132333432303730313033323132343332386A48796E2B3759466931455541524541414141764E5565364876383D" type="binary"/>
         <field id="49" value="356"/>
         <field id="61" value="10251000066003560000000000"/>
         <field id="63" value="MC2J2G6P8"/>
       </isomsg>

      DESTINATION: gwmip-AUTORESPONDER
      RESULT:
       <result/>

      :paused_transaction:
       id: 1

      RESPONSE:
       <isomsg direction="outgoing">
         <!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISebcdic_mada.xml] -->
         <header>0018C9F3F6F8F700000000000000000000000000000000000000000000000000000000000000000000000000000000000002</header>
         <field id="0" value="0210"/>
         <field id="2" value="165000100100700010"/>
         <field id="3" value="000000"/>
         <field id="4" value="002167959991"/>
         <field id="7" value="0416083755"/>
         <field id="11" value="199682"/>
         <field id="15" value="0416"/>
         <field id="32" value="06588850"/>
         <field id="33" value="06004601"/>
         <field id="37" value="123451234512"/>
         <field id="38" value="183755"/>
         <field id="39" value="00"/>
         <field id="41" value="UTIS2I25"/>
         <field id="48" value="060T6105000019203123420701032124328jHyn+7YFi1EUAREAAAAvNUe6Hv8="/>
         <field id="49" value="356"/>
         <field id="63" value="009MC2J2G6P8"/>
       </isomsg>

my server

<server class="org.jpos.q2.iso.QServer" logger="Q2" name="gwmip-server-5281" realm="gwmip-server-5281">
    <attr name="port" type="java.lang.Integer">5281</attr>
    <channel class="org.jpos.iso.channel.GWMipChannel"
             packager="org.jpos.iso.packager.GenericPackager"
             type="server"
             logger="Q2"
             header="6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"
            >
     <property name="packager-config"  value="cfg/packager/CISebcdic_mada.xml" debug="True" />
        <property name="timeout" value="180000"/>
    </channel>
    <request-listener class="org.jpos.iso.IncomingListener" logger="Q2" realm="incoming-request-listener">
        <property name="queue"  value="GWMIPTXNMGR" />
        <property name="ctx.DESTINATION"  value="gwmip-AUTORESPONDER" />
    </request-listener>
</server>

my issuer channel is

<?xml version="1.0" ?>

<channel-adaptor name='gwmip-channel' class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
    <channel class="org.jpos.iso.channel.X9AChannel"
             packager="org.jpos.iso.packager.GenericPackager"
             logger="Q2"
             header="6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002"
             >

         <property name="packager-config"  value="cfg/packager/iso87ascii-backup.xml" debug="True" />

        <property name="host" value="127.0.0.1" />
        <property name="port" value="9001" />
    </channel>
   <in>gwmip-send</in>
    <out>gwmip-receive</out>
    <reconnect-delay>10000</reconnect-delay>
</channel-adaptor>

The issue here is in the response 0210 message jpos sends only the second half 25 bytes as header not the 50 bytes as it received from the issuer.the first 25 bytes of header is not send.

  • I'm not sure I fully understand your question, but, why don't you use a different channel implementation for the connection to the issuer and the connection from the third party app? – Andrés Alcarraz Apr 15 '20 at 12:17
  • In readHeadr you are reading 25 bytes always from the stream, and then read 22 extra bytes in two of the ifs is that intended? 47 bytes of header for those cases? – Andrés Alcarraz Apr 15 '20 at 12:20
  • @AndrésAlcarraz I have modified the question with more details can you please help to solve this – Abrar Sheik Apr 16 '20 at 08:49
  • @AndrésAlcarraz sorry mate jpos was sending correct length , the issue is with the length 0018 was incorrect which is why the header was not able to parse.now all good – Abrar Sheik Apr 16 '20 at 11:11

0 Answers0