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-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. 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);