1

Config:

<template type="0500">
        <field num="3" type="NUMERIC" length="6">920000</field>
        <field num="11" type="NUMERIC" length="6" />
        <field num="24" type="NUMERIC" length="3" />
        <field num="41" type="ALPHA" length="8" />
        <field num="42" type="ALPHA" length="15" />
</template>

Code:

MessageFactory mfact = ConfigParser
                    .createFromClasspathConfig("config.xml");
            mfact.setTraceNumberGenerator(new SimpleTraceGenerator((int) (System.currentTimeMillis() % 100000)));

            m = mfact.newMessage(0x500);
            m.setValue(24, 109, IsoType.NUMERIC, 3);
            m.setValue(41, "10986312", IsoType.ALPHA, 8);
            m.setValue(42, "000001106020132", IsoType.ALPHA, 15);

            String strMsg = new String(msg.writeData());

strMsg is giving me this result:

05 00 20 20 01 00 00 C0 00 00 92 00 00 04 42 18 10 91 09 86 31 20 00 00 11 06 02 01 32

but the result should be:

05 00 20 20 01 00 00 C0 00 00  92 00 00 04 42 18 01 09 31 30 39 38 36 33 31 32 30 30 30 30 30 31 31 30 36 30 32 30 31 33 32

where:

field 24 => 109 should be 0109
field 41 => 10986312 should be in hex 3130393836333132
feild 42 => 000001106020132 should be in hex 303030303031313036303230313332

Both field 41 and 42 are Alpha Numeric Special Character field.

Should I use HexCodec.hexEncode whole message of part of the message before sending to the host using TCP/IP?

Alvin
  • 8,219
  • 25
  • 96
  • 177
  • Check your `config.xml` file, it may have customised packing for those fields. Try doing `ConfigParser.createDefault()` instead and see if you get the expected result – M.M Aug 03 '18 at 03:22
  • I have tried createdDefault, the result is the same. Is J8583 going to help to generate HEX array string message? – Alvin Aug 03 '18 at 09:06
  • Are you calling `MessageFactory.setUseBinaryMessages(true)`? If the message is indeed binary, you should inspect with HexCodec.hexEncode, since creating a String from binary data might do weird things when you try to look at the data. – Chochos Aug 03 '18 at 20:26
  • I didn't use MessageFactory.setUseBinaryMessages(true). I thought HexCodec.hexEncode is use to encode the message into hex. I look at all j8583 example, the result generated is correct, but the message example given by the bank vendor is in hex. So I can't understand should I generated hex message before sending the it to the bank, or the tcp/ip transportation will convert the message into hex value? – Alvin Aug 04 '18 at 01:10
  • HexCodec.hexEncode is a utility method to encode stuff manually. It's used internally by the library and it's public so you can use it in your field codecs if you need it. You can use it to print the byte array returned by `msg.writeData()`. I don't know how you managed to get that hex you put here from a String. – Chochos Aug 31 '18 at 21:57

0 Answers0