In my case, field 61(Type LLLVAR) used for storing the name of card owner, which is encoded in GBK, not utf-8.
while parsing response, class LlvarParseInfo decode the field value like this
line 66: _v = new String(buf, pos + 2, buf.length-pos-2, getCharacterEncoding()).substring(0, length);
line 100: T dec = custom.decodeField(new String(buf, pos + 1, length, getCharacterEncoding()));
The first issue : how to configure the CharacterEncoding for some certain field?
I use the reflect class to change CharacterEncoding of the field 61:
MessageFactory messageFactory =ConfigManager.getInstance().getMessageFactory();
Field [] fields = MessageFactory.class.getDeclaredFields();
Field f = Iterables.find(Arrays.asList(fields), new Predicate<Field>(){
@Override
public boolean apply(Field input) {
return input.getName().equals("parseMap");
}
});
try {
f.setAccessible(true);
Map<Integer, Map<Integer,="" FieldParseInfo="">> parseMap = (Map<Integer, Map<Integer,="" FieldParseInfo="">>) f.get(messageFactory);
parseMap.get(0x0210).get(Integer.valueOf(61)).setCharacterEncoding("GBK");
} catch (Exception e1) {
e1.printStackTrace();
}
but while running at Line64
//This is new: if the String's length is different from the specified length in the buffer,
//there are probably some extended characters. So we create a String from the rest of the buffer,
//and then cut it to the specified length.
if (_v.length() != length) {
_v = new String(buf, pos + 3, buf.length-pos-3, getCharacterEncoding()).substring(0, length);
}
the specified length is 67, _v.length is 66. After reading one more byte, the whole parsing going into the wrong way.
The second issue : It seems IsoValue would hava a property(byte []?) to store the binary data, and let the app layer to handle String decode stuff
In my case, field 61(Type LLLVAR) used for storing the name of card owner, which is encoded in GBK, not utf-8.
while parsing response, class LlvarParseInfo decode the field value like this
line 66: _v = new String(buf, pos + 2, buf.length-pos-2, getCharacterEncoding()).substring(0, length);
line 100: T dec = custom.decodeField(new String(buf, pos + 1, length, getCharacterEncoding()));
The first issue : how to configure the CharacterEncoding for some certain field?
I use the reflect class to change CharacterEncoding of the field 61:
MessageFactory messageFactory =ConfigManager.getInstance().getMessageFactory();
Field [] fields = MessageFactory.class.getDeclaredFields();
Field f = Iterables.find(Arrays.asList(fields), new Predicate<Field>(){
@Override
public boolean apply(Field input) {
return input.getName().equals("parseMap");
}
});
try {
f.setAccessible(true);
Map<Integer, Map<Integer,="" FieldParseInfo="">> parseMap = (Map<Integer, Map<Integer,="" FieldParseInfo="">>) f.get(messageFactory);
parseMap.get(0x0210).get(Integer.valueOf(61)).setCharacterEncoding("GBK");
} catch (Exception e1) {
e1.printStackTrace();
}
but while running at Line64
//This is new: if the String's length is different from the specified length in the buffer,
//there are probably some extended characters. So we create a String from the rest of the buffer,
//and then cut it to the specified length.
if (_v.length() != length) {
_v = new String(buf, pos + 3, buf.length-pos-3, getCharacterEncoding()).substring(0, length);
}
the specified length is 67, _v.length is 66. After reading one more byte, the whole parsing going into the wrong way.
The second issue : It seems IsoValue would hava a property(byte []?) to store the binary data, and let the app layer to handle String decode stuff
sdk : jdk 6.0 + j8583 1.8.0
Field 61 value(HEX):
30363720202020202020202020202020202020202020202020202020202020202020204355504E4D2AC8FD202020202020202020202020202020202020202020202020202020
You can set the encoding for a field using setCharacterEncoding() you just need to find the name for GBK encoding.
To handle binary values (byte arrays) you can use LLBIN, LLLBIN and BINARY, which are the byte[] equivalents of LLVAR, LLLVAR and ALPHA.