javaiso8583jpos

How can I use the `org.jpos.iso.filter.StatefulFilter` in server channel to send back the outgoing value that I got from incoming?


I tried to use the StatefulFilter but I am not able to achieve what I just wanted. I have the below configuration for the server. For particular ISO fields (field 7) I want to I want to reply back with the same value as was sent by the client. If an inbuilt filter like org.jpos.iso.filter.StatefulFilter can do this I would not choose to add the logic through the code.

<server name="eSewa-server-65000" class="org.jpos.q2.iso.QServer" logger="Q2">
    <attr name="port" type="java.lang.Integer">65000</attr>
    <attr name="minSessions" type="java.lang.Integer">1</attr>
    <attr name="maxSessions" type="java.lang.Integer">5</attr>
    <property name="debug" value="true"/>


    <channel class="org.jpos.iso.channel.TelnetXMLChannel"
             packager="org.jpos.iso.packager.XMLPackager"
             type="server"
             logger="Q2"
             realm="server-channel-65000">
                <filter class="org.jpos.iso.filter.StatefulFilter" logger="Q2" realm="server-StatefulFilter-65000">
                    <property name="direction" value="outgoing"/>
                    <property name="saved-fields" value="7"/>
                </filter>
   
        <property name="timeout" value="30000"/>       
        <filter class="org.jpos.iso.filter.DebugFilter" direction="incoming"/>   

    </channel>

    <request-listener class="org.jpos.iso.IncomingListener" logger="Q2"
                      realm="incoming-request-listener">
        <property name="space" value="tspace:default"/>
        <property name="queue" value="TXNMGR"/>
        <property name="ctx.DESTINATION" value="jPOS-AUTORESPONDER"/>
        <property name="timeout" value="30000"/>
    </request-listener>
</server>

Solution

  • You need to change the direction property to incoming, from the StatefulFilter javadoc on matchDirection:

    What messages should I match?

    INCOMING: outgoing messages will be matched against the previous incoming messages

    OUTGOING: incoming messages will be matched against the previous outgoing messages

    And it seems you want to match the previously incoming request, when you send a response to include the original DE 7.

    You'd need to change the StatefulFilter definition to:

    <filter class="org.jpos.iso.filter.StatefulFilter" logger="Q2" realm="server-StatefulFilter-65000">
        <property name="direction" value="incoming"/> 
        <property name="saved-fields" value="7"/>
    </filter>
    

    Actually, incoming is the default if not defined, because it's the most common use case, unless you want to match it in the channel that talks to the other end of your gateway. But (I believe) the most common use case if for retrieving something that precisely is lost in the internal use, but the client expects to receive the same value in the request.

    Well it's not a much used filter and its implementation has some issues. For instance, it does not check the MTI matches, and you cannot add field 0 to the key, because the MTI of the response will not match the one of the request. It should do what QMUX does, but its implementation is too basic.