From 8846477b7b276d9788e2106525ebb82181f51bd3 Mon Sep 17 00:00:00 2001 From: Michael Lawley Date: Wed, 30 Nov 2016 12:03:02 +1000 Subject: [PATCH] Ensure that older DSTU3 versions (ie Baltimore / May2016 / 1.4.0) use the legacy mime types --- .../fhir/rest/server/RestfulServerUtils.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 bf3b99d2c03..2b86df6f05e 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 @@ -77,6 +77,15 @@ public class RestfulServerUtils { private static final HashSet TEXT_ENCODE_ELEMENTS = new HashSet(Arrays.asList("Bundle", "*.text", "*.(mandatory)")); + private static String actualDstu3FhirVersion = FhirVersionEnum.DSTU3.getFhirVersionString(); + static { + try { + Class c = Class.forName("org.hl7.fhir.dstu3.model.Constants"); + actualDstu3FhirVersion = (String) c.getDeclaredField("VERSION").get(null); + } catch (Exception e) { + } + } + public static void configureResponseParser(RequestDetails theRequestDetails, IParser parser) { // Pretty print boolean prettyPrint = RestfulServerUtils.prettyPrintResponse(theRequestDetails.getServer(), theRequestDetails); @@ -757,12 +766,16 @@ public class RestfulServerUtils { myEncoding = theEncoding; if (theContentType != null) { if (theContentType.equals(EncodingEnum.JSON_PLAIN_STRING) || theContentType.equals(EncodingEnum.XML_PLAIN_STRING)) { - myNonLegacy = !theCtx.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3); + FhirVersionEnum ctxtEnum = theCtx.getVersion().getVersion(); + myNonLegacy = ctxtEnum.isNewerThan(FhirVersionEnum.DSTU3) + || (ctxtEnum.isEquivalentTo(FhirVersionEnum.DSTU3) && !"1.4.0".equals(actualDstu3FhirVersion)); } else { myNonLegacy = EncodingEnum.isNonLegacy(theContentType); } } else { - if (theCtx.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { + FhirVersionEnum ctxtEnum = theCtx.getVersion().getVersion(); + if (ctxtEnum.isOlderThan(FhirVersionEnum.DSTU3) + || (ctxtEnum.isEquivalentTo(FhirVersionEnum.DSTU3) && "1.4.0".equals(actualDstu3FhirVersion))) { myNonLegacy = null; } else { myNonLegacy = Boolean.TRUE;