Repository: cxf Updated Branches: refs/heads/master dbc4de183 -> fea260561
Making it simpler to enable auto-closing for JAX-RS 2.0 clients Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/fea26056 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fea26056 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fea26056 Branch: refs/heads/master Commit: fea26056139ac2b4ab991681a35c5c8a20366aba Parents: dbc4de1 Author: Sergey Beryozkin <[email protected]> Authored: Tue Aug 11 15:58:41 2015 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Tue Aug 11 15:58:41 2015 +0100 ---------------------------------------------------------------------- .../apache/cxf/jaxrs/client/spec/ClientImpl.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/fea26056/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java ---------------------------------------------------------------------- diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java index b15d730..52e900f 100644 --- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java +++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java @@ -39,7 +39,6 @@ import javax.ws.rs.core.Link; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; -import org.apache.cxf.common.util.PropertyUtils; import org.apache.cxf.configuration.jsse.TLSClientParameters; import org.apache.cxf.jaxrs.client.ClientConfiguration; import org.apache.cxf.jaxrs.client.ClientProviderFactory; @@ -54,6 +53,7 @@ public class ClientImpl implements Client { private static final String HTTP_PROXY_SERVER_PROP = "http.proxy.server.uri"; private static final String HTTP_PROXY_SERVER_PORT_PROP = "http.proxy.server.port"; private static final String HTTP_AUTOREDIRECT_PROP = "http.autoredirect"; + private static final String HTTP_RESPONSE_AUTOCLOSE_PROP = "http.response.stream.auto.close"; private Configurable<Client> configImpl; private TLSConfiguration secConfig; @@ -273,6 +273,12 @@ public class ClientImpl implements Client { clientCfg.getRequestContext().put(Client.class.getName(), ClientImpl.this); clientCfg.getRequestContext().put(Configuration.class.getName(), getConfiguration()); + + // Response auto-close + Boolean responseAutoClose = getBooleanValue(configProps.get(HTTP_RESPONSE_AUTOCLOSE_PROP)); + if (responseAutoClose != null) { + clientCfg.getResponseContext().put("response.stream.auto.close", responseAutoClose); + } // TLS TLSClientParameters tlsParams = secConfig.getTlsClientParams(); if (tlsParams.getSSLSocketFactory() != null @@ -305,9 +311,9 @@ public class ClientImpl implements Client { if (proxyServerPortValue != null) { clientCfg.getHttpConduit().getClient().setProxyServerPort(proxyServerPortValue); } - Object autoRedirectValue = configProps.get(HTTP_AUTOREDIRECT_PROP); - if (PropertyUtils.isTrue(autoRedirectValue)) { - clientCfg.getHttpConduit().getClient().setAutoRedirect(true); + Boolean autoRedirectValue = getBooleanValue(configProps.get(HTTP_AUTOREDIRECT_PROP)); + if (autoRedirectValue != null) { + clientCfg.getHttpConduit().getClient().setAutoRedirect(autoRedirectValue); } } @@ -386,7 +392,7 @@ public class ClientImpl implements Client { checkNull(name, value); return newWebTarget(getUriBuilder().resolveTemplate(name, value, encodeSlash)); } - + @Override public WebTarget resolveTemplateFromEncoded(String name, Object value) { checkNull(name, value); @@ -514,4 +520,7 @@ public class ClientImpl implements Client { private static Integer getIntValue(Object o) { return o instanceof Integer ? (Integer)o : o instanceof String ? Integer.valueOf(o.toString()) : null; } + private static Boolean getBooleanValue(Object o) { + return o instanceof Boolean ? (Boolean)o : o instanceof Boolean ? Boolean.valueOf(o.toString()) : null; + } }
