From e65363f74db4e702f96a9035f4c6bf17fb273211 Mon Sep 17 00:00:00 2001 From: Diederik Muylwyk Date: Fri, 3 Jan 2020 12:31:11 -0500 Subject: [PATCH 1/2] Fix typo. --- .../ca/uhn/hapi/fhir/docs/validation/profile_validator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/validation/profile_validator.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/validation/profile_validator.md index 5e71c9064eb..ebb455e92c5 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/validation/profile_validator.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/validation/profile_validator.md @@ -79,7 +79,7 @@ However, if you have needs beyond simply validating against the core FHIR specif {{snippet:classpath:/ca/uhn/hapi/fhir/docs/ValidatorExamples.java|validateSupplyProfiles}} ``` -# Buiilt-In Validation Support Classes +# Built-In Validation Support Classes There are a several implementations of the [IValidationSupport](/hapi-fhir/apidocs/hapi-fhir-structures-r4/org/hl7/fhir/r4/hapi/ctx/IValidationSupport.html) interface built into HAPI FHIR that can be used, typically in a chain. From 89c1a15aa42160792910dc0538cceaba69f91c3f Mon Sep 17 00:00:00 2001 From: Petro Mykhaylyshyn Date: Sat, 23 Nov 2019 18:56:22 +0200 Subject: [PATCH 2/2] [(fixclienthandle204)] Fixed handling 204 response which has no body in hapiclient. --- .../uhn/fhir/rest/client/impl/BaseClient.java | 4 +++ .../rest/client/GenericClientDstu2Test.java | 30 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/BaseClient.java b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/BaseClient.java index 82b5d196a5c..ee000bd9baa 100644 --- a/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/BaseClient.java +++ b/hapi-fhir-client/src/main/java/ca/uhn/fhir/rest/client/impl/BaseClient.java @@ -375,6 +375,10 @@ public abstract class BaseClient implements IRestfulClient { } } + if (inputStreamToReturn == null) { + inputStreamToReturn = new ByteArrayInputStream(new byte[]{}); + } + return binding.invokeClient(mimeType, inputStreamToReturn, response.getStatus(), headers); } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java index 56b6d378d2f..0622c981494 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java @@ -14,6 +14,8 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; import ca.uhn.fhir.model.dstu2.resource.Bundle.Link; import ca.uhn.fhir.model.dstu2.resource.Conformance.Rest; import ca.uhn.fhir.model.dstu2.resource.Conformance.RestSecurity; +import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; +import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum; import ca.uhn.fhir.model.primitive.*; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.IParser; @@ -22,6 +24,7 @@ import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; import ca.uhn.fhir.rest.client.api.*; import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException; +import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException; import ca.uhn.fhir.rest.client.impl.BaseClient; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.param.DateParam; @@ -2360,6 +2363,33 @@ public class GenericClientDstu2Test { assertEquals("Patient/2/_history/2", response.getEntry().get(1).getResponse().getLocation()); } + @Test + public void testTransactionHandle204NoBody() throws Exception { + + IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir"); + + ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new Bundle(); + bundle.setType(BundleTypeEnum.TRANSACTION); + + ca.uhn.fhir.model.dstu2.resource.Bundle.Entry entry = bundle.addEntry(); + entry.setResource(new Patient()); + entry.getRequest().setMethod(HTTPVerbEnum.PUT); + + + + ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); + when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); + when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_204_NO_CONTENT, "")); + when(myHttpResponse.getEntity() ).thenReturn(null); + + try { + client.transaction().withBundle(bundle).execute(); + fail("Should throw an exception"); + } catch (NonFhirResponseException e) { + assertEquals("status", Constants.STATUS_HTTP_204_NO_CONTENT, e.getStatusCode()); + } + } + @Test public void testUpdateConditional() throws Exception { ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class);