jpos / jPOS

jPOS Project
http://jpos.org
GNU Affero General Public License v3.0
607 stars 460 forks source link

VAPChannel is not able to log header while sending message #358

Open nalasra opened 3 years ago

nalasra commented 3 years ago

Hello,

I am working with Visa Base I and I encountered a situation where the logger wasn't logging the header component of ISOMsg while sending an ISOMsg with overrided header. Although the header bytes are sent correctly to the endpoint.

FYI, I am using logon manager to send sign on and echo message.

I checked my 10_visa_client_channel.xml configuration

<?xml version="1.0" ?>
<channel-adaptor name='visa-channel' class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
 <channel class="org.jpos.iso.channel.VAPChannel" logger="Q2" realm="visa-channel" packager="org.jpos.iso.packager.GenericPackager" >
  <property name="packager-config" value="jar:packager/base1.xml" />
  <property name="packager-logger" value="Q2" />
  <property name="host" value="@visa_remote_host@"/>
  <property name="port" value="@visa_remote_port@" />
  <property name="timeout" value="300000" />
  <property name="trailer" value="false" />
  <property name="srcid" value="@src_station_id@" />
  <property name="override-header" value="true"/> 
 </channel>  
 <in>visa-send</in>
 <out>visa-receive</out>
 <reconnect-delay>10000</reconnect-delay>
</channel-adaptor>

Found out that VAPChannel.sendMessageHeader doesn't set the header of the ISOMsg. The following trick resolves the issue for me.

protected void sendMessageHeader(ISOMsg m, int len)
        throws IOException {
    ISOHeader h = !isOverrideHeader() && m.getHeader() != null ?
            m.getISOHeader() :
            new BASE1Header(srcid, dstid, headerFormat);

    if (h instanceof BASE1Header)
        ((BASE1Header) h).setLen(len);

    //ASK: set the header to the ISOMsg object so it can be logged by Logger
    m.setHeader(h);
    serverOut.write(h.pack());
}

Please let me know if there is anything I am missing in my configuration.

Thanks

ar commented 3 years ago

The VAPChannel actually sends the header down the wire when it calls serverOut.write(h.pack()).

It doesn't set it back into the ISOMsg because depending of the override-header value, those values could be different.

I can see how this can be confusing when analyzing logs, but I think setting back the header into the ISOMsg could create some production issues, specially in situations where the ISOMsg gets transmitted to more than one endpoint, header's swapDirection gets called, etc.

In order to add your suggested patch, I think we'd need a new property to indicate that we want the channel to force the header back into the ISOMsg, with a default to false.

alcarraz commented 3 years ago

Or we can just add a property to the channel to just log the header sent somehow?

So we don't have to swset the header to the message in order to see it.

El 21/10/20 a las 13:34, Alejandro Revilla escribió:

The VAPChannel actually sends the header down the wire when it calls |serverOut.write(h.pack())|.

It doesn't set it back into the ISOMsg because depending of the override-header value, those values could be different.

I can see how this can be confusing when analyzing logs, but I think setting back the header into the ISOMsg could create some production issues, specially in situations where the ISOMsg gets transmitted to more than one endpoint, header's |swapDirection| gets called, etc.

In order to add your suggested patch, I think we'd need a new property to indicate that we want the channel to force the header back into the ISOMsg, with a default to |false|.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jpos/jPOS/issues/358#issuecomment-713781414, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA42RO5OVBP2HI32NKRIYJ3SL4SSZANCNFSM4S2C2DGQ.

ar commented 3 years ago

We can, but we don't have access to the LogEvent object in sendMessageHeader, we can of course log as a separate event, or change the signature, and make it backward compatible, but not sure it's worth the effort. In my humble experience, these header things just happens in the very early development days, once this is nailed down and you go to production, you forget about the headers, they just work, year after year.