diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverter.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverter.java index bffbff784b7f0af6bc7c707364d2cf3d416766fe..8ff7cf7fd9387b54bbeff69443233bc122faddf5 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceGroupConverter.java @@ -29,6 +29,7 @@ import javax.xml.parsers.ParserConfigurationException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import static java.nio.charset.StandardCharsets.UTF_8; /** * Created by migueti on 26/01/2017. @@ -61,7 +62,7 @@ public class ServiceGroupConverter { } private static Document parse(String serviceGroupXml) throws ParserConfigurationException, IOException, SAXException { - InputStream inputStream = new ByteArrayInputStream(serviceGroupXml.getBytes()); + InputStream inputStream = new ByteArrayInputStream(serviceGroupXml.getBytes(UTF_8)); return getDocumentBuilder().parse(inputStream); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverter.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverter.java index 23da3487c8920ffa1ac10fd58da6f9fe98c03577..4b2baf777d7a39d3bff5a1ac1b4bea67c446a2e8 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverter.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverter.java @@ -21,7 +21,6 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.SAXException; -import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; @@ -32,6 +31,8 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import static java.nio.charset.StandardCharsets.UTF_8; + /** * Created by gutowpa on 05/01/2017. */ @@ -77,7 +78,7 @@ public class ServiceMetadataConverter { } private static Document parse(String serviceMetadataXml) throws SAXException, IOException, ParserConfigurationException { - InputStream inputStream = new ByteArrayInputStream(serviceMetadataXml.getBytes()); + InputStream inputStream = new ByteArrayInputStream(serviceMetadataXml.getBytes(UTF_8)); return getDocumentBuilder().parse(inputStream); } diff --git a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/ExtensionUtils.java b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/ExtensionUtils.java index e4751b2607659713335d99f49352568c3e1715ed..3b6decbcbd237e3001930a5713721472a6b5e49b 100644 --- a/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/ExtensionUtils.java +++ b/smp-server-library/src/main/java/eu/europa/ec/cipa/smp/server/util/ExtensionUtils.java @@ -35,6 +35,7 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.Collections; import java.util.List; +import static java.nio.charset.StandardCharsets.UTF_8; /** * Created by migueti on 13/02/2017. @@ -91,7 +92,7 @@ public class ExtensionUtils { public static List<ExtensionType> unmarshalExtensions(String xml) throws JAXBException { String wrappedExtensionsStr = String.format(WRAPPED_FORMAT, xml); - InputStream inStream = new ByteArrayInputStream(wrappedExtensionsStr.getBytes()); + InputStream inStream = new ByteArrayInputStream(wrappedExtensionsStr.getBytes(UTF_8)); JAXBContext jaxbContext = JAXBContext.newInstance(ExtensionsWrapper.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); JAXBElement<ExtensionsWrapper> wrappedExtensions = jaxbUnmarshaller.unmarshal(new StreamSource(inStream), ExtensionsWrapper.class); diff --git a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverterTest.java b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverterTest.java index 26110036292284a91b52b4366072341e19116505..d3d4bf09830ad2939012385168dd9a1b0e0473d5 100644 --- a/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverterTest.java +++ b/smp-server-library/src/test/java/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataConverterTest.java @@ -64,6 +64,20 @@ public class ServiceMetadataConverterTest { assertEquals("This is the second epSOS Patient Service List for the Polish NCP", serviceDescription2); } + @Test + public void testUnmarshalServiceInformationUtf8() throws IOException, SAXException, ParserConfigurationException, JAXBException { + //given + String inputDoc = XmlTestUtils.loadDocumentAsString(RES_PATH + "ServiceMetadataWithServiceInformationUtf8.xml"); + + //when + ServiceMetadata serviceMetadata = ServiceMetadataConverter.unmarshal(inputDoc); + + //then + String serviceDescription = serviceMetadata.getServiceInformation().getProcessList().getProcesses().get(0).getServiceEndpointList().getEndpoints().get(0).getServiceDescription(); + assertEquals("--ö--ẞßÄäPLżółćNOÆæØøÅå", serviceDescription); + + } + @Test public void testUnmarshalRedirect() throws IOException, SAXException, ParserConfigurationException, JAXBException { //given diff --git a/smp-server-library/src/test/resources/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataWithServiceInformationUtf8.xml b/smp-server-library/src/test/resources/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataWithServiceInformationUtf8.xml new file mode 100644 index 0000000000000000000000000000000000000000..df6b5b9aad35c0e50df7fd564ea35961bd23ca43 --- /dev/null +++ b/smp-server-library/src/test/resources/eu/europa/ec/cipa/smp/server/conversion/ServiceMetadataWithServiceInformationUtf8.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?><!-- + ~ Copyright 2017 European Commission | CEF eDelivery + ~ + ~ Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"); + ~ You may not use this work except in compliance with the Licence. + ~ + ~ You may obtain a copy of the Licence at: + ~ https://joinup.ec.europa.eu/software/page/eupl + ~ or file: LICENCE-EUPL-v1.1.pdf + ~ + ~ Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the Licence for the specific language governing permissions and limitations under the Licence. + --> + +<ServiceMetadata xmlns="http://docs.oasis-open.org/bdxr/ns/SMP/2016/05"> + <ServiceInformation> + <ParticipantIdentifier scheme="ehealth-actorid-qns">urn:poland:ncpb</ParticipantIdentifier> + <DocumentIdentifier scheme="ehealth-resid-qns">urn::epsos##services:extended:epsos::107</DocumentIdentifier> + <ProcessList> + <Process> + <ProcessIdentifier scheme="ehealth-procid-qns">urn:epsosPatientService::List</ProcessIdentifier> + <ServiceEndpointList> + <Endpoint transportProfile="urn:ihe:iti:2013:xcpd"> + <EndpointURI>http://poland.pl/ncp/patient/list</EndpointURI> + <Certificate>QUE=</Certificate> + <ServiceDescription>--ö--ẞßÄäPLżółćNOÆæØøÅå</ServiceDescription> + <TechnicalContactUrl>http://poland.pl/contact</TechnicalContactUrl> + <TechnicalInformationUrl>http://poland.pl/contact</TechnicalInformationUrl> + </Endpoint> + </ServiceEndpointList> + </Process> + </ProcessList> + </ServiceInformation> +</ServiceMetadata> \ No newline at end of file diff --git a/smp-webapp/src/main/java/eu/europa/ec/cipa/smp/server/services/readwrite/ServiceGroupInterface.java b/smp-webapp/src/main/java/eu/europa/ec/cipa/smp/server/services/readwrite/ServiceGroupInterface.java index b36c31585b6a8eecc49e91a40eb50c5c8d30423a..7e8c4088c085b3f2b37064c470357c14b555a52a 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/cipa/smp/server/services/readwrite/ServiceGroupInterface.java +++ b/smp-webapp/src/main/java/eu/europa/ec/cipa/smp/server/services/readwrite/ServiceGroupInterface.java @@ -67,7 +67,7 @@ public final class ServiceGroupInterface { public ServiceGroupInterface () {} @GET - @Produces (MediaType.TEXT_XML) + @Produces ("text/xml; charset=UTF-8") public ServiceGroup getServiceGroup (@PathParam ("ServiceGroupId") final String sServiceGroupId) throws Throwable { // Delegate to common implementation return BaseServiceGroupInterfaceImpl.getServiceGroup (uriInfo, headers, sServiceGroupId, ServiceMetadataInterface.class); diff --git a/smp-webapp/src/main/java/eu/europa/ec/cipa/smp/server/services/readwrite/ServiceMetadataInterface.java b/smp-webapp/src/main/java/eu/europa/ec/cipa/smp/server/services/readwrite/ServiceMetadataInterface.java index 7a7c01412ccd710c41ae221f7f923a013729fd98..4254c73606af539a6e8daf9d7c63a4e962c8fd46 100644 --- a/smp-webapp/src/main/java/eu/europa/ec/cipa/smp/server/services/readwrite/ServiceMetadataInterface.java +++ b/smp-webapp/src/main/java/eu/europa/ec/cipa/smp/server/services/readwrite/ServiceMetadataInterface.java @@ -59,7 +59,7 @@ public final class ServiceMetadataInterface { @GET // changed Produced media type to match the smp specification. - @Produces (MediaType.TEXT_XML) + @Produces ("text/xml; charset=UTF-8") public Document getServiceRegistration (@PathParam ("ServiceGroupId") final String sServiceGroupID, @PathParam ("DocumentTypeId") final String sDocumentTypeID) throws Throwable { // Delegate to common implementation diff --git a/smp-webapp/src/main/resources/log4j.properties b/smp-webapp/src/main/resources/log4j.properties index aa3f18aeeed05cb9624c23d4275e99b23e372a60..45c0a9e741bc42667d238f164c32646bc866dac6 100644 --- a/smp-webapp/src/main/resources/log4j.properties +++ b/smp-webapp/src/main/resources/log4j.properties @@ -23,6 +23,8 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d [%p] %c %x - %m%n #log4j.logger.org.springframework=DEBUG +log4j.logger.org.hibernate.SQL=debug +log4j.logger.org.hibernate.type=trace # Second appender to write to a logfile log4j.appender.logfile=org.apache.log4j.RollingFileAppender