StreamingApacheClientHttpRequest implements ClientHttpRequest, StreamingHttpOutputMessage { @Override public void setBody(final Body body) { if (request instanceof HttpEntityEnclosingRequest) { final HttpEntityEnclosingRequest enclosing = (HttpEntityEnclosingRequest) request; enclosing.setEntity(new StreamingHttpEntity(body)); } else { throw new IllegalStateException(getMethodValue() + " doesn't support a body"); } }  @Nonnull @SuppressWarnings("WeakerAccess") // TODO(Spring 5) @Override String getMethodValue(); HttpMethod getMethod(); @Nonnull @Override URI getURI(); @Nonnull @Override HttpHeaders getHeaders(); @Nonnull @Override OutputStream getBody(); @Override void setBody(final Body body); @Override ClientHttpResponse execute();  }
@Test void shouldUseStreamingEntity() { final HttpClient client = mock(HttpClient.class); final HttpPost request = new HttpPost(); final StreamingApacheClientHttpRequest unit = new StreamingApacheClientHttpRequest(client, request); unit.setBody(mock(Body.class)); final HttpEntity entity = request.getEntity(); assertFalse(entity.isStreaming()); assertThrows(UnsupportedOperationException.class, entity::getContent); assertThrows(UnsupportedOperationException.class, entity::consumeContent); }
@Test void shouldFailOnNonBodyRequests() { final HttpClient client = mock(HttpClient.class); final StreamingHttpOutputMessage unit = new StreamingApacheClientHttpRequest(client, new HttpDelete()); assertThrows(IllegalStateException.class, () -> unit.setBody(mock(Body.class))); }