jpos : how to handle messages with different headers with different length listening to the same endpoint and using same packager

假装没事ソ 提交于 2020-06-29 04:10:09

问题


The scenario is a third party application will send messages to jpos. possibility is that it will send two types of messages with different message header length say one will be length 22 bytes and another will be 44 bytes.the packager will be same.

How can I handle both the messages and route it to the issuers based on the header type? The first 4 bytes in the header will give me the clue what will be header length.

For example

f3f8f6f7 -- means header length is 22 bytes

f4f5f6f7 -- means header length is 44 bytes

sample : header="3867000000000000000002" or "45670000000000000000021601" upto 44

I am not sure where to start. I understand I can create two channels but issue is I have to listen from one endpoint port

If I want to create a custom channel what is the best way to handle this scenario? Just thinking is it possible to handle as below, in the channel header property I can specify multiple headers?

<server class="org.jpos.q2.iso.QServer" logger="Q2" name="gwmip-server-7003" realm="bnet-server-8000">
    <attr name="port" type="java.lang.Integer">7003</attr>
    <channel class="org.jpos.iso.channel.NACChannel"
             packager="org.jpos.iso.packager.GenericPackager"
             type="server"
             logger="Q2"
             header="3687000000000000000002" or "3687000000000000000002"
             >
     <property name="packager-config"  value="cfg/packager/CISebcdic.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="jPOS-AUTORESPONDER" />
    </request-listener>
</server>

I have no clue how to handle this.


回答1:


First of all if you can avoid that, please do it. Do you really need to send two different header lengths for the same application?

As you said it's a third party application I will assume the answer is yes.

Second, by any chance can the application send 22 header length messages to a port different than the 44 header length messages?

If yes, the simplest thing would be to have two servers each configured with a different header. This solution would not require coding.

The other option would involve coding to write your own channel and it's described as follows.

You just need to create your own Channel implementation.

For instance you can extend NACCHannel and override sendMessageHeader and readHeader methods:

public class CustomChannel extends NACChannel {
    byte [] len22Header = {(byte)0xf3,(byte)0xf8,(byte)0xf6,(byte)0xf7};
    byte [] len44Header = {(byte)0xf4,(byte)0xf5,(byte)0xf6,(byte)0xf7};

    protected byte[] readHeader(int hLen) throws IOException {
        byte[] header = new byte[22];
        serverIn.readFully(header, 0, 22);
        if (Arrays.equals(header, len22Header, 0, 4)) {
            return header;
        }
        header = Arrays.copyOf(header, 44);
        serverIn.readFully(header, 22, 22);
    }

    protected 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);
    }
}

Then you just use your channel in the server xml instead of NACChannel

<server class="org.jpos.q2.iso.QServer" logger="Q2" name="gwmip-server-7003" realm="bnet-server-8000">
    <attr name="port" type="java.lang.Integer">7003</attr>
    <channel class="your.package.CustomChannel"
             packager="org.jpos.iso.packager.GenericPackager"
             type="server"
             logger="Q2"
             >
     <property name="packager-config"  value="cfg/packager/CISebcdic.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="jPOS-AUTORESPONDER" />
    </request-listener>
</server>


来源:https://stackoverflow.com/questions/60885678/jpos-how-to-handle-messages-with-different-headers-with-different-length-liste

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!