From f5eda763884d5791fdc5dc03ed39ab3df956d7e4 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Thu, 6 Oct 2016 12:17:59 -0400 Subject: [PATCH] Use new STU3 mimetypes by default --- .gitignore | 1 + .../ca/uhn/fhir/rest/server/EncodingEnum.java | 32 ++++++++++------- .../fhir/rest/server/RestfulServerUtils.java | 32 ++++++++++------- .../dstu3/ResourceProviderDstu3Test.java | 36 +++++++++++++++++++ .../uhn/fhirtest/config/TdlDstu2Config.java | 2 ++ .../uhn/fhirtest/config/TdlDstu3Config.java | 2 ++ .../uhn/fhirtest/config/TestDstu1Config.java | 2 ++ .../uhn/fhirtest/config/TestDstu2Config.java | 2 ++ .../uhn/fhirtest/config/TestDstu3Config.java | 2 ++ .../uhn/fhir/rest/server/BinaryDstu2Test.java | 9 ++--- .../rest/server/ServerMimetypeDstu3Test.java | 32 ++++++++--------- src/changes/changes.xml | 5 +++ 12 files changed, 112 insertions(+), 45 deletions(-) diff --git a/.gitignore b/.gitignore index 6a2618c6a59..7c4ffb73ca9 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ tmp.txt tmp.txt ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString/ ca.uhn.fhir.jpa.entity.ResourceTable/ +ca.uhn.fhir.jpa.entity.TermConcept/ # Vagrant stuff. .vagrant diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/EncodingEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/EncodingEnum.java index 3d1dadce725..f83d7dfbe00 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/EncodingEnum.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/EncodingEnum.java @@ -46,6 +46,11 @@ public enum EncodingEnum { ; + /** "xml" */ + public static final String XML_PLAIN_STRING = "xml"; + /** "json" */ + public static final String JSON_PLAIN_STRING = "json"; + private static Map ourContentTypeToEncoding; private static Map ourContentTypeToEncodingNonLegacy; private static Map ourContentTypeToEncodingStrict; @@ -53,17 +58,24 @@ public enum EncodingEnum { static { ourContentTypeToEncoding = new HashMap(); ourContentTypeToEncodingNonLegacy = new HashMap(); + for (EncodingEnum next : values()) { ourContentTypeToEncoding.put(next.getBundleContentType(), next); ourContentTypeToEncoding.put(next.myResourceContentTypeNonLegacy, next); ourContentTypeToEncoding.put(next.myResourceContentTypeLegacy, next); - ourContentTypeToEncodingNonLegacy.put(next.myResourceContentTypeNonLegacy, next); + + /* + * See #346 + */ + ourContentTypeToEncoding.put(next.myResourceContentTypeNonLegacy.replace('+', ' '), next); + ourContentTypeToEncoding.put(next.myResourceContentTypeLegacy.replace('+', ' '), next); + ourContentTypeToEncodingNonLegacy.put(next.myResourceContentTypeNonLegacy.replace('+', ' '), next); + } - + // Add before we add the lenient ones ourContentTypeToEncodingStrict = Collections.unmodifiableMap(new HashMap(ourContentTypeToEncoding)); - ourContentTypeToEncodingNonLegacy = Collections.unmodifiableMap(ourContentTypeToEncodingNonLegacy); /* * These are wrong, but we add them just to be tolerant of other @@ -77,17 +89,11 @@ public enum EncodingEnum { /* * Plain values, used for parameter values */ - ourContentTypeToEncoding.put("json", JSON); - ourContentTypeToEncoding.put("xml", XML); + ourContentTypeToEncoding.put(JSON_PLAIN_STRING, JSON); + ourContentTypeToEncoding.put(XML_PLAIN_STRING, XML); + + ourContentTypeToEncodingNonLegacy = Collections.unmodifiableMap(ourContentTypeToEncodingNonLegacy); - /* - * See #346 - */ - for (EncodingEnum next : values()) { - ourContentTypeToEncoding.put(next.myResourceContentTypeNonLegacy.replace('+', ' '), next); - ourContentTypeToEncoding.put(next.myResourceContentTypeLegacy.replace('+', ' '), next); - } - } private String myBundleContentType; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java index de786b8b156..0f51a2e9e1a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java @@ -211,7 +211,7 @@ public class RestfulServerUtils { nextPart = nextPart.trim(); EncodingEnum encoding = EncodingEnum.forContentType(nextPart); if (encoding != null) { - retVal = new ResponseEncoding(encoding, nextPart); + retVal = new ResponseEncoding(theReq.getServer().getFhirContext(), encoding, nextPart); break; } } @@ -232,7 +232,7 @@ public class RestfulServerUtils { for (String nextFormat : format) { EncodingEnum retVal = EncodingEnum.forContentType(nextFormat); if (retVal != null) { - return new ResponseEncoding(retVal, nextFormat); + return new ResponseEncoding(theReq.getServer().getFhirContext(), retVal, nextFormat); } } } @@ -288,12 +288,12 @@ public class RestfulServerUtils { ResponseEncoding encoding; if (endSpaceIndex == -1) { if (startSpaceIndex == 0) { - encoding = getEncodingForContentType(strict, nextToken); + encoding = getEncodingForContentType(theReq.getServer().getFhirContext(), strict, nextToken); } else { - encoding = getEncodingForContentType(strict, nextToken.substring(startSpaceIndex)); + encoding = getEncodingForContentType(theReq.getServer().getFhirContext(), strict, nextToken.substring(startSpaceIndex)); } } else { - encoding = getEncodingForContentType(strict, nextToken.substring(startSpaceIndex, endSpaceIndex)); + encoding = getEncodingForContentType(theReq.getServer().getFhirContext(), strict, nextToken.substring(startSpaceIndex, endSpaceIndex)); String remaining = nextToken.substring(endSpaceIndex + 1); StringTokenizer qualifierTok = new StringTokenizer(remaining, ";"); while (qualifierTok.hasMoreTokens()) { @@ -347,7 +347,7 @@ public class RestfulServerUtils { public static ResponseEncoding determineResponseEncodingWithDefault(RequestDetails theReq) { ResponseEncoding retVal = determineResponseEncodingNoDefault(theReq, theReq.getServer().getDefaultResponseEncoding()); if (retVal == null) { - retVal = new ResponseEncoding(theReq.getServer().getDefaultResponseEncoding(), null); + retVal = new ResponseEncoding(theReq.getServer().getFhirContext(), theReq.getServer().getDefaultResponseEncoding(), null); } return retVal; } @@ -417,7 +417,7 @@ public class RestfulServerUtils { return retVal; } - private static ResponseEncoding getEncodingForContentType(boolean theStrict, String theContentType) { + private static ResponseEncoding getEncodingForContentType(FhirContext theFhirContext, boolean theStrict, String theContentType) { EncodingEnum encoding; if (theStrict) { encoding = EncodingEnum.forContentTypeStrict(theContentType); @@ -427,7 +427,7 @@ public class RestfulServerUtils { if (encoding == null) { return null; } else { - return new ResponseEncoding(encoding, theContentType); + return new ResponseEncoding(theFhirContext, encoding, theContentType); } } @@ -635,7 +635,7 @@ public class RestfulServerUtils { // Ok, we're not serving a binary resource, so apply default encoding if (responseEncoding == null) { - responseEncoding = new ResponseEncoding(theServer.getDefaultResponseEncoding(), null); + responseEncoding = new ResponseEncoding(theServer.getFhirContext(), theServer.getDefaultResponseEncoding(), null); } boolean encodingDomainResourceAsText = theSummaryMode.contains(SummaryEnum.TEXT); @@ -752,13 +752,21 @@ public class RestfulServerUtils { private final EncodingEnum myEncoding; private final Boolean myNonLegacy; - public ResponseEncoding(EncodingEnum theEncoding, String theContentType) { + public ResponseEncoding(FhirContext theCtx, EncodingEnum theEncoding, String theContentType) { super(); myEncoding = theEncoding; if (theContentType != null) { - myNonLegacy = EncodingEnum.isNonLegacy(theContentType); + if (theContentType.equals(EncodingEnum.JSON_PLAIN_STRING) || theContentType.equals(EncodingEnum.XML_PLAIN_STRING)) { + myNonLegacy = !theCtx.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3); + } else { + myNonLegacy = EncodingEnum.isNonLegacy(theContentType); + } } else { - myNonLegacy = null; + if (theCtx.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { + myNonLegacy = null; + } else { + myNonLegacy = Boolean.TRUE; + } } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index d2be34ac9d6..cf6a7f6d3bf 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -35,10 +35,13 @@ import java.util.List; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.*; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicNameValuePair; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.Bundle.BundleType; @@ -110,6 +113,39 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } } + + + /** + * See #411 + * + * Let's see if we can reproduce this issue in JPA + */ + @Test + public void testSearchWithMixedParams() throws Exception { + Patient patient = new Patient(); + patient.addIdentifier().setSystem("urn:system").setValue("0"); + patient.addName().addFamily("testSearchWithMixedParams").addGiven("Joe"); + myPatientDao.create(patient, mySrd).getId().toUnqualifiedVersionless(); + + HttpPost httpPost = new HttpPost(ourServerBase + "/Patient/_search?_format=application/xml"); + httpPost.addHeader("Cache-Control","no-cache"); + List parameters = Lists.newArrayList(); + parameters.add(new BasicNameValuePair("name", "Smith")); + httpPost.setEntity(new UrlEncodedFormEntity(parameters)); + + ourLog.info("Outgoing post: {}", httpPost); + + CloseableHttpResponse status = ourHttpClient.execute(httpPost); + try { + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); + ourLog.info(responseContent); + assertEquals(200, status.getStatusLine().getStatusCode()); + } finally { + IOUtils.closeQuietly(status.getEntity().getContent()); + } + + } + @Test public void testSearchPagingKeepsOldSearches() throws Exception { diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TdlDstu2Config.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TdlDstu2Config.java index 93ed4a88dc3..fd267a1940c 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TdlDstu2Config.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TdlDstu2Config.java @@ -7,6 +7,7 @@ import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.lang3.time.DateUtils; +import org.hibernate.dialect.DerbyTenSevenDialect; import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Autowire; import org.springframework.beans.factory.annotation.Value; @@ -98,6 +99,7 @@ public class TdlDstu2Config extends BaseJavaConfigDstu2 { private Properties jpaProperties() { Properties extraProperties = new Properties(); + extraProperties.put("hibernate.dialect", DerbyTenSevenDialect.class.getName()); extraProperties.put("hibernate.format_sql", "false"); extraProperties.put("hibernate.show_sql", "false"); extraProperties.put("hibernate.hbm2ddl.auto", "update"); diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TdlDstu3Config.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TdlDstu3Config.java index ac94f011bf8..43cff75c5b5 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TdlDstu3Config.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TdlDstu3Config.java @@ -7,6 +7,7 @@ import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.lang3.time.DateUtils; +import org.hibernate.dialect.DerbyTenSevenDialect; import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Autowire; import org.springframework.beans.factory.annotation.Value; @@ -88,6 +89,7 @@ public class TdlDstu3Config extends BaseJavaConfigDstu3 { private Properties jpaProperties() { Properties extraProperties = new Properties(); + extraProperties.put("hibernate.dialect", DerbyTenSevenDialect.class.getName()); extraProperties.put("hibernate.format_sql", "false"); extraProperties.put("hibernate.show_sql", "false"); extraProperties.put("hibernate.hbm2ddl.auto", "update"); diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu1Config.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu1Config.java index baa50c9aacb..6d7f39af3a6 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu1Config.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu1Config.java @@ -6,6 +6,7 @@ import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; +import org.hibernate.dialect.DerbyTenSevenDialect; import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -81,6 +82,7 @@ public class TestDstu1Config extends BaseJavaConfigDstu1 { private Properties jpaProperties() { Properties extraProperties = new Properties(); + extraProperties.put("hibernate.dialect", DerbyTenSevenDialect.class.getName()); extraProperties.put("hibernate.format_sql", "true"); extraProperties.put("hibernate.show_sql", "false"); extraProperties.put("hibernate.hbm2ddl.auto", "update"); diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu2Config.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu2Config.java index 7ab13bed574..6e0c0881bc9 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu2Config.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu2Config.java @@ -7,6 +7,7 @@ import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.lang3.time.DateUtils; +import org.hibernate.dialect.DerbyTenSevenDialect; import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Autowire; import org.springframework.beans.factory.annotation.Value; @@ -98,6 +99,7 @@ public class TestDstu2Config extends BaseJavaConfigDstu2 { private Properties jpaProperties() { Properties extraProperties = new Properties(); + extraProperties.put("hibernate.dialect", DerbyTenSevenDialect.class.getName()); extraProperties.put("hibernate.format_sql", "false"); extraProperties.put("hibernate.show_sql", "false"); extraProperties.put("hibernate.hbm2ddl.auto", "update"); diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java index 751f4521080..646be3280b4 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java @@ -7,6 +7,7 @@ import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.lang3.time.DateUtils; +import org.hibernate.dialect.DerbyTenSevenDialect; import org.hibernate.jpa.HibernatePersistenceProvider; import org.springframework.beans.factory.annotation.Autowire; import org.springframework.beans.factory.annotation.Value; @@ -82,6 +83,7 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 { private Properties jpaProperties() { Properties extraProperties = new Properties(); + extraProperties.put("hibernate.dialect", DerbyTenSevenDialect.class.getName()); extraProperties.put("hibernate.format_sql", "false"); extraProperties.put("hibernate.show_sql", "false"); extraProperties.put("hibernate.hbm2ddl.auto", "update"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java index 4f838e076f1..265c2a7d94b 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -159,7 +160,7 @@ public class BinaryDstu2Test { IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals("foo", status.getFirstHeader("content-type").getValue()); - assertEquals("Attachment;", status.getFirstHeader("Content-Disposition").getValue()); + assertEquals("Attachment;", status.getFirstHeader("Content-Disposition").getValue()); // This is a security requirement! assertArrayEquals(new byte[] { 1, 2, 3, 4 }, responseContent); } @@ -170,7 +171,7 @@ public class BinaryDstu2Test { httpGet.addHeader("Accept", Constants.CT_FHIR_JSON); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(Constants.CT_FHIR_JSON + ";charset=utf-8", status.getFirstHeader("content-type").getValue().replace(" ", "").toLowerCase()); @@ -183,7 +184,7 @@ public class BinaryDstu2Test { public void testSearchJson() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary?_pretty=true&_format=json"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(Constants.CT_FHIR_JSON + ";charset=utf-8", status.getFirstHeader("content-type").getValue().replace(" ", "").replace("UTF", "utf")); @@ -201,7 +202,7 @@ public class BinaryDstu2Test { public void testSearchXml() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Binary?_pretty=true"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(Constants.CT_FHIR_XML + ";charset=utf-8", status.getFirstHeader("content-type").getValue().replace(" ", "").replace("UTF", "utf")); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java index 0e8656f9338..33419de199b 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerMimetypeDstu3Test.java @@ -88,7 +88,7 @@ public class ServerMimetypeDstu3Test { httpPost.setEntity(new StringEntity(enc, ContentType.parse(Constants.CT_FHIR_XML + "; charset=utf-8"))); HttpResponse status = ourClient.execute(httpPost); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -138,7 +138,7 @@ public class ServerMimetypeDstu3Test { httpPost.setEntity(new StringEntity(enc, ContentType.parse(Constants.CT_FHIR_XML_NEW + "; charset=utf-8"))); HttpResponse status = ourClient.execute(httpPost); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -159,7 +159,7 @@ public class ServerMimetypeDstu3Test { httpPost.addHeader(Constants.HEADER_ACCEPT, Constants.CT_FHIR_XML_NEW); HttpResponse status = ourClient.execute(httpPost); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -179,7 +179,7 @@ public class ServerMimetypeDstu3Test { httpPost.setEntity(new StringEntity(enc, ContentType.parse(Constants.CT_FHIR_JSON + "; charset=utf-8"))); HttpResponse status = ourClient.execute(httpPost); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -199,7 +199,7 @@ public class ServerMimetypeDstu3Test { httpPost.setEntity(new StringEntity(enc, ContentType.parse(Constants.CT_FHIR_JSON_NEW + "; charset=utf-8"))); HttpResponse status = ourClient.execute(httpPost); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -220,7 +220,7 @@ public class ServerMimetypeDstu3Test { httpPost.addHeader(Constants.HEADER_ACCEPT, Constants.CT_FHIR_JSON_NEW); HttpResponse status = ourClient.execute(httpPost); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -236,7 +236,7 @@ public class ServerMimetypeDstu3Test { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=xml"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -244,7 +244,7 @@ public class ServerMimetypeDstu3Test { assertEquals(200, status.getStatusLine().getStatusCode()); assertThat(responseContent, containsString("")); assertThat(responseContent, not(containsString("http://hl7.org/fhir/"))); - assertEquals(Constants.CT_FHIR_XML, status.getFirstHeader("content-type").getValue().replaceAll(";.*", "")); + assertEquals(Constants.CT_FHIR_XML_NEW, status.getFirstHeader("content-type").getValue().replaceAll(";.*", "")); } @Test @@ -253,7 +253,7 @@ public class ServerMimetypeDstu3Test { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=" + Constants.CT_FHIR_XML); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -270,7 +270,7 @@ public class ServerMimetypeDstu3Test { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=" + Constants.CT_FHIR_XML_NEW); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -278,7 +278,7 @@ public class ServerMimetypeDstu3Test { assertEquals(200, status.getStatusLine().getStatusCode()); assertThat(responseContent, containsString("")); assertThat(responseContent, not(containsString("http://hl7.org/fhir/"))); - assertEquals(Constants.CT_FHIR_XML, status.getFirstHeader("content-type").getValue().replaceAll(";.*", "")); + assertEquals(Constants.CT_FHIR_XML_NEW, status.getFirstHeader("content-type").getValue().replaceAll(";.*", "")); } @@ -289,14 +289,14 @@ public class ServerMimetypeDstu3Test { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=json"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); assertThat(responseContent, containsString("\"resourceType\"")); - assertEquals(Constants.CT_FHIR_JSON, status.getFirstHeader("content-type").getValue().replaceAll(";.*", "")); + assertEquals(Constants.CT_FHIR_JSON_NEW, status.getFirstHeader("content-type").getValue().replaceAll(";.*", "")); } @Test @@ -305,7 +305,7 @@ public class ServerMimetypeDstu3Test { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=" + Constants.CT_FHIR_JSON); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); @@ -321,14 +321,14 @@ public class ServerMimetypeDstu3Test { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_format=" + Constants.CT_FHIR_JSON_NEW); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); assertThat(responseContent, containsString("\"resourceType\"")); - assertEquals(Constants.CT_FHIR_JSON, status.getFirstHeader("content-type").getValue().replaceAll(";.*", "")); + assertEquals(Constants.CT_FHIR_JSON_NEW, status.getFirstHeader("content-type").getValue().replaceAll(";.*", "")); } @AfterClass diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e8ccd8365d4..5d9b1dbe5ee 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -19,6 +19,11 @@ Thanks to Pater Girard for all of his help during the connectathon in implementing this feature! + + Both client and server now use the new STU3 mime types by default + if running in STU3 mode (in other words, using an STU3 + FhirContext). + In server, when returning a list of resources, the server sometimes failed to add _include]]> resources to the response bundle if they were