Search code examples
javaiso8583

j8583 library - how to convert value into hex


I am using j8583 library to build iso8583 message. I want to set DE96 element value as hexadecimals of binary data. As per my understanding, the value should be converted to binary and then to hexadecimal. Much like the BitMap value. I am not finding any way on achieving this using j8583 API. I have tried ISOType.BINARY type but that does not give the required value.

Please see the following code

package j8583.example;

import java.io.IOException;
import java.util.Date;


import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.IsoType;
import com.solab.iso8583.MessageFactory;
import com.solab.iso8583.parse.ConfigParser;
import com.solab.iso8583.util.HexCodec;

public class MsgSender0800 {


public static void main(String[] args) {

    try {
        MessageFactory mfact = ConfigParser.createFromClasspathConfig("j8583/example/config.xml");
        IsoMessage msg = mfact.newMessage(0x800);
        msg.setValue(7, new Date(), IsoType.DATE10, 10);
        msg.setValue(96, "123456", IsoType.BINARY, 6);

        /* I want DE 96 value similar to the output of this code
        String test = "123456";
        String encoded = HexCodec.hexEncode(test.getBytes(), 0, test.length());
        System.out.println(encoded);            
        System.out.println(new String(HexCodec.hexDecode(encoded)));
        */

        String strMsg = new String(msg.writeData());
        System.out.println(strMsg);

    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

The above code prints the following iso message

08008200000000000800040000010000000002190926080000000000000000000123456000000

Please see the last 12 bytes, produced by msg.setValue(96, "123456", IsoType.BINARY, 6);, instead of above message I want to build the following message

08008200000000000800040000010000000002190926080000000000000000000313233343536

The last 6 bytes are hex encoded value.

The ISO.BINAY also appending additional '0' i.e. with msg.setValue(96, "123456", IsoType.BINARY, 6);, it produces 123456000000 instead of 123456

I am wondering if anyone has done it using this API. Otherwise I have to add some sort of wrapper on it to add this functionality.

Following is the xml configuration

<template type="0800">
<field num="53" type="NUMERIC" length="16">00</field>
<field num="70" type="NUMERIC" length="3">000</field>
</template>

I am quite new to library. Can anyone please help me understand.

Thanks


Solution

  • For IsoType.BINARY the provided value should be a byte[] and then that byte array is converted to hex during the write operation.