how to prepend ISO8583 message length to an ISO8583 message using j8583 library

5.6k views Asked by At

I am trying to send an ISO8583 message to a server using j8583. I am setting the header in the config.xml file and setting the fields from the same. Now the server configuration requires that 2byte length(Length in hex sent as bytes) should be sent before the incoming ISO8583 message. So my question is :

1)How to calculate the length of the message i.e the byte representation of the ISO message and how to calculate the length of the byte representation.

2)How to send the length of the message to the server before the ISO8583 message i.e prepended in front of the header.

Here are some of the code excerpts

Client client = new Client(sock);
    Thread reader = new Thread(client, "j8583-client");
    reader.start();

        IsoMessage req = mfact.newMessage(0x200);
        req.setValue(4, amounts[rng.nextInt(amounts.length)],
                IsoType.AMOUNT, 0);
        req.setValue(12, req.getObjectValue(7), IsoType.TIME, 0);
        req.setValue(13, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(15, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(17, req.getObjectValue(7), IsoType.DATE4, 0);
        req.setValue(37, System.currentTimeMillis() % 1000000,
                IsoType.NUMERIC, 12);
        req.setValue(41, data[rng.nextInt(data.length)], IsoType.ALPHA, 16);
        req.setValue(48, data[rng.nextInt(data.length)], IsoType.LLLVAR, 0);
        pending.put(req.getField(11).toString(), req);
        System.err.println(String.format("Sending request %s", req.getField(11)));
                    System.out.println(req.getIsoHeader());
                    System.out.println(req.debugString());

        req.write(sock.getOutputStream(), 2);

and below is the config

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE j8583-config PUBLIC "-//J8583//DTD CONFIG 1.0//EN"
    "http://j8583.sourceforge.net/j8583.dtd">
<j8583-config>

<!-- These are the ISO headers to be prepended to the message types specified -->
<header type="0200">ISO026000073</header>
<header type="0210">ISO015000055</header>
<header type="0400">ISO015000050</header>
<header type="0410">ISO015000055</header>
<header type="0800">ISO015000015</header>
<header type="0810">ISO015000015</header>

<!-- The client example uses this to create requests -->
<template type="0200">
    <field num="3" type="NUMERIC" length="6">650000</field>
    <field num="32" type="LLVAR">456</field>
    <field num="35" type="LLVAR">4591700012340000=</field>
    <field num="43" type="ALPHA" length="40">SOLABTEST             TEST-3       DF MX</field>
    <field num="49" type="ALPHA" length="3">484</field>
    <field num="60" type="LLLVAR">B456PRO1+000</field>
    <field num="61" type="LLLVAR">        1234P</field>
    <field num="100" type="LLVAR">999</field>
    <field num="102" type="LLVAR">ABCD</field>
</template>

the below is the string representation of the ISO message (the output) :

    Connecting to server
ISO026000073
Sending request 008386
ISO0260000730200B23A800128A180180000000014000000650000000000002050021112445800838612445802110211021103456174591700012340000=0000008984011234567890      SOLABTEST             TEST-3       DF MX010abcdefghij484012B456PRO1+000013        1234P0399904ABCD

Also how can I see what raw message is being sent from my terminal to the server?

2

There are 2 answers

4
Chochos On BEST ANSWER

Well you already use IsoMessage.write(outputStream, 2) to write a message to a stream, with its length prepended as a 2-byte header. In other words, that method does exactly what you're asking for, but you're already using it, so I'm not sure what the problem is; is the message not property received on the other side? Perhaps you should wrap the socket's outputStream in a BufferedOutputStream; IsoMessage.write will flush the stream after writing the message.

IsoMessage.writeData() gives you the byte array without any length headers.

0
Shay Ribera On
/* Handel a hexidecimal header in j8583 */
String header = "6000888000"; 
long it = Long.parseLong(header.trim(), 16); 
BigInteger bigInt = BigInteger.valueOf(it);
Log.i(TAG, "value of heder " + bigInt.toString());
byte[] bytearray = (bigInt.toByteArray());