Added a new property, characterEncoding, to MessageFactory, IsoMessage, FieldParseInfo and IsoValue. This helps in parsing messages from byte buffers containing extended characters in encodings other than the default for the JVM. Tested with UTF8 on a Mac (which has default Mac OS Roman) and worked fine.
Several methods now have an additional encoding parameter (just a String, not directly a Charset), but the default is always the JVM's default encoding (taken from the property 'file.encoding'). git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@70 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package j8583;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
@@ -22,9 +23,11 @@ public class TestBinaries {
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
mfactAscii.setCharacterEncoding("UTF-8");
|
||||
mfactAscii.setConfigPath("config.xml");
|
||||
mfactBin.setConfigPath("config.xml");
|
||||
mfactAscii.setAssignDate(true);
|
||||
mfactBin.setCharacterEncoding("UTF-8");
|
||||
mfactBin.setConfigPath("config.xml");
|
||||
mfactBin.setAssignDate(true);
|
||||
mfactBin.setUseBinaryMessages(true);
|
||||
}
|
||||
@@ -61,19 +64,19 @@ public class TestBinaries {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessages() throws ParseException {
|
||||
public void testMessages() throws ParseException, UnsupportedEncodingException {
|
||||
//Create a message with both factories
|
||||
IsoMessage ascii = mfactAscii.newMessage(0x600);
|
||||
IsoMessage bin = mfactBin.newMessage(0x600);
|
||||
//HEXencode the binary message, headers should be similar to the ASCII version
|
||||
String hexBin = HexCodec.hexEncode(bin.writeData());
|
||||
String hexAscii = new String(ascii.writeData()).toUpperCase();
|
||||
System.out.printf("bin: %s%nascii: %s%n", hexBin, hexAscii);
|
||||
Assert.assertEquals("0600", hexBin.substring(0, 4));
|
||||
//Should be the same up to the field 42 (first 80 chars)
|
||||
Assert.assertEquals(hexAscii.substring(0, 88), hexBin.substring(0, 88));
|
||||
//Parse both messages
|
||||
IsoMessage ascii2 = mfactAscii.parseMessage(ascii.writeData(), 0);
|
||||
byte[] asciiBuf = ascii.writeData();
|
||||
IsoMessage ascii2 = mfactAscii.parseMessage(asciiBuf, 0);
|
||||
testParsed(ascii2);
|
||||
Assert.assertEquals(ascii.getObjectValue(7).toString(), ascii2.getObjectValue(7).toString());
|
||||
IsoMessage bin2 = mfactBin.parseMessage(bin.writeData(), 0);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package j8583;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -23,6 +25,7 @@ public class TestIsoMessage {
|
||||
@Before
|
||||
public void init() throws IOException {
|
||||
mf = new MessageFactory();
|
||||
mf.setCharacterEncoding("UTF-8");
|
||||
mf.setCustomField(48, new CustomField48());
|
||||
mf.setConfigPath("config.xml");
|
||||
}
|
||||
@@ -60,7 +63,7 @@ public class TestIsoMessage {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncoding() throws ParseException {
|
||||
public void testEncoding() throws Exception {
|
||||
IsoMessage m1 = mf.newMessage(0x200);
|
||||
byte[] buf = m1.writeData();
|
||||
IsoMessage m2 = mf.parseMessage(buf, mf.getIsoHeader(0x200).length());
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<field num="48" type="LLLVAR">Life, the Universe, and Everything|42</field>
|
||||
<field num="49" type="ALPHA" length="3">484</field>
|
||||
<field num="60" type="LLLVAR">B456PRO1+000</field>
|
||||
<field num="61" type="LLLVAR"> 1234P vamos a meter mas de 90 caracteres en este campo para comprobar si hay algun error en el parseo del mismo. Esta definido como un LLLVAR aqui por lo tanto esto debe caber sin problemas; las guias de parseo de 200 y 210 tienen LLLVAR en campo 61 tambien.</field>
|
||||
<field num="61" type="LLLVAR"> 1234P vamos a meter más de 90 caracteres en este campo para comprobar si hay algun error en el parseo del mismo. Esta definido como un LLLVAR aqui por lo tanto esto debe caber sin problemas; las guias de parseo de 200 y 210 tienen LLLVAR en campo 61 tambien.</field>
|
||||
<field num="100" type="LLVAR">999</field>
|
||||
<field num="102" type="LLVAR">ABCD</field>
|
||||
</template>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
ISO0250000550210B23A80012EA080180000000014000004650000000000003000042813054746877112594604280428081103123173766123456123456=00123442579114472300614209027600TESTSOLAB TEST-3 DF MX484012B123PRO1+000013 0000P0312304ABCD040ABCD8123477547
|
||||
ISO0250000550210B23A80012EA080180000000014000004650000000000003000042813054746877112594604280428081103123173766123456123456=00123442579114472300614209027600TéSTSOLAB áéíóú üñÑ TEST-3 DF MX484012B123P®O1+000013 0000P0312304ABCD040ABCD8123477547
|
||||
|
||||
|
||||
Reference in New Issue
Block a user