Message Length

86 views
Skip to first unread message

pks!!@

unread,
Dec 21, 2016, 6:27:06 AM12/21/16
to jPOS Users
Hi,
 Here I am using ASCIIChannel (Override getMessageLength & sendMessageLength) & ISO87APackager. IsoMessage Sending to server but not able to length as prefix.When I debug code then, in ASCIIChannel serverIn.readFully(b, 0, 4) shows EOF exception, value for serverIn.available() also shows 0. Header is going with message but not length.

Am i missing any specific point ?
Please guide on this point. 

Thanks & regards
 pK.

chhil

unread,
Dec 21, 2016, 8:19:04 AM12/21/16
to jpos-...@googlegroups.com

Here is a simple test code, a client using AsciiChannel and ISO87APackager connects to a netcat server.

import java.io.IOException;

import org.jpos.iso.ClientChannel;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.channel.ASCIIChannel;
import org.jpos.iso.packager.ISO87APackager;

public class Test {

    public static void main(String[] args) throws ISOException, IOException {

        ClientChannel cs = new ASCIIChannel("127.0.0.1", 7666, new ISO87APackager());
        ISOMsg m = new ISOMsg();
        m.setMTI("0200");
        m.set(2, "123456789");
        cs.connect();
​ // make sure netcat server is already running​
cs.send(m); } }

Netcat server listening on port 7666. And data received from your jpos client. The the first 4 [0031] is the 4 byte ascii length prepended by the AsciiChannel.
C:\>ncat -l 7666 
00310200400000000000000009123456789
-chhil

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/bf2f260a-172c-45ff-946c-d767899ebda0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pks!!@

unread,
Dec 21, 2016, 8:56:36 AM12/21/16
to jPOS Users

Hi Chhil,

Very Thanks for your valuable response. Yes your suggestion is working fine but, I have build a demo server using ASCIIChannel & ISO87APackager and this server not getting length as prefix from client.Here i am getting header as prefix very well.

One more point at your suggested example on "ISOUtil.hexdump(m.pack())" ,i am not getting header & length with message.

Here You can analyze my server code:-

    public static void main(String[] args) {
       try{
            Logger logger = new Logger();
            logger.addListener(new SimpleLogListener(System.out));
            ServerChannel channel = new org.jpos.iso.channel.ASCIIChannel(new ISO87APackager(),null);
            ((LogSource) channel).setLogger(logger, "channel");
            ISOServer server = new ISOServer(port, channel, null);
            server.setLogger(logger, "server");
            server.addISORequestListener(new MainApp(box));
            new Thread(server).start();                  
       }catch(Exception e){
           e.printStackTrace();
       }
    }

    private MainApp(Properties box) {
        super();
        this.box = box;
    }
    
    @Override
    public boolean process(ISOSource isoSrc, ISOMsg isoMsg) {
        try {
                ISOMsg reply = (ISOMsg) isoMsg.clone();
                reply.setResponseMTI();
                reply.set(39, "00");
                isoSrc.send(reply);
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }


Please point me out at missing point.


Thanks & regards
 pK.

Andrés Alcarraz

unread,
Dec 21, 2016, 9:05:57 AM12/21/16
to jpos-...@googlegroups.com

Hi PK, interpreting what you are saying problem is that the client is not sending as lenght what you are expecting ?

It's really difficult to help givn the lack of information, an hexdump with the stream your client is sending would be helpful. The most probably thing is that your channel is not aligned with your client.

Best regards


El 21/12/16 a las 10:56, pks!!@ escribió:
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.

To post to this group, send email to jpos-...@googlegroups.com.

Mark Salter

unread,
Dec 21, 2016, 9:07:30 AM12/21/16
to jPOS Users


On Wednesday, December 21, 2016 at 1:56:36 PM UTC, pks!!@ wrote:
I have build a demo server using ASCIIChannel & ISO87APackager and this server not getting length as prefix from client.
What are you getting?

Please ask a smart question :- http://www.catb.org/~esr/faqs/smart-questions.html#before

pks!!@

unread,
Dec 21, 2016, 9:21:11 AM12/21/16
to jPOS Users
Hi,

Sorry to missing clarification at question.

I have made demo client & demo Server. Now, I am sending IsoMessage from client & receiving at Server side.
At client side i am setting header to isomessage & getting same on server side but, on server side i have to get message length also as prefix of message.
Both side i am using same channel & packager.

Hope now clears my point on which i need your guide.


Thanks & regards
 pK.

Andrés Alcarraz

unread,
Dec 21, 2016, 9:36:12 AM12/21/16
to jpos-...@googlegroups.com

Sorry to say that does not clarify enough, please share your server and client code. If you are using same channel and same packager, there is no way that you receive something different from what you send. ASCIIChannel and ISO87APackager are widely tested and used everwhere.

Pleas as Mark suggested ask a smart question


El 21/12/16 a las 11:21, pks!!@ escribió:
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.

pks!!@

unread,
Dec 21, 2016, 9:49:38 AM12/21/16
to jPOS Users
Hi,

Here as below my democlient & demoserver code.

public class Client extends ISOBasePackager{


    public static void main(String[] args) {

        ISO87BPackager isoPkg = new ISO87BPackager();
        ClientChannel channel = new ASCIIChannel("localhost", PORT, new ISO87APackager());
        try{
            Logger logger = new Logger();
            logger.addListener(new SimpleLogListener(System.out));
            ((LogSource) channel).setLogger(logger, "channel");
            channel.connect();
            ISOMsg reqMessage = new ISOMsg();                       
    reqMessage.setHeader("XXXXXXXXXXXXXXXXXXXXXX".getBytes());
            reqMessage.setMTI("200");
            reqMessage.set(3, "12908");         
            
            channel.send(reqMessage);
            ISOMsg r = channel.receive();
            channel.disconnect();
            
        }catch(Exception e){
            e.printStackTrace();
        }       
    }
}

******************

public class Server implements ISORequestListener{
    
    public static void main(String[] args) {
       try{
       System.out.println(ISOUtil.hexdump(isoMsg.pack()));
            Logger logger = new Logger();
            logger.addListener(new SimpleLogListener(System.out));
            ServerChannel channel = new org.jpos.iso.channel.ASCIIChannel(new ISO87APackager(),null);
            ((LogSource) channel).setLogger(logger, "channel");
            ISOServer server = new ISOServer(PORT, channel, null);
            server.setLogger(logger, "server");
            server.addISORequestListener(new MainApp(box));
            new Thread(server).start();                  
       }catch(Exception e){
           e.printStackTrace();
       }
    }

    private MainApp(Properties box) {
        super();
        this.box = box;
    }
    
    @Override
    public boolean process(ISOSource isoSrc, ISOMsg isoMsg) {
        try {
                ISOMsg reply = (ISOMsg) isoMsg.clone();
                reply.setResponseMTI();
                reply.set(39, "00");
                isoSrc.send(reply);
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}


Please guide me where am i missing.

Thanks & regards
 pK.

Andrés Alcarraz

unread,
Dec 21, 2016, 9:53:34 AM12/21/16
to jpos-...@googlegroups.com

Your problem is that you are sending a message with a header but on the server you are not configuring the channel to expect that header.


El 21/12/16 a las 11:49, pks!!@ escribió:
--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.

chhil

unread,
Dec 21, 2016, 12:31:40 PM12/21/16
to jpos-...@googlegroups.com
Andres is absolutely right.
You need to provide your server channel with a dummy header so that it can account for the header in your code.
What you will see in the example below, even if the server channel is set with a header value, it simply uses its length to determine the number of bytes it expects.
The logged value will show you that received value is 01234 (3031323334) and not 56789


import java.io.IOException;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISORequestListener;
import org.jpos.iso.ISOServer;
import org.jpos.iso.ISOSource;
import org.jpos.iso.channel.ASCIIChannel;
import org.jpos.iso.packager.ISO87APackager;
import org.jpos.util.Logger;
import org.jpos.util.SimpleLogListener;
import org.jpos.util.ThreadPool;

public class Test {

    public static void main(String[] args) throws ISOException, IOException {

        Logger l = new Logger();
        l.addListener(new SimpleLogListener());
        ASCIIChannel sc = new ASCIIChannel(new ISO87APackager());
        sc.setHeader("56789".getBytes());
        sc.setLogger(l, "serverchannel");
        ISOServer server = new ISOServer(7776, sc, new ThreadPool(10, 100));
        server.setLogger(l, "server");
        server.addISORequestListener(new ISORequestListener() {

            @Override
            public boolean process(ISOSource source, ISOMsg m) {
                m.dump(System.out, ">>");

                return true;
            }
        });
        Thread t = new Thread(server);
        t.start();
        ASCIIChannel cs = new ASCIIChannel("127.0.0.1", 7776, new ISO87APackager());
        cs.setLogger(l, "clientchannel");
        ISOMsg m = new ISOMsg();
        m.setMTI("0200");
        m.set(2, "123456789");
        m.setHeader("01234".getBytes());
        cs.connect();
        cs.send(m);
    }
}

Output 
<log realm="server" at="Wed Dec 21 22:59:11 IST 2016.185" lifespan="45ms">
  <iso-server>
    listening on port 7776
  </iso-server>
</log>
<log realm="clientchannel/127.0.0.1:7776" at="Wed Dec 21 22:59:11 IST 2016.198" lifespan="60ms">
  <connect>
    127.0.0.1:7776
  </connect>
</log>
<log realm="clientchannel/127.0.0.1:7776" at="Wed Dec 21 22:59:11 IST 2016.209" lifespan="11ms">
  <send>
    <isomsg direction="outgoing">
      <!-- org.jpos.iso.packager.ISO87APackager -->
      <header>3031323334</header>
      <field id="0" value="0200"/>
      <field id="bitmap" value="{2}" type="bitmap"/>
      <field id="2" value="123456789"/>
    </isomsg>
  </send>
</log>
<log realm="serverchannel/127.0.0.1:39561" at="Wed Dec 21 22:59:11 IST 2016.210" lifespan="9ms">
  <receive>
    <isomsg direction="incoming">
      <!-- org.jpos.iso.packager.ISO87APackager -->
      <header>3031323334</header>
      <field id="0" value="0200"/>
      <field id="bitmap" value="{2}" type="bitmap"/>
      <field id="2" value="123456789"/>
    </isomsg>
  </receive>
</log>
>><isomsg direction="incoming">
>>  <!-- org.jpos.iso.packager.ISO87APackager -->
>>  <header>3031323334</header>
>>  <field id="0" value="0200"/>
>>  <field id="bitmap" value="{2}" type="bitmap"/>
>>  <field id="2" value="123456789"/>
>></isomsg>
-chhil

To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.

To post to this group, send email to jpos-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/397f5b4b-3092-40f1-8306-8cd34ef79a4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.

To post to this group, send email to jpos-...@googlegroups.com.

Alejandro Revilla

unread,
Dec 21, 2016, 4:35:04 PM12/21/16
to jPOS Users
Andres is absolutely right.

​Andres is a distinguished professor at a prestigious university, he's always right :) :) :)


pks!!@

unread,
Dec 21, 2016, 11:42:11 PM12/21/16
to jPOS Users
Hi Good Morning,

 Thanks to all of you for your valuable guideline & hope i am little closer to my need.
 Yes, your are absolutely correct. As i know with help of jpos guide pdf header contains all information about message.But i need something else.

 Here i am sending request iso message from client is as below.

reqMessage.setHeader("01ISO1".getBytes());            
reqMessage.setMTI("200");
reqMessage.set(3, "123456");


at server side on console i am getting as below

<log realm="channel/127.0.0.1:49744" at="Thu Dec 22 09:52:51 IST 2016.409" lifespan="32ms">
  <receive>
    <isomsg direction="incoming">
      <!-- org.jpos.iso.packager.ISO87APackager -->
      <header>303149534F31</header>
      <field id="0" value="0200"/>
      <field id="3" value="123456"/>
    </isomsg>
  </receive>
</log>

0000  30 32 30 30 32 30 30 30  30 30 30 30 30 30 30 30  0200200000000000
0010  30 30 30 30 31 32 33 34  35 36                    0000123456

you can see the hex dump output does not have header & message length as prefix.

Here, i am expecting hexdump as below. ( & message length also should be in hex format in prefix)

0000  30 31 49 53 4F 31 30 32 30 30 32 30 30 30 30 30  01ISO10200200000
0010  30 30 30 30 30 30 30 30 30 30 31 32 33 34 35 36  0000000000123456

One more thing in 2nd attempt (scenario) when i override sendMessageLength & getMessageLength of ASCIIChannel ( as custom channel ) at client side.
then, at sendMessageLength method 
 serverOut.write(ISOUtil.zeropad(String.valueOf(len), 4).getBytes()); 
works very well but at getMessageLength method 
 serverIn.readFully(b,0,4);
shows EOF exception and when i check serverIn.available() it return 0 (zero).


Please suggest me the right way to get it.


Thanks & regards
 pK.



chhil

unread,
Dec 22, 2016, 1:43:27 AM12/22/16
to jpos-...@googlegroups.com
The log has data in a form that you are not interpreting correctly.
Length header is never logged (if you want to , extend the AsciiChannel and log it in getMessageLength and sendMessageLength methods). But since the message is logged in the<receive>, rest assured, jpos channel figured out the length and unpacked your message to display it correctly in the xml you see.

The header gets logged in hex for viewing.
So your expectation of 
0000  30 31 49 53 4F 31 30 32 30 30 32 30 30 30 30 30  
​​
01ISO10200200000
is partially met by hex part in your dump.
<header>303149534F31</header>

The iso messages hexdump done by you will not log the header. You can get to the header if you want, by
System.out.println(ISOUtil.hexdump(m.getHeader()));
You can concatenate byte arrays of the length, header, isomsg and do a hexdump in your custom channel implementation.

On a side note, hexdumps are good for debugging, but they are not pci compliant as you log everything in the clear. Its also good to 
look at the source to see how the channel handles the length, header, message , trailer etc to avoid confusion.
 

To your one more thing when you override clientChannel code. Please provide a reproducer, I cannot reproduce what you are seeing.

Below is Server channel using jpos AsciiChannel and client using extended AsciChannelEx
import java.io.IOException;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISORequestListener;
import org.jpos.iso.ISOServer;
import org.jpos.iso.ISOSource;
import org.jpos.iso.ISOUtil;
import org.jpos.iso.channel.ASCIIChannel;
import org.jpos.iso.packager.ISO87APackager;
import org.jpos.util.Logger;
import org.jpos.util.SimpleLogListener;
import org.jpos.util.ThreadPool;

public class Test {

    public static void main(String[] args) throws ISOException, IOException 
{

        int len = 31;
        System.out.println(ISOUtil.zeropad(Integer.toString(len), 4));
        System.out.println(ISOUtil.zeropad(String.valueOf(len), 4));

        Logger l = new Logger();
        l.addListener(new SimpleLogListener());
        ASCIIChannel sc = new ASCIIChannel(new ISO87APackager());
        sc.setHeader("56789".getBytes());
        sc.setLogger(l, "serverchannel");
        ISOServer server = new ISOServer(7776, sc, new ThreadPool(10, 100));
        server.setLogger(l, "server");
        server.addISORequestListener(new ISORequestListener() {

            
@Override
            public boolean process(ISOSource source, ISOMsg m) 
{

                System.out.println(ISOUtil.hexdump(m.getHeader()));
                m.dump(System.out, ">>");

                
return true;
            }
        });
        Thread t = new
 Thread(server);
        t.start();
        AsciiChannelEx cs = new AsciiChannelEx("127.0.0.1", 7776, new ISO87APackager());
        cs.setLogger(l, "clientchannel");
        ISOMsg m = new ISOMsg();
        m.setMTI("0200");
        m.set(2, "123456789");
        m.setHeader("01234".getBytes());
        cs.connect();
        cs.send(m);
    }
}


AsciiChannelEx look like

import java.io.IOException;

import org.jpos.iso.ISOException;
import org.jpos.iso.ISOUtil;
import org.jpos.iso.channel.ASCIIChannel;
import org.jpos.iso.packager.ISO87APackager;

public class AsciiChannelEx extends ASCIIChannel {

    public AsciiChannelEx(String string, int i, ISO87APackager iso87aPackager) {
        super(string, i, iso87aPackager);
    }

    public AsciiChannelEx(ISO87APackager iso87aPackager) throws IOException {
        super(iso87aPackager);
    }

    @Override
    protected void sendMessageLength(int len) throws IOException {

        try {
            serverOut.write(ISOUtil.zeropad(String.valueOf(len), 4).getBytes());
        }
        catch (ISOException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected int getMessageLength() throws IOException, ISOException {
        byte[] b = new byte[4];
        serverIn.readFully(b, 0, 4);
        int l = Integer.parseInt(new String(b));
        return l;
    }

}
Not sure why you are overriding the channel. A lot of times 0 byte packets are exchanged and the code that you removed, removes handling the echoing of those 0 byte keep alive packets. You will run into trouble when those are not handled (you have been warned of the consequences).

Works on my machine :)

-chhil


--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.

pks!!@

unread,
Dec 22, 2016, 3:59:41 AM12/22/16
to jPOS Users

 Hello Sir,

 Thanks to you for your guideline in right way.  Now i am little clear to Jpos ISO Message.

 please clear me on one last point.
 When i send iso message to netcat server then, server output shows message with length & header as prefix ( shown as below ) how? what concept works at netcat server?

003801ISO120200400000000000000009123456789

request message is:-

 m.setMTI("0200");
 m.set(2, "123456789");
 m.setHeader("01ISO12".getBytes());    


 Thanks & regard
 pK.

chhil

unread,
Dec 22, 2016, 5:05:18 AM12/22/16
to jpos-...@googlegroups.com
Netcat server in tcp mode is simply using basic socket communication (tcp/udp), it spits out the raw data it receives. Its like you write a simple tcp server in a language of your choice and dump all the bytes received, that were sent by a client. The data is exactly the same received by your jpos server channel. JPOS channel 
simply handle the framing of the length prefix, header and message data and pretty print it out for you.
Its basic tcp communication using packets in the background.

-chhil

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.

pks!!@

unread,
Dec 22, 2016, 5:57:59 AM12/22/16
to jPOS Users
Hello Sir,

 Great, Exactly the point where i was facing problem.
 Now, According to Jpos when i have to send ISO Message from client using QMUX. This receives ISO Message as parameter to send as below,
 
 ISOMsg resp = mux.request(requestISOMessage, timeout");

 But, the point is , How can i send hexdump of any ISOMessage on TCP/UDP socket based communication using above QMUX method.

 my using xml is as below.

 <?xml version="1.0" ?>
<channel-adaptor name='adaptor' class="org.jpos.q2.iso.ChannelAdaptor" logger="Q2">
<channel class="org.jpos.iso.channel.ASCIIChannel" logger="Q2" packager="org.jpos.iso.packager.ISO87APackager" header="XXXXXXXXXXXXXXX">
                       <property name="host" value="localhost" />
         <property name="port" value="36605" />
</channel>
<in>send</in> 
<out>receive</out> 
<reconnect-delay>10000</reconnect-delay>
</channel-adaptor>

or is there any way to send to TCP/UDP communication using JPOS framework & Q2 server.

Please guide me to achieve on this point.


Thanks & regards
 pK.

chhil

unread,
Dec 22, 2016, 6:20:04 AM12/22/16
to jpos-...@googlegroups.com
Please understand the framework and its component before using it. Help yourself with this freely available programmer guide.


-chhil

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+unsubscribe@googlegroups.com.
To post to this group, send email to jpos-...@googlegroups.com.

pks!!@

unread,
Dec 22, 2016, 6:24:37 AM12/22/16
to jPOS Users

Hello Sir,

 Thanks for your valuable time. I have point out problem with the help of your suggestions. 
 Now i have to do more R&D on Jpos and related.

 Thanks & regards
 pK.
Reply all
Reply to author
Forward
0 new messages