jpos :对于传入消息加载动态打包器有效,但不适用于传出消息

jpos : For incoming message loading dynamic packager works but not for outgoing message

我已经创建了自己的频道,基于 header 扩展 NAC 频道,它将动态加载打包程序。

根据 header 正确识别传入和传出消息(示例 mada_header 和 response_mada_header)的值,通道如下所示。

为 CISebcdic_mada.xml 的传入消息正确加载包,但对于传出消息,它不是动态加载的(预期是加载 CISebcdic_mada.xml),而是使用来自的默认打包程序服务器 xml 文件

    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) 0x31, (byte) 0xc9, (byte) 0xf3, (byte) 0xf6, (byte) 0xf8, (byte) 0xf7};
       
        byte[] message_header = null;
    
        @Override
        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 amex_header = ByteBuffer.wrap(header, 0, 7).equals(ByteBuffer.wrap(amexheader));
             boolean rsp_mada_header = ByteBuffer.wrap(header, 0, 7).equals(ByteBuffer.wrap(response_mada_header, 0, 7));
             boolean rsp_nitmx_header = ByteBuffer.wrap(header, 0, 7).equals(ByteBuffer.wrap(response_mada_header, 0, 7));
             boolean rsp_amex_header = ByteBuffer.wrap(header, 0, 7).equals(ByteBuffer.wrap(response_amexheader, 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 (amex_header){
    
                return header;
            }
            else if (rsp_mada_header) {
    
                //serverIn.readFully(header, 0, 50);
    
                header = Arrays.copyOf(header, 48);
    
                serverIn.readFully(header, 0, 48);
    
                return header;
            }
    
        else if (rsp_nitmx_header) {
    
            //serverIn.readFully(header, 0, 50);
    
            header = Arrays.copyOf(header, 50);
    
            serverIn.readFully(header, 0, 50);
    
            return header;
    
        }
            else{
                Exception e = new ISOException();
                e.printStackTrace();
            }
            this.message_header = header;
            return header;
        }
    
    
    @Override
        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);
    
    
        }
    
       @Override
        protected ISOPackager getDynamicPackager(byte[] header, byte[] message) {
    
           
           boolean md = ByteBuffer.wrap(header, 3, 4).equals(ByteBuffer.wrap(madaHeader,3,4));
            
           boolean nd = ByteBuffer.wrap(header, 0, 7).equals(ByteBuffer.wrap(nitmxHeader,0,7));

           ISOPackager genericPackager = null;
    
           if(nd) {
    
               try {
                   genericPackager = new GenericPackager("cfg/packager/AS2805_NITMX.xml");
               } catch (ISOException e) {
                   e.printStackTrace();
               }
    
           }
           if(md) {
    
               try {
                   genericPackager = new GenericPackager("cfg/packager/CISebcdic_mada.xml");
               } catch (ISOException e) {
                   e.printStackTrace();
               }
    
           }
    
           if(ax) {
    
               try {
                   genericPackager = new GenericPackager("cfg/packager/CISebcdic_AMX.xml");
               } catch (ISOException e) {
                   e.printStackTrace();
               }
           }
            return genericPackager;
        }
    }


我的server-xml文件-


<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="0018D6F3F7F3F2000000000000000000000000000000000002"

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

        <!--<property name="packager-config"  value="cfg/packager/iso93ebcdic-custom.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>


传入 XML ,其中为传入消息正确动态加载打包程序。 消息被转发给发行者主机


<log realm="channel/127.0.0.1:44158" at="2020-06-23T03:38:42.475" lifespan="872ms">
  <receive>
    <isomsg direction="incoming">
      <!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISebcdic_mada.xml] -->
      <header>0018D6F3F6F8F7000000000000000000000000000000000002</header>
      <field id="0" value="0200"/>
      <field id="2" value="5000100100700010"/>
      <field id="3" value="000000"/>
      <field id="4" value="000000000100"/>
      <field id="7" value="0623033838"/>
      <field id="11" value="033838"/>
      <field id="12" value="033838"/>
      <field id="13" value="0623"/>
      <field id="14" value="2006"/>
      <field id="18" value="4900"/>
      <field id="22" value="812"/>
      <field id="32" value="588850"/>
      <field id="33" value="004601"/>
      <field id="37" value="230620033838"/>
      <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="MC2MJG4F7"/>
    </isomsg>
  </receive>
</log>


传出消息(对传入消息的响应)如下 header 长度已正确加载,但打包程序未动态加载,即 CISebcdic_mada.xml 相反,它使用服务器 xml 文件中指定的默认打包程序,即 -CISebcdic_AMX.xml


<log realm="channel/127.0.0.1:44158" at="2020-06-23T03:38:42.504" lifespan="2ms">
  <send>
    <isomsg direction="outgoing">
      <!-- org.jpos.iso.packager.GenericPackager[cfg/packager/CISebcdic_AMX.xml] -->
      <header>0031C9F3F6F8F700000000000000000000000000000000000000000000000000000000000000000000000000000000000002</header>
      <field id="0" value="0210"/>
      <field id="2" value="5000100100700010"/>
      <field id="3" value="000000"/>
      <field id="4" value="000000000100"/>
      <field id="11" value="033838"/>
      <field id="12" value="033838"/>
      <field id="13" value="0623"/>
      <field id="15" value="0623"/>
      <field id="32" value="588850"/>
      <field id="33" value="004601"/>
      <field id="37" value="230620033838"/>
      <field id="38" value="033842"/>
      <field id="39" value="00"/>
      <field id="41" value="UTIS2I25"/>
      <field id="48" value="T6105000019203123420701032124328jHyn+7YFi1EUAREAAAAvNUe6Hv8="/>
      <field id="49" value="356"/>
      <field id="63" value="MC2MJG4F7"/>
    </isomsg>
  </send>
</log>


我需要做些什么才能为传出(响应消息)动态加载打包程序吗?

提前致谢

正如 getDynamicPackager(byte[], byte[]) 的 javadoc 所说:

    /**
     * allow subclasses to override default packager
     * on incoming messages
     * @param header message header
     * @param image incoming message image
     * @return ISOPackager
     */
     protected ISOPackager getDynamicPackager (byte[] header, byte[] image) {
         return getDynamicPackager(image);
     }

该方法用于覆盖传入消息的打包程序。

如果你想覆盖传出消息的打包器,你需要实现方法:


   /**
    * allow subclasses to override default packager
    * on outgoing messages
    * @param m outgoing ISOMsg
    * @return ISOPackager
    */
    protected ISOPackager getDynamicPackager (ISOMsg m) {
        return packager;
    }

为了实现该方法,您可以 return getDynamicPcakager(m.getHeader(), null) 因为您没有使用 message 参数。