Skip to content

Commit

Permalink
[DUBBO-3243] Fix Invalid use of BasicClientConnManager: connection st…
Browse files Browse the repository at this point in the history
…ill allocated #3243 (#3581)
  • Loading branch information
CrazyHZM authored and ralf0131 committed Mar 7, 2019
1 parent c528d56 commit ef2cae1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ protected <T> T doRefer(Class<T> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit ef2cae1

Please sign in to comment.