diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java index 6e1e6a0efd3..9efad04ab1a 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java @@ -54,6 +54,7 @@ import org.mockito.InOrder; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -126,6 +127,7 @@ public class InterceptorDstu3Test { post.setEntity(new StringEntity(input, ContentType.create("application/fhir+json", Constants.CHARSET_UTF8))); try (CloseableHttpResponse status = ourClient.execute(post)) { assertEquals(200, status.getStatusLine().getStatusCode()); + IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); } } finally { ourServlet.unregisterInterceptor(interceptor); @@ -195,8 +197,9 @@ public class InterceptorDstu3Test { HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); httpPost.setEntity(new StringEntity(input, ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); - HttpResponse status = ourClient.execute(httpPost); - IOUtils.closeQuietly(status.getEntity().getContent()); + try (CloseableHttpResponse status = ourClient.execute(httpPost)) { + IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); + } InOrder order = inOrder(myInterceptor1, myInterceptor2); order.verify(myInterceptor1, times(1)).incomingRequestPreProcessed(nullable(HttpServletRequest.class), nullable(HttpServletResponse.class)); @@ -228,11 +231,9 @@ public class InterceptorDstu3Test { HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); httpPost.setEntity(new StringEntity(input, ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); - HttpResponse status = ourClient.execute(httpPost); - try { + try (CloseableHttpResponse status = ourClient.execute(httpPost)) { + IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); assertThat(status.getStatusLine().getStatusCode(), either(equalTo(200)).or(equalTo(201))); - } finally { - IOUtils.closeQuietly(status.getEntity().getContent()); } } @@ -252,11 +253,9 @@ public class InterceptorDstu3Test { HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); httpPost.setEntity(new StringEntity(input, ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); - HttpResponse status = ourClient.execute(httpPost); - try { + try (CloseableHttpResponse status = ourClient.execute(httpPost)) { assertEquals(201, status.getStatusLine().getStatusCode()); - } finally { - IOUtils.closeQuietly(status.getEntity().getContent()); + IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); } InOrder order = inOrder(myInterceptor1); @@ -290,8 +289,9 @@ public class InterceptorDstu3Test { HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); httpPost.setEntity(new StringEntity(input, ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); - HttpResponse status = ourClient.execute(httpPost); - IOUtils.closeQuietly(status.getEntity().getContent()); + try (CloseableHttpResponse status = ourClient.execute(httpPost)) { + IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8); + } InOrder order = inOrder(myInterceptor1); order.verify(myInterceptor1, times(1)).incomingRequestPreProcessed(nullable(HttpServletRequest.class), nullable(HttpServletResponse.class));