Disable content header on response for non-create operations

This commit is contained in:
jamesagnew 2018-05-25 07:28:01 -04:00
parent 09eb52ed27
commit 67f21426cb
13 changed files with 135 additions and 91 deletions

View File

@ -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 {

View File

@ -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<String> searchAndReturnUnqualifiedIdValues(String uri) throws IOException, ClientProtocolException {
private List<String> searchAndReturnUnqualifiedIdValues(String uri) throws IOException {
List<String> ids;
HttpGet get = new HttpGet(uri);
@ -188,7 +188,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test {
return ids;
}
private List<String> searchAndReturnUnqualifiedVersionlessIdValues(String uri) throws IOException, ClientProtocolException {
private List<String> searchAndReturnUnqualifiedVersionlessIdValues(String uri) throws IOException {
List<String> 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<IBaseResource> resources = new ArrayList<IBaseResource>();
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<IIdType> 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<IBaseResource> resources = new ArrayList<IBaseResource>();
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<IBaseResource> resources = new ArrayList<IBaseResource>();
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<IBaseResource> resources = new ArrayList<IBaseResource>();
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();

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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());

View File

@ -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());
}

View File

@ -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(
"<Patient xmlns=\"http://hl7.org/fhir\">",

View File

@ -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());

View File

@ -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<ILoggingEvent>() {
verify(myMockAppender, times(1)).doAppend(argThat(new ArgumentMatcher<ILoggingEvent>() {
@Override
public boolean matches(final Object argument) {
String formattedMessage = ((LoggingEvent) argument).getFormattedMessage();

View File

@ -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");

View File

@ -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());
}

View File

@ -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!
</action>
<action type="fix">
The REST server has been modified so that the
<![CDATA[<code>Location</code>]]>
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
<![CDATA[<code>Content-Location</code>]]>
will still be returned, and will hold the same contents.
</action>
</release>
<release version="3.3.0" date="2018-03-29">
<action type="add">