diff --git a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java index 9733307d629..b0e4a8202d0 100644 --- a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java +++ b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HessianProtocol.java @@ -109,7 +109,9 @@ protected T doRefer(Class serviceType, URL url) throws RpcException { hessianProxyFactory.setOverloadEnabled(isOverloadEnabled); String client = url.getParameter(Constants.CLIENT_KEY, Constants.DEFAULT_HTTP_CLIENT); if ("httpclient".equals(client)) { - hessianProxyFactory.setConnectionFactory(new HttpClientConnectionFactory()); + HessianConnectionFactory factory = new HttpClientConnectionFactory(); + factory.setHessianProxyFactory(hessianProxyFactory); + hessianProxyFactory.setConnectionFactory(factory); } else if (client != null && client.length() > 0 && !Constants.DEFAULT_HTTP_CLIENT.equals(client)) { throw new IllegalStateException("Unsupported http protocol client=\"" + client + "\"!"); } else { diff --git a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HttpClientConnectionFactory.java b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HttpClientConnectionFactory.java index b19cd275c8a..44e0ebd7c3a 100644 --- a/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HttpClientConnectionFactory.java +++ b/dubbo-rpc/dubbo-rpc-hessian/src/main/java/com/alibaba/dubbo/rpc/protocol/hessian/HttpClientConnectionFactory.java @@ -22,8 +22,8 @@ import com.caucho.hessian.client.HessianConnectionFactory; import com.caucho.hessian.client.HessianProxyFactory; import org.apache.http.client.HttpClient; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.params.HttpConnectionParams; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.impl.client.HttpClientBuilder; import java.io.IOException; import java.net.URL; @@ -33,12 +33,15 @@ */ public class HttpClientConnectionFactory implements HessianConnectionFactory { - private final HttpClient httpClient = new DefaultHttpClient(); + private HttpClient httpClient; @Override public void setHessianProxyFactory(HessianProxyFactory factory) { - HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), (int) factory.getConnectTimeout()); - HttpConnectionParams.setSoTimeout(httpClient.getParams(), (int) factory.getReadTimeout()); + RequestConfig requestConfig = RequestConfig.custom() + .setConnectionRequestTimeout((int) factory.getConnectTimeout()) + .setSocketTimeout((int) factory.getReadTimeout()) + .build(); + httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build(); } @Override