Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 053594ff authored by Pawel GUTOWSKI's avatar Pawel GUTOWSKI
Browse files

EDELIVERY-2771 fixed UTF-8 characters encoding for incomming requests and produced responses body

parent 5df67425
No related branches found
No related tags found
No related merge requests found
Showing
with 60 additions and 6 deletions
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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
......
<?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
......@@ -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);
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment