From eb4384925db492c3db6c302ef6f183fa904fd8f3 Mon Sep 17 00:00:00 2001 From: ptorres-prowide Date: Wed, 15 Feb 2023 15:56:57 -0300 Subject: [PATCH 1/2] CU-85zrnb6u1_PW---631--XML-Handling --- CHANGELOG.md | 3 + .../swift/model/mx/AbstractMX.java | 16 +- .../swift/model/mx/AppHdrParser.java | 2 +- .../swift/model/mx/MxParseUtils.java | 17 +- .../swift/model/mx/MxReadConfiguration.java | 8 + .../swift/model/mx/MxReadImpl.java | 2 +- .../swift/model/mx/MxReadParams.java | 9 + .../swift/model/mx/MxWriteConfiguration.java | 8 + .../swift/model/mx/MxWriteParams.java | 8 + .../swift/model/mx/MxWriteUtils.java | 4 +- .../issues/IssueJira631Test.java | 291 ++++++++++++++++++ 11 files changed, 359 insertions(+), 9 deletions(-) create mode 100644 iso20022-core/src/test/java/com/prowidesoftware/issues/IssueJira631Test.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8545a3f86..5a504b8a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Prowide ISO 20022 - CHANGELOG +#### 9.3.6-SNAPSHOT + * (PW-631) Changed the XML marshaling/unmarshalling to honor the default system encoding, and added optional parameters to use a specific charset if needed + #### 9.3.5 - January 2023 * Added an optional way to pass a JaxbContext instance to the parse and write methods diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AbstractMX.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AbstractMX.java index 70c9ad7a2..77aaf9c23 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AbstractMX.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AbstractMX.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.StringReader; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -54,6 +55,10 @@ import java.util.logging.Level; import java.util.logging.Logger; +import static java.nio.charset.StandardCharsets.*; +import static org.apache.commons.lang3.StringUtils.getBytes; +import static org.apache.commons.lang3.StringUtils.toEncodedString; + /** * Base class for specific MX messages.
@@ -303,8 +308,12 @@ public String message(MxWriteConfiguration conf) { String root = usableConf.rootElement; StringBuilder xml = new StringBuilder(); + + Charset charsetToUse =conf.charset != null? conf.charset:Charset.defaultCharset(); if (usableConf.includeXMLDeclaration) { - xml.append("\n"); + xml.append("\n"); } params.prefix = usableConf.headerPrefix; @@ -319,7 +328,8 @@ public String message(MxWriteConfiguration conf) { if (header != null) { xml.append(""); } - return xml.toString(); + + return toEncodedString(getBytes(xml.toString(), UTF_8), charsetToUse); } /** @@ -510,7 +520,7 @@ public void write(final File file) throws IOException { @ProwideDeprecated(phase2 = TargetYear.SRU2023) public void write(final OutputStream stream) throws IOException { Objects.requireNonNull(stream, "the stream to write cannot be null"); - stream.write(message().getBytes(StandardCharsets.UTF_8)); + stream.write(message().getBytes(UTF_8)); } /** diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AppHdrParser.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AppHdrParser.java index 6752704e4..1542c8c1d 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AppHdrParser.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AppHdrParser.java @@ -76,7 +76,7 @@ public static Optional parse(final String xml, MxReadParams params) { private static AppHdr parseHeaderFromSAXSource(final String xml, final String namespace, final MxReadParams params) { - SAXSource source = MxParseUtils.createFilteredSAXSource(xml, AppHdr.HEADER_LOCALNAME); + SAXSource source = MxParseUtils.createFilteredSAXSource(xml, AppHdr.HEADER_LOCALNAME, null); if (StringUtils.equals(LegacyAppHdr.NAMESPACE, namespace)) { // parse legacy AH diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxParseUtils.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxParseUtils.java index 1dcc67044..6338206ca 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxParseUtils.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxParseUtils.java @@ -32,6 +32,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.transform.sax.SAXSource; import java.io.StringReader; +import java.nio.charset.Charset; import java.util.Objects; import java.util.Optional; import java.util.concurrent.ExecutionException; @@ -52,14 +53,18 @@ public class MxParseUtils { * @return a safe source * @since 9.2.1 */ - static SAXSource createFilteredSAXSource(final String xml, final String localName) { + static SAXSource createFilteredSAXSource(final String xml, final String localName, Charset charset) { XMLReader documentReader = SafeXmlUtils.reader(true, null); NamespaceAndElementFilter documentFilter = new NamespaceAndElementFilter(localName); documentFilter.setParent(documentReader); InputSource documentInputSource = new InputSource(new StringReader(xml)); - + if (charset != null) { + documentInputSource.setEncoding(charset.name()); + } else { + documentInputSource.setEncoding(Charset.defaultCharset().name()); + } return new SAXSource(documentFilter, documentInputSource); } @@ -108,6 +113,12 @@ static Object parseSAXSource(final SAXSource source, final Class targetClass, fi } } + if(params.charset!=null){ + source.getInputSource().setEncoding(params.charset.name()); + } else { + source.getInputSource().setEncoding(Charset.defaultCharset().name()); + } + JAXBElement element = unmarshaller.unmarshal(source, targetClass); if (element != null) { return element.getValue(); @@ -166,7 +177,7 @@ static Object parse(final Class targetClass, final String xml, final Class[] Objects.requireNonNull(params, "unmarshalling params cannot be null"); try { - SAXSource saxSource = createFilteredSAXSource(xml, localName); + SAXSource saxSource = createFilteredSAXSource(xml, localName, params.charset); return parseSAXSource(saxSource, targetClass, classes, params); } catch (final Exception e) { diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadConfiguration.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadConfiguration.java index 2d79b9155..63c52e3ad 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadConfiguration.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadConfiguration.java @@ -18,6 +18,7 @@ import com.prowidesoftware.swift.model.mx.adapters.TypeAdaptersConfiguration; import javax.xml.bind.JAXBContext; +import java.nio.charset.Charset; /** * Options to customize the behaviour of the MX parser (XML into model) in the {@link AbstractMX} and its specific @@ -39,6 +40,12 @@ public class MxReadConfiguration { */ public JAXBContext context; + /** + * Optional parameter to use a specific charset when unmarshalling XML content, if not set, the system default is used + * @since 9.3.6 + */ + public Charset charset; + /** * Creates a configuration with the default adapters */ @@ -52,6 +59,7 @@ public MxReadConfiguration() { public MxReadConfiguration(MxWriteConfiguration writeConf) { this.adapters = writeConf.adapters; this.context = writeConf.context; + this.charset = writeConf.charset; } } diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadImpl.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadImpl.java index 740c8c69d..d5d0e65ac 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadImpl.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadImpl.java @@ -75,7 +75,7 @@ public static AbstractMX parse(final Class targetClass, fi try { - SAXSource documentSource = MxParseUtils.createFilteredSAXSource(xml, AbstractMX.DOCUMENT_LOCALNAME); + SAXSource documentSource = MxParseUtils.createFilteredSAXSource(xml, AbstractMX.DOCUMENT_LOCALNAME, params.charset); final AbstractMX parsedDocument = (AbstractMX) MxParseUtils.parseSAXSource(documentSource, targetClass, classes, params); Optional mx = Optional.ofNullable(parsedDocument); diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadParams.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadParams.java index 533ef8073..59e7bacec 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadParams.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxReadParams.java @@ -19,6 +19,8 @@ import javax.xml.bind.JAXBContext; +import java.nio.charset.Charset; + /** * Simple DTO to encapsulate parameters in the different XML-to-model parser implementation methods in the API * @@ -45,6 +47,12 @@ public class MxReadParams { */ public JAXBContext context; + /** + * Optional parameter to use a specific charset when unmarshalling XML content, if not set, the system default is used + * @since 9.3.6 + */ + public Charset charset; + public MxReadParams() { this.adapters = new TypeAdaptersConfiguration(); } @@ -54,6 +62,7 @@ public MxReadParams(MxReadConfiguration conf) { if (conf != null) { this.adapters = conf.adapters; this.context = conf.context; + this.charset = conf.charset; } } diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteConfiguration.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteConfiguration.java index 96677151d..9fe88b14d 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteConfiguration.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteConfiguration.java @@ -18,6 +18,7 @@ import com.prowidesoftware.swift.model.mx.adapters.TypeAdaptersConfiguration; import javax.xml.bind.JAXBContext; +import java.nio.charset.Charset; /** * Options to customize the behaviour of the MX writer (model into XML serialization) in the {@link AbstractMX} @@ -73,6 +74,12 @@ public class MxWriteConfiguration { */ public JAXBContext context; + /** + * Optional parameter to use a specific charset when unmarshalling XML content, if not set, the system default is used + * @since 9.3.6 + */ + public Charset charset; + /** * Creates a configuration with the default options and adapters */ @@ -99,6 +106,7 @@ public MxWriteConfiguration(MxReadConfiguration readConf) { this(); this.adapters = readConf.adapters; this.context = readConf.context; + this.charset = readConf.charset; } } \ No newline at end of file diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteParams.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteParams.java index c802d7880..d1bb915a8 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteParams.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteParams.java @@ -18,6 +18,7 @@ import com.prowidesoftware.swift.model.mx.adapters.TypeAdaptersConfiguration; import javax.xml.bind.JAXBContext; +import java.nio.charset.Charset; /** * Simple DTO to encapsulate parameters in the different model-to-XML serialization implementation methods in the API @@ -52,6 +53,12 @@ public class MxWriteParams { */ public TypeAdaptersConfiguration adapters; + /** + * Optional parameter to use a specific charset when marshalling into XML, if not set, the system default is used + * @since 9.3.6 + */ + public Charset charset; + public MxWriteParams() { this(new MxWriteConfiguration()); } @@ -64,6 +71,7 @@ public MxWriteParams() { this.escapeHandler = notNullConf.escapeHandler; this.adapters = notNullConf.adapters; this.context = notNullConf.context; + this.charset = notNullConf.charset; } } diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteUtils.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteUtils.java index c447a203c..64b6727c7 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteUtils.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/MxWriteUtils.java @@ -35,7 +35,9 @@ static Marshaller createMarshaller(final JAXBContext context, final MxWriteParam marshaller.setAdapter(adapter); } } - + if (params.charset != null) { + marshaller.setProperty(Marshaller.JAXB_ENCODING, params.charset.name()); + } return marshaller; } diff --git a/iso20022-core/src/test/java/com/prowidesoftware/issues/IssueJira631Test.java b/iso20022-core/src/test/java/com/prowidesoftware/issues/IssueJira631Test.java new file mode 100644 index 000000000..f11b11b58 --- /dev/null +++ b/iso20022-core/src/test/java/com/prowidesoftware/issues/IssueJira631Test.java @@ -0,0 +1,291 @@ +package com.prowidesoftware.issues; + +import com.prowidesoftware.swift.model.mx.BusinessAppHdrV02; +import com.prowidesoftware.swift.model.mx.MxPacs00800108; +import com.prowidesoftware.swift.model.mx.MxReadParams; +import com.prowidesoftware.swift.model.mx.MxWriteConfiguration; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Field; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +//@Execution(SAME_THREAD) +public class IssueJira631Test { + + @Test + void testBusinessAppHeaderV02() throws IllegalAccessException, NoSuchFieldException { + String currentCharset = Charset.defaultCharset().name(); + Field defaultCharset = Charset.class.getDeclaredField("defaultCharset"); + defaultCharset.setAccessible(true); + defaultCharset.set(null,null); + System.setProperty("file.encoding","Cp1141"); + + String xmlAsString = "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " AAAAUSXXXXX\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " BBBBUSXXXXX\n" + + " \n" + + " \n" + + " \n" + + " REF1\n" + + " pain.001.001.08\n" + + " 2023-02-15T15:48:00+00:00\n" + + ""; + + //System.out.println(xmlAsString); + + byte[] srcBytes; + srcBytes = xmlAsString.getBytes(StandardCharsets.UTF_8); + String destStr = new String(srcBytes, Charset.defaultCharset()); + + //System.out.println(destStr); + MxReadParams params = new MxReadParams(); + params.charset = Charset.defaultCharset(); + BusinessAppHdrV02 parse = BusinessAppHdrV02.parse(xmlAsString, params); + assertNotNull(parse); + System.setProperty("file.encoding", currentCharset); + } + + @Test + void testMxPacsWithWindowsEncoding() throws IllegalAccessException, NoSuchFieldException { + String currentCharset = Charset.defaultCharset().name(); + Field defaultCharset = Charset.class.getDeclaredField("defaultCharset"); + defaultCharset.setAccessible(true); + defaultCharset.set(null,null); + System.setProperty("file.encoding","windows-1252"); + + String xmlAsString = "\n" + + "\n" + + " \n" + + " \n" + + " asdfsd\n" + + " 2020-09-17T21:27:41\n" + + " 1\n" + + " \n" + + " INDA\n" + + " \n" + + " \n" + + " \n" + + " ACAABAJOESTAELCODIGO\n" + + " \n" + + " \n" + + " BBAN\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " sdfasdfsd\n" + + " asdfasdfasdfasdf\n" + + " 8579f4a4-a547-463e-ae63-e7c6620d59b4\n" + + " \n" + + " 11111\n" + + " 2023-04-10\n" + + " DEBT\n" + + " \n" + + " asdfasdf\n" + + " \n" + + " \n" + + " \n" + + " ITAUUSXXXXX\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " AAAAUSXXXXX\n" + + " \n" + + " \n" + + " \n" + + " sdfasdfsd\n" + + " \n" + + " \n" + + " \n" + + ""; + + //System.out.println(xmlAsString); + + MxPacs00800108 parse = MxPacs00800108.parse(xmlAsString); + assertNotNull(parse); + + MxWriteConfiguration mxWriteConfiguration = new MxWriteConfiguration(); + mxWriteConfiguration.charset = Charset.forName("Cp1141"); + String modelToStringMsg = parse.message(mxWriteConfiguration); + System.out.println(modelToStringMsg); + assertFalse(modelToStringMsg.contains("encoding=")); + + MxPacs00800108 stringToModelMx = MxPacs00800108.parse(modelToStringMsg); + assertNotNull(stringToModelMx); + + System.setProperty("file.encoding", currentCharset); + } + + + @Test //Single thread + void testMxPacsWithUTF8Encoding() throws IllegalAccessException, NoSuchFieldException { + String currentCharset = Charset.defaultCharset().name(); + Field defaultCharset = Charset.class.getDeclaredField("defaultCharset"); + defaultCharset.setAccessible(true); + defaultCharset.set(null,null); + System.setProperty("file.encoding","UTF-8"); + + String xmlAsString = "\n" + + "\n" + + " \n" + + " \n" + + " asdfsd\n" + + " 2020-09-17T21:27:41\n" + + " 1\n" + + " \n" + + " INDA\n" + + " \n" + + " \n" + + " \n" + + " ACAABAJOESTAELCODIGO\n" + + " \n" + + " \n" + + " BBAN\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " sdfasdfsd\n" + + " asdfasdfasdfasdf\n" + + " 8579f4a4-a547-463e-ae63-e7c6620d59b4\n" + + " \n" + + " 11111\n" + + " 2023-04-10\n" + + " DEBT\n" + + " \n" + + " asdfasdf\n" + + " \n" + + " \n" + + " \n" + + " ITAUUSXXXXX\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " AAAAUSXXXXX\n" + + " \n" + + " \n" + + " \n" + + " sdfasdfsd\n" + + " \n" + + " \n" + + " \n" + + ""; + + //System.out.println(xmlAsString); + + MxPacs00800108 parse = MxPacs00800108.parse(xmlAsString); + assertNotNull(parse); + + MxWriteConfiguration mxWriteConfiguration = new MxWriteConfiguration(); + mxWriteConfiguration.charset = Charset.forName("Cp1141"); + String modelToStringMsg = parse.message(mxWriteConfiguration); + System.out.println(modelToStringMsg); + assertFalse(modelToStringMsg.contains("encoding=")); + + MxPacs00800108 stringToModelMx = MxPacs00800108.parse(modelToStringMsg); + assertNotNull(stringToModelMx); + + System.setProperty("file.encoding", currentCharset); + } + + @Test //Single thread + void testMxPacsWithIBMEncoding() throws IllegalAccessException, NoSuchFieldException { + String currentCharset = Charset.defaultCharset().name(); + Field defaultCharset = Charset.class.getDeclaredField("defaultCharset"); + defaultCharset.setAccessible(true); + defaultCharset.set(null,null); + System.setProperty("file.encoding","Cp1141"); + + String xmlAsString = "\n" + + "\n" + + " \n" + + " \n" + + " asdfsd\n" + + " 2020-09-17T21:27:41\n" + + " 1\n" + + " \n" + + " INDA\n" + + " \n" + + " \n" + + " \n" + + " ACAABAJOESTAELCODIGO\n" + + " \n" + + " \n" + + " BBAN\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " sdfasdfsd\n" + + " asdfasdfasdfasdf\n" + + " 8579f4a4-a547-463e-ae63-e7c6620d59b4\n" + + " \n" + + " 11111\n" + + " 2023-04-10\n" + + " DEBT\n" + + " \n" + + " asdfasdf\n" + + " \n" + + " \n" + + " \n" + + " ITAUUSXXXXX\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " AAAAUSXXXXX\n" + + " \n" + + " \n" + + " \n" + + " sdfasdfsd\n" + + " \n" + + " \n" + + " \n" + + ""; + + //System.out.println(xmlAsString); + + MxPacs00800108 parse = MxPacs00800108.parse(xmlAsString); + assertNotNull(parse); + + String modelToStringMsg = parse.message(); + System.out.println("Model message with defaultCharset, Cp1141"); + System.out.println(modelToStringMsg); + assertFalse(modelToStringMsg.contains("encoding=")); + + MxPacs00800108 stringToModelMx = MxPacs00800108.parse(modelToStringMsg); + assertNotNull(stringToModelMx); + + System.setProperty("file.encoding", currentCharset); + System.out.println("Charset reset from Cp1141 to " + currentCharset); + } + +} From 6ac4b92dd5e582bf51506e1f68c15548d6fa31dc Mon Sep 17 00:00:00 2001 From: ptorres-prowide Date: Fri, 24 Feb 2023 09:55:05 -0300 Subject: [PATCH 2/2] CU-85zrnb6u1_PW---631--XML-Handling --- .../com/prowidesoftware/swift/model/mx/AbstractMX.java | 8 ++------ .../src/test/java/com/prowidesoftware/issues/Issue24.java | 4 ++++ .../java/com/prowidesoftware/issues/IssueJira631Test.java | 7 +++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AbstractMX.java b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AbstractMX.java index 77aaf9c23..463368e8f 100644 --- a/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AbstractMX.java +++ b/iso20022-core/src/main/java/com/prowidesoftware/swift/model/mx/AbstractMX.java @@ -309,13 +309,9 @@ public String message(MxWriteConfiguration conf) { String root = usableConf.rootElement; StringBuilder xml = new StringBuilder(); - Charset charsetToUse =conf.charset != null? conf.charset:Charset.defaultCharset(); if (usableConf.includeXMLDeclaration) { - xml.append("\n"); + xml.append("\n"); } - params.prefix = usableConf.headerPrefix; final String header = header(params); if (header != null) { @@ -329,7 +325,7 @@ public String message(MxWriteConfiguration conf) { xml.append(""); } - return toEncodedString(getBytes(xml.toString(), UTF_8), charsetToUse); + return xml.toString(); } /** diff --git a/iso20022-core/src/test/java/com/prowidesoftware/issues/Issue24.java b/iso20022-core/src/test/java/com/prowidesoftware/issues/Issue24.java index 2591cb541..d5fbfb79c 100644 --- a/iso20022-core/src/test/java/com/prowidesoftware/issues/Issue24.java +++ b/iso20022-core/src/test/java/com/prowidesoftware/issues/Issue24.java @@ -24,6 +24,9 @@ import com.prowidesoftware.swift.model.mx.dic.PaymentInstructionInformation3; import org.junit.jupiter.api.Test; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -62,6 +65,7 @@ public void testWriteDefaultMinimumEscapeHandler() { conf.escapeHandler = new MinimumEscapeHandler(); String xml = mx.message(conf); + System.out.println(Charset.defaultCharset().name()); assertTrue(xml.contains("текст текст öñ")); MxPain00100103 mx2 = MxPain00100103.parse(xml); diff --git a/iso20022-core/src/test/java/com/prowidesoftware/issues/IssueJira631Test.java b/iso20022-core/src/test/java/com/prowidesoftware/issues/IssueJira631Test.java index f11b11b58..217826c29 100644 --- a/iso20022-core/src/test/java/com/prowidesoftware/issues/IssueJira631Test.java +++ b/iso20022-core/src/test/java/com/prowidesoftware/issues/IssueJira631Test.java @@ -2,6 +2,7 @@ import com.prowidesoftware.swift.model.mx.BusinessAppHdrV02; import com.prowidesoftware.swift.model.mx.MxPacs00800108; +import com.prowidesoftware.swift.model.mx.MxReadConfiguration; import com.prowidesoftware.swift.model.mx.MxReadParams; import com.prowidesoftware.swift.model.mx.MxWriteConfiguration; import org.junit.jupiter.api.Test; @@ -24,7 +25,7 @@ void testBusinessAppHeaderV02() throws IllegalAccessException, NoSuchFieldExcept defaultCharset.set(null,null); System.setProperty("file.encoding","Cp1141"); - String xmlAsString = "\n" + + String xmlAsString = "\n" + "\n" + " \n" + " \n" + @@ -129,7 +130,9 @@ void testMxPacsWithWindowsEncoding() throws IllegalAccessException, NoSuchFieldE System.out.println(modelToStringMsg); assertFalse(modelToStringMsg.contains("encoding=")); - MxPacs00800108 stringToModelMx = MxPacs00800108.parse(modelToStringMsg); + MxReadConfiguration conf = new MxReadConfiguration(); + conf.charset = Charset.forName("Cp1141"); + MxPacs00800108 stringToModelMx = MxPacs00800108.parse(modelToStringMsg, conf); assertNotNull(stringToModelMx); System.setProperty("file.encoding", currentCharset);