Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 0f5b3a9d9 -> b61f6ddd9
[CXF-7478] Response stream can not be auto-closed if it is read implicitly Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/b61f6ddd Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b61f6ddd Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b61f6ddd Branch: refs/heads/3.0.x-fixes Commit: b61f6ddd988f5eac40e1eb14b031826a1ee32d9c Parents: 0f5b3a9 Author: Sergey Beryozkin <[email protected]> Authored: Thu Aug 17 09:49:52 2017 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Thu Aug 17 10:20:08 2017 +0100 ---------------------------------------------------------------------- .../src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java | 8 +++++++- .../src/main/java/org/apache/cxf/jaxrs/client/WebClient.java | 6 +++--- .../apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/b61f6ddd/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java index d68b35b..704ed02 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java @@ -1725,8 +1725,14 @@ public final class JAXRSUtils { } public static ResponseBuilder fromResponse(Response response) { + return fromResponse(response, true); + } + + public static ResponseBuilder fromResponse(Response response, boolean copyEntity) { ResponseBuilder rb = toResponseBuilder(response.getStatus()); - rb.entity(response.getEntity()); + if (copyEntity) { + rb.entity(response.getEntity()); + } for (Map.Entry<String, List<Object>> entry : response.getMetadata().entrySet()) { List<Object> values = entry.getValue(); for (Object value : values) { http://git-wip-us.apache.org/repos/asf/cxf/blob/b61f6ddd/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java ---------------------------------------------------------------------- diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java index 3bef610..64b0145 100644 --- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java +++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java @@ -1194,9 +1194,9 @@ public class WebClient extends AbstractClient { entity = currentResponse.getEntity(); } } - rb = JAXRSUtils.fromResponse(currentResponse); - - rb.entity(entity instanceof Response + rb = JAXRSUtils.fromResponse(currentResponse, false); + + rb.entity(entity instanceof Response ? ((Response)entity).getEntity() : entity); Response r = rb.build(); http://git-wip-us.apache.org/repos/asf/cxf/blob/b61f6ddd/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java index 3c52760..9d492a3 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java @@ -114,7 +114,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase { // and this property is not already set. The async conduit is loaded in the tests module // but we do want to test HTTPUrlConnection reflection hence we set this property to false WebClient.getConfig(wc).getRequestContext().put("use.async.http.conduit", false); - + WebClient.getConfig(wc).getRequestContext().put("response.stream.auto.close", true); return wc.invoke("RETRIEVE", new Book("Retrieve", 123L), Book.class); }
