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 2eeaa007567..c8bb6e18c36 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 @@ -224,7 +224,7 @@ public class RestfulServerUtils { } } - if (q > bestQ) { + if (q > bestQ && encoding != null) { retVal = encoding; bestQ = q; } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java index ea449f6fa1b..c98994426a9 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java @@ -16,4 +16,16 @@ public class RestfulServerUtilsTest { assertEquals("application/json+fhir", m.group(1)); } + @Test + public void testAcceptPattern2() { + Matcher m = RestfulServerUtils.ACCEPT_HEADER_PATTERN.matcher("text/plain, " + Constants.CT_FHIR_JSON); + assertTrue(m.find()); + assertEquals("text/plain,", m.group(0)); + assertEquals("text/plain", m.group(1)); + + assertTrue(m.find()); + assertEquals(" application/json+fhir", m.group(0)); + assertEquals("application/json+fhir", m.group(1)); + } + } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java index 90754d15272..042b4e2f08c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java @@ -2,6 +2,7 @@ package ca.uhn.fhir.rest.server; import static org.junit.Assert.*; +import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -10,6 +11,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; @@ -145,11 +147,15 @@ public class ServerFeaturesTest { IOUtils.closeQuietly(status.getEntity().getContent()); assertThat(responseContent, StringContains.containsString("