From 67f21426cbbd839b5e3cb0e580efe7a29b5807ef Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 25 May 2018 07:28:01 -0400 Subject: [PATCH] Disable content header on response for non-create operations --- .../provider/ResourceProviderDstu2Test.java | 8 +- .../dstu3/ResourceProviderDstu3Test.java | 103 +++++++++--------- .../provider/r4/ResourceProviderR4Test.java | 8 +- .../fhir/rest/server/RestfulServerUtils.java | 40 ++++--- .../uhn/fhir/rest/server/ReadDstu2_1Test.java | 2 +- .../uhn/fhir/rest/server/UpdateDstu2Test.java | 6 +- .../uhn/fhir/rest/server/CreateDstu3Test.java | 2 +- .../uhn/fhir/rest/server/ReadDstu3Test.java | 4 +- .../UpdateConditionalHl7OrgDstu2Test.java | 4 +- .../rest/client/LoggingInterceptorTest.java | 2 +- .../fhir/rest/server/BinaryServerR4Test.java | 33 +++++- .../ca/uhn/fhir/rest/server/CreateR4Test.java | 4 +- src/changes/changes.xml | 10 ++ 13 files changed, 135 insertions(+), 91 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java index 8574762e9af..13dbedd304f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java @@ -244,7 +244,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { CloseableHttpResponse resp = ourHttpClient.execute(putRequest); try { assertEquals(200, resp.getStatusLine().getStatusCode()); - assertEquals(resource.withVersion("2").getValue(), resp.getFirstHeader("Location").getValue()); + assertEquals(resource.withVersion("2").getValue(), resp.getFirstHeader("Content-Location").getValue()); } finally { IOUtils.closeQuietly(resp); } @@ -260,7 +260,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { resp = ourHttpClient.execute(putRequest); try { assertEquals(200, resp.getStatusLine().getStatusCode()); - assertEquals(resource.withVersion("3").getValue(), resp.getFirstHeader("Location").getValue()); + assertEquals(resource.withVersion("3").getValue(), resp.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue()); } finally { IOUtils.closeQuietly(resp); } @@ -2415,7 +2415,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { response = ourHttpClient.execute(put); try { assertEquals(200, response.getStatusLine().getStatusCode()); - IdDt newId = new IdDt(response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue()); + IdDt newId = new IdDt(response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION_LC).getValue()); assertEquals(id.toVersionless(), newId.toVersionless()); // version shouldn't match for conditional update assertNotEquals(id, newId); } finally { @@ -2454,7 +2454,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { response = ourHttpClient.execute(put); try { assertEquals(200, response.getStatusLine().getStatusCode()); - String newIdString = response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue(); + String newIdString = response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION_LC).getValue(); assertThat(newIdString, startsWith(ourServerBase + "/Patient/")); id2 = new IdDt(newIdString); } finally { 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 75e30533aa3..d34d31b3a7a 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 @@ -135,7 +135,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { mySearchCoordinatorSvcRaw = AopTestUtils.getTargetObject(mySearchCoordinatorSvc); } - private void checkParamMissing(String paramName) throws IOException, ClientProtocolException { + private void checkParamMissing(String paramName) throws IOException { HttpGet get = new HttpGet(ourServerBase + "/Observation?" + paramName + ":missing=false"); CloseableHttpResponse resp = ourHttpClient.execute(get); IOUtils.closeQuietly(resp.getEntity().getContent()); @@ -172,7 +172,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { assertEquals(1, exts.size()); } - private List searchAndReturnUnqualifiedIdValues(String uri) throws IOException, ClientProtocolException { + private List searchAndReturnUnqualifiedIdValues(String uri) throws IOException { List ids; HttpGet get = new HttpGet(uri); @@ -188,7 +188,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { return ids; } - private List searchAndReturnUnqualifiedVersionlessIdValues(String uri) throws IOException, ClientProtocolException { + private List searchAndReturnUnqualifiedVersionlessIdValues(String uri) throws IOException { List ids; HttpGet get = new HttpGet(uri); @@ -280,7 +280,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testCountParam() throws Exception { + public void testCountParam() { List resources = new ArrayList(); for (int i = 0; i < 100; i++) { Organization org = new Organization(); @@ -303,7 +303,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * See #438 */ @Test - public void testCreateAndUpdateBinary() throws ClientProtocolException, Exception { + public void testCreateAndUpdateBinary() throws Exception { byte[] arr = { 1, 21, 74, 123, -44 }; Binary binary = new Binary(); binary.setContent(arr); @@ -320,7 +320,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { CloseableHttpResponse resp = ourHttpClient.execute(putRequest); try { assertEquals(200, resp.getStatusLine().getStatusCode()); - assertEquals(resource.withVersion("2").getValue(), resp.getFirstHeader("Location").getValue()); + assertEquals(resource.withVersion("2").getValue(), resp.getFirstHeader("Content-Location").getValue()); } finally { IOUtils.closeQuietly(resp); } @@ -336,7 +336,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { resp = ourHttpClient.execute(putRequest); try { assertEquals(200, resp.getStatusLine().getStatusCode()); - assertEquals(resource.withVersion("3").getValue(), resp.getFirstHeader("Location").getValue()); + assertEquals(resource.withVersion("3").getValue(), resp.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue()); } finally { IOUtils.closeQuietly(resp); } @@ -391,7 +391,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testCreateIncludesRequestValidatorInterceptorOutcome() throws IOException { + public void testCreateIncludesRequestValidatorInterceptorOutcome() { RequestValidatingInterceptor interceptor = new RequestValidatingInterceptor(); assertTrue(interceptor.isAddValidationResultsToResponseOperationOutcome()); interceptor.setFailOnSeverity(null); @@ -422,7 +422,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { @Test @Ignore - public void testCreateQuestionnaireResponseWithValidation() throws IOException { + public void testCreateQuestionnaireResponseWithValidation() { CodeSystem cs = new CodeSystem(); cs.setUrl("http://urn/system"); cs.addConcept().setCode("code0"); @@ -583,7 +583,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testCreateWithForcedId() throws IOException { + public void testCreateWithForcedId() { String methodName = "testCreateWithForcedId"; Patient p = new Patient(); @@ -812,7 +812,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * Based on email from Rene Spronk */ @Test - public void testDeleteResourceConditional2() throws IOException, Exception { + public void testDeleteResourceConditional2() throws Exception { String methodName = "testDeleteResourceConditional2"; Patient pt = new Patient(); @@ -925,7 +925,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testEmptySearch() throws Exception { + public void testEmptySearch() { Bundle responseBundle; responseBundle = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).execute(); @@ -940,7 +940,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testEverythingEncounterInstance() throws Exception { + public void testEverythingEncounterInstance() { String methodName = "testEverythingEncounterInstance"; Organization org1parent = new Organization(); @@ -1004,7 +1004,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testEverythingEncounterType() throws Exception { + public void testEverythingEncounterType() { String methodName = "testEverythingEncounterInstance"; Organization org1parent = new Organization(); @@ -1104,7 +1104,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { List actual; StringAndListParam param; - ourLog.info("Pt1:{} Pt2:{} Obs1:{} Obs2:{} Obs3:{}", new Object[] { ptId1.getIdPart(), ptId2.getIdPart(), obsId1.getIdPart(), obsId2.getIdPart(), obsId3.getIdPart() }); + ourLog.info("Pt1:{} Pt2:{} Obs1:{} Obs2:{} Obs3:{}", ptId1.getIdPart(), ptId2.getIdPart(), obsId1.getIdPart(), obsId2.getIdPart(), obsId3.getIdPart()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); @@ -1127,7 +1127,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * See #147"Patient" */ @Test - public void testEverythingPatientDoesntRepeatPatient() throws Exception { + public void testEverythingPatientDoesntRepeatPatient() { Bundle b; IParser parser = myFhirCtx.newJsonParser(); b = parser.parseResource(Bundle.class, new InputStreamReader(ResourceProviderDstu3Test.class.getResourceAsStream("/bug147-bundle-dstu3.json"))); @@ -1187,7 +1187,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * Test for #226 */ @Test - public void testEverythingPatientIncludesBackReferences() throws Exception { + public void testEverythingPatientIncludesBackReferences() { String methodName = "testEverythingIncludesBackReferences"; Medication med = new Medication(); @@ -1214,7 +1214,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * See #148 */ @Test - public void testEverythingPatientIncludesCondition() throws Exception { + public void testEverythingPatientIncludesCondition() { Bundle b = new Bundle(); Patient p = new Patient(); p.setId("1"); @@ -1246,7 +1246,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testEverythingPatientOperation() throws Exception { + public void testEverythingPatientOperation() { String methodName = "testEverythingOperation"; Organization org1parent = new Organization(); @@ -1291,7 +1291,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testEverythingPatientType() throws Exception { + public void testEverythingPatientType() { String methodName = "testEverythingPatientType"; Organization o1 = new Organization(); @@ -1507,7 +1507,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * Per message from David Hay on Skype */ @Test - public void testEverythingWithLargeSet2() throws Exception { + public void testEverythingWithLargeSet2() { Patient p = new Patient(); p.setActive(true); IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); @@ -1598,7 +1598,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { @SuppressWarnings("unused") @Test - public void testFullTextSearch() throws RuntimeException, Exception { + public void testFullTextSearch() throws Exception { Observation obs1 = new Observation(); obs1.getCode().setText("Systolic Blood Pressure"); obs1.setStatus(ObservationStatus.FINAL); @@ -1912,7 +1912,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { @SuppressWarnings("unused") @Test - public void testMetadataSuperParamsAreIncluded() throws IOException { + public void testMetadataSuperParamsAreIncluded() { StructureDefinition p = new StructureDefinition(); p.setAbstract(true); p.setUrl("http://example.com/foo"); @@ -1929,7 +1929,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testMetaOperations() throws Exception { + public void testMetaOperations() { String methodName = "testMetaOperations"; Patient pt = new Patient(); @@ -2051,7 +2051,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testPagingOverEverythingSetWithNoPagingProvider() throws InterruptedException { + public void testPagingOverEverythingSetWithNoPagingProvider() { ourRestServer.setPagingProvider(null); Patient p = new Patient(); @@ -2239,7 +2239,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * See issue #52 */ @Test - public void testProcedureRequestResources() throws Exception { + public void testProcedureRequestResources() { IGenericClient client = ourClient; int initialSize = client.search().forResource(ProcedureRequest.class).returnBundle(Bundle.class).execute().getEntry().size(); @@ -2259,7 +2259,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * Test for issue #60 */ @Test - public void testReadAllInstancesOfType() throws Exception { + public void testReadAllInstancesOfType() { Patient pat; pat = new Patient(); @@ -2697,14 +2697,14 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().setFamily(methodName).addGiven("Joe"); - id1a = (IdType) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + id1a = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); } IIdType id1b; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().setFamily(methodName + "XXXX").addGiven("Joe"); - id1b = (IdType) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + id1b = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); } Thread.sleep(1100); @@ -2716,7 +2716,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().setFamily(methodName).addGiven("John"); - id2 = (IdType) ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + id2 = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); } { @@ -2811,7 +2811,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { @SuppressWarnings("unused") @Test - public void testSearchPagingKeepsOldSearches() throws Exception { + public void testSearchPagingKeepsOldSearches() { String methodName = "testSearchPagingKeepsOldSearches"; IIdType pid1; { @@ -2844,7 +2844,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } } - private void testSearchReturnsResults(String search) throws IOException, ClientProtocolException { + private void testSearchReturnsResults(String search) throws IOException { int matches; HttpGet get = new HttpGet(ourServerBase + search); CloseableHttpResponse response = ourHttpClient.execute(get); @@ -2885,7 +2885,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testSearchReusesNoParams() throws Exception { + public void testSearchReusesNoParams() { List resources = new ArrayList(); for (int i = 0; i < 50; i++) { Organization org = new Organization(); @@ -2916,7 +2916,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testSearchReusesResultsDisabled() throws Exception { + public void testSearchReusesResultsDisabled() { List resources = new ArrayList(); for (int i = 0; i < 50; i++) { Organization org = new Organization(); @@ -3026,7 +3026,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testSearchReusesResultsEnabledNoParams() throws Exception { + public void testSearchReusesResultsEnabledNoParams() { List resources = new ArrayList(); for (int i = 0; i < 50; i++) { Organization org = new Organization(); @@ -3159,7 +3159,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { testSearchWithEmptyParameter("/Observation?code=bar&value-concept="); } - private void testSearchWithEmptyParameter(String url) throws IOException, ClientProtocolException { + private void testSearchWithEmptyParameter(String url) throws IOException { HttpGet get = new HttpGet(ourServerBase + url); CloseableHttpResponse resp = ourHttpClient.execute(get); try { @@ -3173,7 +3173,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testSearchWithInclude() throws Exception { + public void testSearchWithInclude() { Organization org = new Organization(); org.addIdentifier().setSystem("urn:system:rpdstu2").setValue("testSearchWithInclude01"); IdType orgId = (IdType) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId(); @@ -3202,7 +3202,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test() - public void testSearchWithInvalidNumberPrefix() throws Exception { + public void testSearchWithInvalidNumberPrefix() { try { //@formatter:off ourClient @@ -3220,7 +3220,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test() - public void testSearchWithInvalidQuantityPrefix() throws Exception { + public void testSearchWithInvalidQuantityPrefix() { Observation o = new Observation(); o.getCode().setText("testSearchWithInvalidSort"); myObservationDao.create(o, mySrd); @@ -3266,7 +3266,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test(expected = InvalidRequestException.class) - public void testSearchWithInvalidSort() throws Exception { + public void testSearchWithInvalidSort() { Observation o = new Observation(); o.getCode().setText("testSearchWithInvalidSort"); myObservationDao.create(o, mySrd); @@ -3282,7 +3282,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testSearchWithMissing() throws Exception { + public void testSearchWithMissing() { ourLog.info("Starting testSearchWithMissing"); String methodName = "testSearchWithMissing"; @@ -3561,7 +3561,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * Test for issue #60 */ @Test - public void testStoreUtf8Characters() throws Exception { + public void testStoreUtf8Characters() { Organization org = new Organization(); org.setName("測試醫院"); org.addIdentifier().setSystem("urn:system").setValue("testStoreUtf8Characters_01"); @@ -3615,7 +3615,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testUpdateInvalidReference() throws IOException, Exception { + public void testUpdateInvalidReference() throws Exception { String methodName = "testUpdateInvalidReference"; Patient pt = new Patient(); @@ -3638,7 +3638,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testUpdateInvalidReference2() throws IOException, Exception { + public void testUpdateInvalidReference2() throws Exception { String methodName = "testUpdateInvalidReference2"; Patient pt = new Patient(); @@ -3665,7 +3665,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { */ @Test @Ignore - public void testUpdateNoIdInBody() throws IOException, Exception { + public void testUpdateNoIdInBody() throws Exception { String methodName = "testUpdateNoIdInBody"; Patient pt = new Patient(); @@ -3748,7 +3748,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testUpdateRejectsInvalidTypes() throws InterruptedException { + public void testUpdateRejectsInvalidTypes() { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsInvalidTypes"); @@ -3802,7 +3802,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { response = ourHttpClient.execute(put); try { assertEquals(200, response.getStatusLine().getStatusCode()); - IdType newId = new IdType(response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue()); + IdType newId = new IdType(response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION_LC).getValue()); assertEquals(id.toVersionless(), newId.toVersionless()); // version shouldn't match for conditional update assertNotEquals(id, newId); } finally { @@ -3841,7 +3841,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { response = ourHttpClient.execute(put); try { assertEquals(200, response.getStatusLine().getStatusCode()); - String newIdString = response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue(); + String newIdString = response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION_LC).getValue(); assertThat(newIdString, startsWith(ourServerBase + "/Patient/")); id2 = new IdType(newIdString); } finally { @@ -3854,7 +3854,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testUpdateResourceWithPrefer() throws IOException, Exception { + public void testUpdateResourceWithPrefer() throws Exception { String methodName = "testUpdateResourceWithPrefer"; Patient pt = new Patient(); @@ -3930,7 +3930,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testUpdateWithETag() throws IOException, Exception { + public void testUpdateWithETag() throws Exception { String methodName = "testUpdateWithETag"; Patient pt = new Patient(); @@ -3971,7 +3971,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - public void testUpdateWrongIdInBody() throws IOException, Exception { + public void testUpdateWrongIdInBody() throws Exception { String methodName = "testUpdateWrongIdInBody"; Patient pt = new Patient(); @@ -4067,7 +4067,6 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { Patient patient = new Patient(); patient.addName().addGiven("James" + StringUtils.leftPad("James", 1000000, 'A')); - ; patient.setBirthDateElement(new DateType("2011-02-02")); Parameters input = new Parameters(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index 2ba483856c3..4bd8a736df3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -330,7 +330,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { CloseableHttpResponse resp = ourHttpClient.execute(putRequest); try { assertEquals(200, resp.getStatusLine().getStatusCode()); - assertEquals(resource.withVersion("2").getValue(), resp.getFirstHeader("Location").getValue()); + assertEquals(resource.withVersion("2").getValue(), resp.getFirstHeader("Content-Location").getValue()); } finally { IOUtils.closeQuietly(resp); } @@ -346,7 +346,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { resp = ourHttpClient.execute(putRequest); try { assertEquals(200, resp.getStatusLine().getStatusCode()); - assertEquals(resource.withVersion("3").getValue(), resp.getFirstHeader("Location").getValue()); + assertEquals(resource.withVersion("3").getValue(), resp.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue()); } finally { IOUtils.closeQuietly(resp); } @@ -4271,7 +4271,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { response = ourHttpClient.execute(put); try { assertEquals(200, response.getStatusLine().getStatusCode()); - IdType newId = new IdType(response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue()); + IdType newId = new IdType(response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION_LC).getValue()); assertEquals(id.toVersionless(), newId.toVersionless()); // version shouldn't match for conditional update assertNotEquals(id, newId); } finally { @@ -4310,7 +4310,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { response = ourHttpClient.execute(put); try { assertEquals(200, response.getStatusLine().getStatusCode()); - String newIdString = response.getFirstHeader(Constants.HEADER_LOCATION_LC).getValue(); + String newIdString = response.getFirstHeader(Constants.HEADER_CONTENT_LOCATION_LC).getValue(); assertThat(newIdString, startsWith(ourServerBase + "/Patient/")); id2 = new IdType(newIdString); } finally { diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java index 6980c011056..36710e49f2c 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java @@ -28,10 +28,7 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.api.EncodingEnum; -import ca.uhn.fhir.rest.api.PreferReturnEnum; -import ca.uhn.fhir.rest.api.SummaryEnum; +import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.api.server.IRestfulResponse; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; @@ -617,10 +614,10 @@ public class RestfulServerUtils { } if (theAddContentLocationHeader && fullId != null) { - if (theServer.getFhirContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { - response.addHeader(Constants.HEADER_CONTENT_LOCATION, fullId.getValue()); + if (theRequestDetails.getRequestType() == RequestTypeEnum.POST) { + response.addHeader(Constants.HEADER_LOCATION, fullId.getValue()); } - response.addHeader(Constants.HEADER_LOCATION, fullId.getValue()); + response.addHeader(Constants.HEADER_CONTENT_LOCATION, fullId.getValue()); } if (theServer.getETagSupport() == ETagSupportEnum.ENABLED) { @@ -631,19 +628,12 @@ public class RestfulServerUtils { } } + // Binary handling String contentType; - if (theResource instanceof IBaseBinary && responseEncoding == null) { + if (theResource instanceof IBaseBinary) { IBaseBinary bin = (IBaseBinary) theResource; - if (isNotBlank(bin.getContentType())) { - contentType = bin.getContentType(); - } else { - contentType = Constants.CT_OCTET_STREAM; - } - - // Force binary resources to download - This is a security measure to prevent - // malicious images or HTML blocks being served up as content. - response.addHeader(Constants.HEADER_CONTENT_DISPOSITION, "Attachment;"); + // Add a security context header IBaseReference securityContext = BinaryUtil.getSecurityContext(theServer.getFhirContext(), bin); if (securityContext != null) { String securityContextRef = securityContext.getReferenceElement().getValue(); @@ -652,7 +642,21 @@ public class RestfulServerUtils { } } - return response.sendAttachmentResponse(bin, theStatusCode, contentType); + // If the user didn't explicitly request FHIR as a response, return binary + // content directly + if (responseEncoding == null) { + if (isNotBlank(bin.getContentType())) { + contentType = bin.getContentType(); + } else { + contentType = Constants.CT_OCTET_STREAM; + } + + // Force binary resources to download - This is a security measure to prevent + // malicious images or HTML blocks being served up as content. + response.addHeader(Constants.HEADER_CONTENT_DISPOSITION, "Attachment;"); + + return response.sendAttachmentResponse(bin, theStatusCode, contentType); + } } // Ok, we're not serving a binary resource, so apply default encoding diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2_1Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2_1Test.java index 70314e82e36..ac4aadb6229 100644 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2_1Test.java +++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2_1Test.java @@ -48,7 +48,7 @@ public class ReadDstu2_1Test { ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("http://localhost:" + ourPort + "/Patient/2/_history/2", status.getFirstHeader(Constants.HEADER_LOCATION).getValue()); + assertEquals(null, status.getFirstHeader(Constants.HEADER_LOCATION)); assertEquals("http://localhost:" + ourPort + "/Patient/2/_history/2", status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue()); //@formatter:off diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu2Test.java index 7297a05ddca..a689ac321d9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu2Test.java @@ -97,7 +97,7 @@ public class UpdateDstu2Test { ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); + assertEquals(null, status.getFirstHeader("location")); assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); assertNull(ourLastId.getValue()); @@ -127,7 +127,7 @@ public class UpdateDstu2Test { assertThat(responseContent, blankOrNullString()); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); + assertEquals(null, status.getFirstHeader("location")); assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); assertEquals("W/\"002\"", status.getFirstHeader(Constants.HEADER_ETAG_LC).getValue()); assertEquals("Mon, 22 Apr 2002 11:22:33 GMT", status.getFirstHeader(Constants.HEADER_LAST_MODIFIED_LOWERCASE).getValue()); @@ -152,7 +152,7 @@ public class UpdateDstu2Test { ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); + assertEquals(null, status.getFirstHeader("location")); assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); assertEquals("Patient/2", ourLastId.toUnqualified().getValue()); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateDstu3Test.java index 16e2acc993f..1500193edc2 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateDstu3Test.java @@ -74,7 +74,7 @@ public class CreateDstu3Test { assertEquals(201, status.getStatusLine().getStatusCode()); assertEquals(1, status.getHeaders("Location").length); - assertEquals(0, status.getHeaders("Content-Location").length); + assertEquals(1, status.getHeaders("Content-Location").length); assertEquals("http://localhost:" + ourPort + "/Patient/1", status.getFirstHeader("Location").getValue()); } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ReadDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ReadDstu3Test.java index ae8065ed5c4..a5fc7228dce 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ReadDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ReadDstu3Test.java @@ -48,8 +48,8 @@ public class ReadDstu3Test { ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("http://localhost:" + ourPort + "/Patient/2/_history/2", status.getFirstHeader(Constants.HEADER_LOCATION).getValue()); - assertEquals(null, status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION)); + assertEquals(null, status.getFirstHeader(Constants.HEADER_LOCATION)); + assertEquals("http://localhost:" + ourPort + "/Patient/2/_history/2", status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue()); assertThat(responseContent, stringContainsInOrder( "", diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateConditionalHl7OrgDstu2Test.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateConditionalHl7OrgDstu2Test.java index 20ea71c6d67..0e56b9f729f 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateConditionalHl7OrgDstu2Test.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateConditionalHl7OrgDstu2Test.java @@ -70,7 +70,7 @@ public class UpdateConditionalHl7OrgDstu2Test { ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); + assertEquals(null, status.getFirstHeader("location")); assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); assertNull(ourLastId); @@ -97,7 +97,7 @@ public class UpdateConditionalHl7OrgDstu2Test { ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); + assertEquals(null, status.getFirstHeader("location")); assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); assertEquals("Patient/2", new IdType(ourLastId).toUnqualified().getValue()); diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java index 8eff0b9e38e..a91119bf365 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java @@ -76,7 +76,7 @@ public class LoggingInterceptorTest { Patient patient = client.read(Patient.class, "1"); assertFalse(patient.getIdentifierFirstRep().isEmpty()); - verify(myMockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() { + verify(myMockAppender, times(1)).doAppend(argThat(new ArgumentMatcher() { @Override public boolean matches(final Object argument) { String formattedMessage = ((LoggingEvent) argument).getFormattedMessage(); diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/BinaryServerR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/BinaryServerR4Test.java index 4bee8510f9e..ca995124560 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/BinaryServerR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/BinaryServerR4Test.java @@ -6,6 +6,7 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.TestUtil; +import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -70,7 +71,8 @@ public class BinaryServerR4Test { assertEquals("application/foo", status.getEntity().getContentType().getValue()); assertEquals("Patient/1", status.getFirstHeader(Constants.HEADER_X_SECURITY_CONTEXT).getValue()); assertEquals("W/\"222\"", status.getFirstHeader(Constants.HEADER_ETAG).getValue()); - assertEquals("http://localhost:" + ourPort + "/Binary/A/_history/222", status.getFirstHeader(Constants.HEADER_LOCATION).getValue()); + assertEquals("http://localhost:" + ourPort + "/Binary/A/_history/222", status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue()); + assertEquals(null, status.getFirstHeader(Constants.HEADER_LOCATION)); byte[] content = IOUtils.toByteArray(status.getEntity().getContent()); assertArrayEquals(new byte[]{0, 1, 2, 3, 4}, content); @@ -79,6 +81,35 @@ public class BinaryServerR4Test { } } + + @Test + public void testGetWithAccept() throws Exception { + + ourNextBinary = new Binary(); + ourNextBinary.setId("Binary/A/_history/222"); + ourNextBinary.setContent(new byte[]{0, 1, 2, 3, 4}); + ourNextBinary.setSecurityContext(new Reference("Patient/1")); + ourNextBinary.setContentType("application/foo"); + + HttpGet get = new HttpGet("http://localhost:" + ourPort + "/Binary/A"); + get.addHeader("Content-Type", "application/foo"); + get.addHeader("Accept", Constants.CT_FHIR_JSON); + CloseableHttpResponse status = ourClient.execute(get); + try { + assertEquals(200, status.getStatusLine().getStatusCode()); + assertEquals("application/json+fhir;charset=utf-8", status.getEntity().getContentType().getValue()); + assertEquals("Patient/1", status.getFirstHeader(Constants.HEADER_X_SECURITY_CONTEXT).getValue()); + assertEquals("W/\"222\"", status.getFirstHeader(Constants.HEADER_ETAG).getValue()); + assertEquals("http://localhost:" + ourPort + "/Binary/A/_history/222", status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION).getValue()); + assertEquals(null, status.getFirstHeader(Constants.HEADER_LOCATION)); + + String content = IOUtils.toString(status.getEntity().getContent(), Charsets.UTF_8); + assertEquals("{\"resourceType\":\"Binary\",\"id\":\"A\",\"meta\":{\"versionId\":\"222\"},\"contentType\":\"application/foo\",\"securityContext\":{\"reference\":\"Patient/1\"},\"content\":\"AAECAwQ=\"}", content); + } finally { + IOUtils.closeQuietly(status); + } + } + @Test public void testPostBinaryWithSecurityContext() throws Exception { HttpPost post = new HttpPost("http://localhost:" + ourPort + "/Binary"); diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/CreateR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/CreateR4Test.java index 5a03adf5002..571e86efdad 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/CreateR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/CreateR4Test.java @@ -66,7 +66,7 @@ public class CreateR4Test { assertEquals(201, status.getStatusLine().getStatusCode()); assertEquals(1, status.getHeaders("Location").length); - assertEquals(0, status.getHeaders("Content-Location").length); + assertEquals(1, status.getHeaders("Content-Location").length); assertEquals("http://localhost:" + ourPort + "/Patient/1", status.getFirstHeader("Location").getValue()); } @@ -89,7 +89,7 @@ public class CreateR4Test { assertEquals(201, status.getStatusLine().getStatusCode()); assertEquals(1, status.getHeaders("Location").length); - assertEquals(0, status.getHeaders("Content-Location").length); + assertEquals(1, status.getHeaders("Content-Location").length); assertEquals("http://localhost:" + ourPort + "/Patient/1", status.getFirstHeader("Location").getValue()); } diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9bb8343a7d5..c91f7232b42 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -266,6 +266,16 @@ QuestionnaireResponse answers of type "text" may now be validated by the FhirInstanceValidator. Thanks to Heinz-Dieter Conradi for the pull request! + + The REST server has been modified so that the + Location]]> + header is no longer returned by the server on read or update responses. + This header was returned in the past, but this header is actually + inappropriate for any response that is not a create operation. + The + Content-Location]]> + will still be returned, and will hold the same contents. +