2

I came across an issue, when the jpos channel header string has spaces. I configured that in the channel adaptor configuration as below, but when I start the Q2 server, it seems it trims the header value. As a result of that, I'm not getting any response from the jpos server for certain requests.

<channel-adaptor class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2"  name="my-channel">
    <channel class="CBCChannel" logger="Q2"
             packager="org.jpos.iso.packager.GenericPackager" header="ISOHEADER        ">
        <property name="packager-config" value="/path/to/PACKAGER/iso87ascii.xml" />
        <property name="host" value="xxx.xx.xx.xx"/>
        <property name="port" value="yyyy" />

    </channel>
    <in>channel-send</in>
    <out>channel-receive</out>
    <property name="timeout" value="300000" />
    <property name="keep-alive" value="true" />
    <reconnect-delay>10000</reconnect-delay>
</channel-adaptor>

The CBCChannel just extends the RawChannel

public class CBCChannel extends RawChannel {

    public CBCChannel() throws ISOException {
    }

    public CBCChannel(String host, int port, ISOPackager p, byte[] header) {
        super(host, port, p, header);
    }

    public CBCChannel(ISOPackager p, byte[] header) throws IOException {
        super(p, header);
    }

    public CBCChannel(ISOPackager p, byte[] header, ServerSocket serverSocket) throws IOException {
        super(p, header, serverSocket);
    }
}

Is there any way to configure channel header which contains spaces without neglecting the spaces?

Chanikag
  • 1,419
  • 2
  • 18
  • 31
  • Hi, you have a custom channel implementation, as we can't know what it does or where channel it extends from we can't say how your setHeader is implemented and so we can't guide you. Please add the CBCChannel code, or at least the extends part if the rest is classeified. – Andrés Alcarraz Aug 16 '17 at 13:05
  • Hi Andres, I added the CBCChannel code. It just extends the RawChannel interface and do not do any thing for the header. – Chanikag Aug 16 '17 at 14:39
  • I don't know why you extended RawChannel if you didn't override any method, but anyway the main problem is that RawChannel expects a header of only digits, as it encodes them as bcd. – Andrés Alcarraz Aug 16 '17 at 16:20
  • when i set header inside the Constructor (without args) and remove the header config in the channel adaptor config, it works fine. But I need to move the header config out of the code. – Chanikag Aug 17 '17 at 03:12
  • Or what is the recommended way? – Chanikag Aug 18 '17 at 03:53
  • The recommended way is to override the setHeader method since RawChannel is expecting only digits. You need to override it and set the byte[] as you need from your header="" attribute. – Andrés Alcarraz Aug 23 '17 at 16:19
  • Thanks Andres. Got it working !!!!. I changed the header value inside the channel adaptor config with the converted byte[] value. For an example: . Thank you once again!!! – Chanikag Aug 29 '17 at 05:05
  • I @chanikag, I'm glad it worked but as you're sublassing a subclass of BaseChannel, for the sake of readability of the xml definition I would implement the setHeader as in my answer, and put the clear string in the header attribute of the channel. Best regards and good luck – Andrés Alcarraz Aug 29 '17 at 10:01

1 Answers1

0

I guess you only need to override setHeader method:

public CBCChannel extends RawChannel {
....
    public void setHeader(String header){
        super.setHeader(header.getBytes());
    }

}

But you would only be doing what BaseChannel does in regard to the header. Are you sure you need a RawChannel based channel?

Andrés Alcarraz
  • 1,570
  • 1
  • 12
  • 21