Fix #472 - Wrong header being returned (Content-Location instead of

Location) on STU3 server
This commit is contained in:
James Agnew 2016-10-26 12:12:19 -04:00
parent a246809c92
commit a67171e231
3 changed files with 35 additions and 2 deletions

View File

@ -607,9 +607,9 @@ public class RestfulServerUtils {
if (theAddContentLocationHeader && fullId != null) { if (theAddContentLocationHeader && fullId != null) {
if (theServer.getFhirContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { if (theServer.getFhirContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) {
restUtil.addHeader(Constants.HEADER_LOCATION, fullId.getValue()); restUtil.addHeader(Constants.HEADER_CONTENT_LOCATION, fullId.getValue());
} }
restUtil.addHeader(Constants.HEADER_CONTENT_LOCATION, fullId.getValue()); restUtil.addHeader(Constants.HEADER_LOCATION, fullId.getValue());
} }
if (theServer.getETagSupport() == ETagSupportEnum.ENABLED) { if (theServer.getETagSupport() == ETagSupportEnum.ENABLED) {

View File

@ -46,6 +46,29 @@ public class CreateDstu3Test {
private static int ourPort; private static int ourPort;
private static Server ourServer; private static Server ourServer;
/**
* #472
*/
@Test
public void testCreateReturnsLocationHeader() throws Exception {
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient");
httpPost.setEntity(new StringEntity("{\"resourceType\":\"Patient\", \"status\":\"active\"}", ContentType.parse("application/fhir+json; charset=utf-8")));
HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
IOUtils.closeQuietly(status.getEntity().getContent());
ourLog.info("Response was:\n{}", responseContent);
assertEquals(201, status.getStatusLine().getStatusCode());
assertEquals(1, status.getHeaders("Location").length);
assertEquals(0, status.getHeaders("Content-Location").length);
assertEquals("http://localhost:" + ourPort + "/Patient/1", status.getFirstHeader("Location").getValue());
}
/** /**
* #342 * #342
*/ */

View File

@ -231,6 +231,16 @@
way in if there is no way they will be accepted way in if there is no way they will be accepted
to the resource check on the way out to the resource check on the way out
</action> </action>
<action type="fix" issue="472">
STU3 servers were incorrectly returning the
<![CDATA[<code>Content-Location</code>]]>
header instead of the
<![CDATA[<code>Content</code>]]>
header. The former has been removed from the
FHIR specification in STU3, but the
latter got removed in HAPI's code base.
Thanks to Jim Steel for reporting!
</action>
</release> </release>
<release version="2.0" date="2016-08-30"> <release version="2.0" date="2016-08-30">
<action type="fix"> <action type="fix">