You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by rf...@apache.org on 2012/03/30 18:47:19 UTC
svn commit: r1307529 - in
/incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client:
ApacheHttpClientConfig.java
internal/handlers/ApacheHttpClientConnectionHandler.java
Author: rfeng
Date: Fri Mar 30 16:47:19 2012
New Revision: 1307529
URL: http://svn.apache.org/viewvc?rev=1307529&view=rev
Log:
Apply the patch for https://issues.apache.org/jira/browse/WINK-364. Thanks, Seshu.
Modified:
incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/ApacheHttpClientConfig.java
incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/internal/handlers/ApacheHttpClientConnectionHandler.java
Modified: incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/ApacheHttpClientConfig.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/ApacheHttpClientConfig.java?rev=1307529&r1=1307528&r2=1307529&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/ApacheHttpClientConfig.java (original)
+++ incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/ApacheHttpClientConfig.java Fri Mar 30 16:47:19 2012
@@ -46,6 +46,7 @@ import org.apache.wink.client.internal.h
public class ApacheHttpClientConfig extends ClientConfig {
private HttpClient client;
+ private int maxPooledConnections;
public ApacheHttpClientConfig() {
client = null;
@@ -60,4 +61,11 @@ public class ApacheHttpClientConfig exte
return new ApacheHttpClientConnectionHandler(client);
}
+ public void setMaxPooledConnections(int maxPooledConnections) {
+ this.maxPooledConnections = maxPooledConnections;
+ }
+
+ public int getMaxPooledConnections() {
+ return maxPooledConnections;
+ }
}
Modified: incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/internal/handlers/ApacheHttpClientConnectionHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/internal/handlers/ApacheHttpClientConnectionHandler.java?rev=1307529&r1=1307528&r2=1307529&view=diff
==============================================================================
--- incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/internal/handlers/ApacheHttpClientConnectionHandler.java (original)
+++ incubator/wink/trunk/wink-client-apache-httpclient/src/main/java/org/apache/wink/client/internal/handlers/ApacheHttpClientConnectionHandler.java Fri Mar 30 16:47:19 2012
@@ -46,12 +46,16 @@ import org.apache.http.client.methods.Ht
import org.apache.http.client.params.ClientPNames;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.SchemeRegistryFactory;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
-import org.apache.wink.client.ClientConfig;
+import org.apache.http.util.EntityUtils;
+import org.apache.wink.client.ApacheHttpClientConfig;
import org.apache.wink.client.ClientRequest;
import org.apache.wink.client.ClientResponse;
import org.apache.wink.client.handlers.HandlerContext;
@@ -99,7 +103,12 @@ public class ApacheHttpClientConnectionH
HttpRequestBase entityRequest = setupHttpRequest(request, client, entityWriter);
- return client.execute(entityRequest);
+ try {
+ return client.execute(entityRequest);
+ } catch (Exception ex) {
+ entityRequest.abort();
+ throw new RuntimeException(ex);
+ }
}
private HttpRequestBase setupHttpRequest(ClientRequest request,
@@ -133,13 +142,13 @@ public class ApacheHttpClientConnectionH
return httpRequest;
}
- private HttpClient openConnection(ClientRequest request) throws NoSuchAlgorithmException, KeyManagementException {
+ private synchronized HttpClient openConnection(ClientRequest request) throws NoSuchAlgorithmException, KeyManagementException {
if (this.httpclient != null) {
return this.httpclient;
}
// cast is safe because we're on the client
- ClientConfig config = (ClientConfig)request.getAttribute(WinkConfiguration.class);
+ ApacheHttpClientConfig config = (ApacheHttpClientConfig)request.getAttribute(WinkConfiguration.class);
BasicHttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.valueOf(config
.getConnectTimeout()));
@@ -156,14 +165,23 @@ public class ApacheHttpClientConnectionH
config.getProxyPort()));
}
- this.httpclient = new DefaultHttpClient(params);
+ if (config.getMaxPooledConnections() > 0) {
+ SchemeRegistry schemeRegistry = SchemeRegistryFactory.createDefault();
+ ThreadSafeClientConnManager httpConnectionManager = new ThreadSafeClientConnManager(schemeRegistry);
+
+ httpConnectionManager.setMaxTotal(config.getMaxPooledConnections());
+ httpConnectionManager.setDefaultMaxPerRoute(config.getMaxPooledConnections());
+
+ this.httpclient = new DefaultHttpClient(httpConnectionManager, params);
+ } else {
+ this.httpclient = new DefaultHttpClient(params);
+ }
if (config.getBypassHostnameVerification()) {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, null, null);
- SSLSocketFactory sf = new SSLSocketFactory(sslcontext);
- sf.setHostnameVerifier(new X509HostnameVerifier() {
+ SSLSocketFactory sf = new SSLSocketFactory(sslcontext, new X509HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
@@ -179,10 +197,10 @@ public class ApacheHttpClientConnectionH
public void verify(String host, SSLSocket ssl) throws IOException {
}
});
- httpclient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", sf,
- 443));
+ httpclient.getConnectionManager().getSchemeRegistry().register(new Scheme("https", 443, sf));
}
- return httpclient;
+
+ return this.httpclient;
}
/**
@@ -225,7 +243,7 @@ public class ApacheHttpClientConnectionH
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
try {
- entity.consumeContent();
+ EntityUtils.consume(entity);
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -324,6 +342,7 @@ public class ApacheHttpClientConnectionH
this.ncos = ncos;
}
+ @Deprecated
public void consumeContent() throws IOException {
}