Skip to content
Browse files

httpclient 3.x to httpclient 4.x

  • Loading branch information...
1 parent e22c162 commit c1efb918169a018f6ea8240710fc053a61b5f04e @akkumar akkumar committed Dec 30, 2011
View
5 .classpath
@@ -14,11 +14,9 @@
<classpathentry kind="src" path="contrib/krati/test"/>
<classpathentry kind="src" path="contrib/collections/src/java"/>
<classpathentry kind="src" path="contrib/collections/test"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/catalina-ant.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
<classpathentry kind="lib" path="lib/commons-dbcp-1.2.2.jar"/>
- <classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="lib/colt-1.2.0.jar"/>
<classpathentry kind="lib" path="contrib/hadoop-store-builder/lib/commons-cli-2.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="contrib/hadoop-store-builder/lib/hadoop-0.20.2-core.jar"/>
@@ -53,5 +51,8 @@
<classpathentry kind="lib" path="lib/compress-lzf-0.9.1.jar"/>
<classpathentry kind="lib" path="lib/snappy-0.2.jar"/>
<classpathentry kind="lib" path="lib/libthrift-0.8.0.jar"/>
+ <classpathentry kind="lib" path="lib/httpclient-4.1.2.jar" sourcepath="/httpclient"/>
+ <classpathentry kind="lib" path="lib/httpcore-4.1.2.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="classes"/>
</classpath>
View
7 .settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Fri Sep 18 15:20:52 BST 2009
+#Fri Dec 30 14:37:10 PST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
@@ -149,9 +149,12 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
-org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
View
1 build.xml
@@ -193,7 +193,6 @@
<src path="${contrib.root.dir}" />
<classpath refid="main-classpath" />
<classpath refid="contrib-classpath" />
- <bootclasspath refid="bootref-classpath" />
</javac>
<copy todir="${contrib.classes.dir}">
<fileset dir="${contrib.root.dir}/ec2-testing/resources" />
View
BIN lib/commons-httpclient-3.1.jar
Binary file not shown.
View
BIN lib/httpclient-4.1.2.jar
Binary file not shown.
View
BIN lib/httpcore-4.1.2.jar
Binary file not shown.
View
55 src/java/voldemort/client/HttpStoreClientFactory.java
@@ -22,15 +22,15 @@
import java.util.Collection;
import java.util.concurrent.TimeUnit;
-import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpVersion;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
-import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.params.HttpClientParams;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
import voldemort.client.protocol.RequestFormatFactory;
import voldemort.client.protocol.RequestFormatType;
@@ -55,31 +55,28 @@
private static final String VOLDEMORT_USER_AGENT = "vldmrt/0.01";
- private final HttpClient httpClient;
+ private final DefaultHttpClient httpClient;
private final RequestFormatFactory requestFormatFactory;
private final boolean reroute;
public HttpStoreClientFactory(ClientConfig config) {
super(config);
- HostConfiguration hostConfig = new HostConfiguration();
- hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
- MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
- this.httpClient = new HttpClient(connectionManager);
- this.httpClient.setHostConfiguration(hostConfig);
- HttpClientParams clientParams = this.httpClient.getParams();
- clientParams.setConnectionManagerTimeout(config.getConnectionTimeout(TimeUnit.MILLISECONDS));
- clientParams.setSoTimeout(config.getSocketTimeout(TimeUnit.MILLISECONDS));
- clientParams.setParameter(HttpMethodParams.RETRY_HANDLER,
- new DefaultHttpMethodRetryHandler(0, false));
- clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
- clientParams.setParameter("http.useragent", VOLDEMORT_USER_AGENT);
- HttpConnectionManagerParams managerParams = this.httpClient.getHttpConnectionManager()
- .getParams();
- managerParams.setConnectionTimeout(config.getConnectionTimeout(TimeUnit.MILLISECONDS));
- managerParams.setMaxTotalConnections(config.getMaxTotalConnections());
- managerParams.setStaleCheckingEnabled(false);
- managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(),
- config.getMaxConnectionsPerNode());
+ ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager();
+ mgr.setMaxTotal(config.getMaxTotalConnections());
+ mgr.setDefaultMaxPerRoute(config.getMaxConnectionsPerNode());
+
+ this.httpClient = new DefaultHttpClient(mgr);
+ HttpParams clientParams = this.httpClient.getParams();
+ clientParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
+ HttpConnectionParams.setConnectionTimeout(clientParams,
+ config.getConnectionTimeout(TimeUnit.MILLISECONDS));
+ HttpConnectionParams.setSoTimeout(clientParams,
+ config.getSocketTimeout(TimeUnit.MILLISECONDS));
+ this.httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
+ HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
+ clientParams.setParameter(CoreProtocolPNames.USER_AGENT, VOLDEMORT_USER_AGENT);
+ HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
+
this.reroute = config.getRoutingTier().equals(RoutingTier.SERVER);
this.requestFormatFactory = new RequestFormatFactory();
}
View
58 src/java/voldemort/store/http/HttpStore.java
@@ -24,10 +24,10 @@
import java.util.List;
import java.util.Map;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
-import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ByteArrayEntity;
import voldemort.VoldemortException;
import voldemort.client.protocol.RequestFormat;
@@ -70,9 +70,9 @@ public HttpStore(String storeName,
public boolean delete(ByteArray key, Version version) throws VoldemortException {
StoreUtils.assertValidKey(key);
- PostMethod method = null;
+ HttpPost method = null;
try {
- method = new PostMethod(this.storeUrl);
+ method = new HttpPost(this.storeUrl);
ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
requestFormat.writeDeleteRequest(new DataOutputStream(outputBytes),
storeName,
@@ -84,17 +84,14 @@ public boolean delete(ByteArray key, Version version) throws VoldemortException
} catch(IOException e) {
throw new UnreachableStoreException("Could not connect to " + storeUrl + " for "
+ storeName, e);
- } finally {
- if(method != null)
- method.releaseConnection();
}
}
public List<Versioned<byte[]>> get(ByteArray key, byte[] transforms) throws VoldemortException {
StoreUtils.assertValidKey(key);
- PostMethod method = null;
+ HttpPost method = null;
try {
- method = new PostMethod(this.storeUrl);
+ method = new HttpPost(this.storeUrl);
ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
requestFormat.writeGetRequest(new DataOutputStream(outputBytes),
storeName,
@@ -106,19 +103,16 @@ public boolean delete(ByteArray key, Version version) throws VoldemortException
} catch(IOException e) {
throw new UnreachableStoreException("Could not connect to " + storeUrl + " for "
+ storeName, e);
- } finally {
- if(method != null)
- method.releaseConnection();
}
}
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys,
Map<ByteArray, byte[]> transforms)
throws VoldemortException {
StoreUtils.assertValidKeys(keys);
- PostMethod method = null;
+ HttpPost method = null;
try {
- method = new PostMethod(this.storeUrl);
+ method = new HttpPost(this.storeUrl);
ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
requestFormat.writeGetAllRequest(new DataOutputStream(outputBytes),
storeName,
@@ -130,18 +124,15 @@ public boolean delete(ByteArray key, Version version) throws VoldemortException
} catch(IOException e) {
throw new UnreachableStoreException("Could not connect to " + storeUrl + " for "
+ storeName, e);
- } finally {
- if(method != null)
- method.releaseConnection();
}
}
public void put(ByteArray key, Versioned<byte[]> versioned, byte[] transforms)
throws VoldemortException {
StoreUtils.assertValidKey(key);
- PostMethod method = null;
+ HttpPost method = null;
try {
- method = new PostMethod(this.storeUrl);
+ method = new HttpPost(this.storeUrl);
ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
requestFormat.writePutRequest(new DataOutputStream(outputBytes),
storeName,
@@ -155,23 +146,19 @@ public void put(ByteArray key, Versioned<byte[]> versioned, byte[] transforms)
} catch(IOException e) {
throw new UnreachableStoreException("Could not connect to " + storeUrl + " for "
+ storeName, e);
- } finally {
- if(method != null)
- method.releaseConnection();
}
}
- private DataInputStream executeRequest(PostMethod method, ByteArrayOutputStream output) {
+ private DataInputStream executeRequest(HttpPost method, ByteArrayOutputStream output) {
try {
- method.setRequestEntity(new ByteArrayRequestEntity(output.toByteArray()));
- int response = httpClient.executeMethod(method);
- if(response != HttpURLConnection.HTTP_OK)
+ method.setEntity(new ByteArrayEntity(output.toByteArray()));
+ HttpResponse response = httpClient.execute(method);
+ int statusCode = response.getStatusLine().getStatusCode();
+ if(statusCode != HttpURLConnection.HTTP_OK)
throw new UnreachableStoreException("HTTP request to store " + storeName
+ " returned status code " + response + " "
- + method.getStatusText());
- return new DataInputStream(method.getResponseBodyAsStream());
- } catch(HttpException e) {
- throw new VoldemortException(e);
+ + response.getStatusLine().getReasonPhrase());
+ return new DataInputStream(response.getEntity().getContent());
} catch(IOException e) {
throw new UnreachableStoreException("Could not connect to " + storeUrl + " for "
+ storeName, e);
@@ -190,9 +177,9 @@ public Object getCapability(StoreCapabilityType capability) {
public List<Version> getVersions(ByteArray key) {
StoreUtils.assertValidKey(key);
- PostMethod method = null;
+ HttpPost method = null;
try {
- method = new PostMethod(this.storeUrl);
+ method = new HttpPost(this.storeUrl);
ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
requestFormat.writeGetVersionRequest(new DataOutputStream(outputBytes),
storeName,
@@ -203,9 +190,6 @@ public Object getCapability(StoreCapabilityType capability) {
} catch(IOException e) {
throw new UnreachableStoreException("Could not connect to " + storeUrl + " for "
+ storeName, e);
- } finally {
- if(method != null)
- method.releaseConnection();
}
}
}
View
98 src/java/voldemort/store/readonly/swapper/HttpStoreSwapper.java
@@ -9,8 +9,11 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.params.HttpParams;
import org.apache.log4j.Logger;
import voldemort.VoldemortException;
@@ -64,22 +67,31 @@ public HttpStoreSwapper(Cluster cluster,
public String call() throws Exception {
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
- PostMethod post = new PostMethod(url);
- post.addParameter("operation", "fetch");
+ HttpPost post = new HttpPost(url);
+ HttpParams params = post.getParams();
+ params.setParameter("operation", "fetch");
String storeDir = basePath + "/node-" + node.getId();
- post.addParameter("dir", storeDir);
- post.addParameter("store", storeName);
+ params.setParameter("dir", storeDir);
+ params.setParameter("store", storeName);
if(pushVersion > 0)
- post.addParameter("pushVersion", Long.toString(pushVersion));
+ params.setParameter("pushVersion", Long.toString(pushVersion));
logger.info("Invoking fetch for node " + node.getId() + " for " + storeDir);
- int responseCode = httpClient.executeMethod(post);
- String response = post.getResponseBodyAsString(30000);
+ HttpResponse httpResponse = httpClient.execute(post);
+ int responseCode = httpResponse.getStatusLine().getStatusCode();
+ String response = IOUtils.toString(httpResponse.getEntity().getContent());
+ // TODO: clip response to 30K .
+ // post.getResponseBodyAsString(30000);
if(responseCode != 200)
- throw new VoldemortException("Fetch request on node " + node.getId() + " ("
- + url + ") failed: " + post.getStatusText());
+ throw new VoldemortException("Fetch request on node "
+ + node.getId()
+ + " ("
+ + url
+ + ") failed: "
+ + httpResponse.getStatusLine()
+ .getReasonPhrase());
logger.info("Fetch succeeded on node " + node.getId());
return response.trim();
}
@@ -107,14 +119,16 @@ public String call() throws Exception {
try {
String url = cluster.getNodeById(successfulNodeId).getHttpUrl() + "/"
+ readOnlyMgmtPath;
- PostMethod post = new PostMethod(url);
- post.addParameter("operation", "failed-fetch");
- post.addParameter("dir", results.get(successfulNodeId));
- post.addParameter("store", storeName);
+ HttpPost post = new HttpPost(url);
+ HttpParams params = post.getParams();
+ params.setParameter("operation", "failed-fetch");
+ params.setParameter("dir", results.get(successfulNodeId));
+ params.setParameter("store", storeName);
logger.info("Deleting fetched data from node " + successfulNodeId);
- int responseCode = httpClient.executeMethod(post);
- String response = post.getStatusText();
+ HttpResponse httpResponse = httpClient.execute(post);
+ int responseCode = httpResponse.getStatusLine().getStatusCode();
+ String response = httpResponse.getStatusLine().getReasonPhrase();
if(responseCode == 200) {
logger.info("Deleted successfully on node " + successfulNodeId);
@@ -150,19 +164,24 @@ public void invokeSwap(final String storeName, final List<String> fetchFiles) {
for(final Node node: cluster.getNodes()) {
try {
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
- PostMethod post = new PostMethod(url);
- post.addParameter("operation", "swap");
+ HttpPost post = new HttpPost(url);
+ HttpParams params = post.getParams();
+ params.setParameter("operation", "swap");
String dir = fetchFiles.get(node.getId());
logger.info("Attempting swap for node " + node.getId() + " dir = " + dir);
- post.addParameter("dir", dir);
- post.addParameter("store", storeName);
+ params.setParameter("dir", dir);
+ params.setParameter("store", storeName);
- int responseCode = httpClient.executeMethod(post);
- String previousDir = post.getResponseBodyAsString(30000);
+ HttpResponse httpResponse = httpClient.execute(post);
+ int responseCode = httpResponse.getStatusLine().getStatusCode();
+ String previousDir = IOUtils.toString(httpResponse.getEntity().getContent());
+ // TODO: clip response to 30K .
+ // post.getResponseBodyAsString(30000);
if(responseCode != 200)
throw new VoldemortException("Swap request on node " + node.getId() + " ("
- + url + ") failed: " + post.getStatusText());
+ + url + ") failed: "
+ + httpResponse.getStatusLine().getReasonPhrase());
logger.info("Swap succeeded on node " + node.getId());
previousDirs.put(node.getId(), previousDir);
} catch(Exception e) {
@@ -179,16 +198,18 @@ public void invokeSwap(final String storeName, final List<String> fetchFiles) {
try {
String url = cluster.getNodeById(successfulNodeId).getHttpUrl() + "/"
+ readOnlyMgmtPath;
- PostMethod post = new PostMethod(url);
- post.addParameter("operation", "rollback");
- post.addParameter("store", storeName);
- post.addParameter("pushVersion",
- Long.toString(ReadOnlyUtils.getVersionId(new File(previousDirs.get(successfulNodeId)))));
+ HttpPost post = new HttpPost(url);
+ HttpParams params = post.getParams();
+ params.setParameter("operation", "rollback");
+ params.setParameter("store", storeName);
+ params.setParameter("pushVersion",
+ Long.toString(ReadOnlyUtils.getVersionId(new File(previousDirs.get(successfulNodeId)))));
logger.info("Rolling back data on successful node " + successfulNodeId);
- int responseCode = httpClient.executeMethod(post);
- String response = post.getStatusText();
+ HttpResponse httpResponse = httpClient.execute(post);
+ int responseCode = httpResponse.getStatusLine().getStatusCode();
+ String response = httpResponse.getStatusLine().getReasonPhrase();
if(responseCode == 200) {
logger.info("Rollback succeeded for node " + successfulNodeId);
@@ -223,13 +244,16 @@ public void invokeRollback(String storeName, final long pushVersion) {
logger.info("Attempting rollback for node " + node.getId() + " storeName = "
+ storeName);
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
- PostMethod post = new PostMethod(url);
- post.addParameter("operation", "rollback");
- post.addParameter("store", storeName);
- post.addParameter("pushVersion", Long.toString(pushVersion));
+ HttpPost post = new HttpPost(url);
+ HttpParams params = post.getParams();
- int responseCode = httpClient.executeMethod(post);
- String response = post.getStatusText();
+ params.setParameter("operation", "rollback");
+ params.setParameter("store", storeName);
+ params.setParameter("pushVersion", Long.toString(pushVersion));
+
+ HttpResponse httpResponse = httpClient.execute(post);
+ int responseCode = httpResponse.getStatusLine().getStatusCode();
+ String response = httpResponse.getStatusLine().getReasonPhrase();
if(responseCode == 200) {
logger.info("Rollback succeeded for node " + node.getId());
} else {
View
28 src/java/voldemort/store/readonly/swapper/StoreSwapper.java
@@ -11,11 +11,12 @@
import joptsimple.OptionParser;
import joptsimple.OptionSet;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpConnectionManager;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.io.FileUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
import org.apache.log4j.Logger;
import voldemort.client.protocol.admin.AdminClient;
@@ -31,8 +32,8 @@
/**
* A helper class to invoke the FETCH and SWAP operations on a remote store via
* HTTP.
- *
- *
+ *
+ *
*/
public abstract class StoreSwapper {
@@ -119,14 +120,15 @@ public static void main(String[] args) throws Exception {
adminClient = new AdminClient(cluster, new AdminClientConfig());
swapper = new AdminStoreSwapper(cluster, executor, adminClient, timeoutMs);
} else {
- HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
-
int numConnections = cluster.getNumberOfNodes() + 3;
- manager.getParams().setMaxTotalConnections(numConnections);
- manager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION,
- numConnections);
- HttpClient client = new HttpClient(manager);
- client.getParams().setParameter("http.socket.timeout", timeoutMs);
+ ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager();
+ DefaultHttpClient client = new DefaultHttpClient(connectionManager);
+
+ HttpParams clientParams = client.getParams();
+
+ connectionManager.setMaxTotal(numConnections);
+ connectionManager.setDefaultMaxPerRoute(numConnections);
+ HttpConnectionParams.setSoTimeout(clientParams, timeoutMs);
swapper = new HttpStoreSwapper(cluster, executor, client, mgmtPath);
}
View
4 test/common/voldemort/ServerTestUtils.java
@@ -31,8 +31,8 @@
import java.util.Properties;
import java.util.Set;
-import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.io.FileUtils;
+import org.apache.http.impl.client.DefaultHttpClient;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
@@ -214,7 +214,7 @@ public static HttpStore getHttpStore(String storeName, RequestFormatType format,
return new HttpStore(storeName,
"localhost",
port,
- new HttpClient(),
+ new DefaultHttpClient(),
new RequestFormatFactory().getRequestFormat(format),
false);
}
View
74 test/integration/voldemort/performance/HttpClientBench.java
@@ -16,17 +16,19 @@
package voldemort.performance;
-import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpConnectionManager;
-import org.apache.commons.httpclient.HttpVersion;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
-import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.params.HttpClientParams;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
public class HttpClientBench {
@@ -52,14 +54,12 @@ public static void main(String[] args) throws Exception {
@Override
public void doOperation(int index) {
- GetMethod get = new GetMethod(url);
+ HttpGet get = new HttpGet(url);
try {
- client.executeMethod(get);
- get.getResponseBody();
+ HttpResponse response = client.execute(get);
+ response.getEntity().consumeContent();
} catch(Exception e) {
e.printStackTrace();
- } finally {
- get.releaseConnection();
}
}
};
@@ -70,28 +70,28 @@ public void doOperation(int index) {
}
private static HttpClient createClient() {
- HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
- HttpClient httpClient = new HttpClient(connectionManager);
- HttpClientParams clientParams = httpClient.getParams();
- clientParams.setConnectionManagerTimeout(DEFAULT_CONNECTION_MANAGER_TIMEOUT);
- clientParams.setSoTimeout(500);
- clientParams.setParameter(HttpMethodParams.RETRY_HANDLER,
- new DefaultHttpMethodRetryHandler(0, false));
- clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
- clientParams.setBooleanParameter("http.tcp.nodelay", false);
+ ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager();
+ DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
+
+ HttpParams clientParams = httpClient.getParams();
+
+ clientParams.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, false);
+
clientParams.setIntParameter("http.socket.receivebuffer", 60000);
- clientParams.setParameter("http.useragent", VOLDEMORT_USER_AGENT);
- HostConfiguration hostConfig = new HostConfiguration();
- hostConfig.setHost("localhost");
- hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
- httpClient.setHostConfiguration(hostConfig);
- HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager()
- .getParams();
- managerParams.setConnectionTimeout(DEFAULT_CONNECTION_MANAGER_TIMEOUT);
- managerParams.setMaxTotalConnections(DEFAULT_MAX_CONNECTIONS);
- managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(),
- DEFAULT_MAX_HOST_CONNECTIONS);
- managerParams.setStaleCheckingEnabled(false);
+ clientParams.setParameter(CoreProtocolPNames.USER_AGENT, VOLDEMORT_USER_AGENT);
+ // HostConfiguration hostConfig = new HostConfiguration();
+ // hostConfig.setHost("localhost");
+
+ clientParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
+
+ HttpConnectionParams.setConnectionTimeout(clientParams, DEFAULT_CONNECTION_MANAGER_TIMEOUT);
+ HttpConnectionParams.setSoTimeout(clientParams, 500);
+ httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
+ HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
+
+ connectionManager.setMaxTotal(DEFAULT_MAX_CONNECTIONS);
+ connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_HOST_CONNECTIONS);
+ HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
return httpClient;
}
View
48 test/integration/voldemort/performance/RemoteStoreComparisonTest.java
@@ -16,15 +16,15 @@
package voldemort.performance;
-import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpVersion;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.cookie.CookiePolicy;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
-import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.params.HttpClientParams;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
import voldemort.ServerTestUtils;
import voldemort.TestUtils;
@@ -154,21 +154,21 @@ public void doOperation(int i) {
numThreads,
8080);
httpService.start();
- HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
- HttpClientParams clientParams = httpClient.getParams();
- clientParams.setParameter(HttpMethodParams.RETRY_HANDLER,
- new DefaultHttpMethodRetryHandler(0, false));
- clientParams.setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
- clientParams.setParameter("http.useragent", "test-agent");
- HostConfiguration hostConfig = new HostConfiguration();
- hostConfig.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
- httpClient.setHostConfiguration(hostConfig);
- HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager()
- .getParams();
- managerParams.setConnectionTimeout(10000);
- managerParams.setMaxTotalConnections(numThreads);
- managerParams.setStaleCheckingEnabled(false);
- managerParams.setMaxConnectionsPerHost(httpClient.getHostConfiguration(), numThreads);
+
+ ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager();
+ DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
+
+ HttpParams clientParams = httpClient.getParams();
+ httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false));
+ HttpClientParams.setCookiePolicy(clientParams, CookiePolicy.IGNORE_COOKIES);
+ clientParams.setParameter(CoreProtocolPNames.USER_AGENT, "test-agent");
+ clientParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
+ HttpConnectionParams.setConnectionTimeout(clientParams, 10000);
+
+ connectionManager.setMaxTotal(numThreads);
+ connectionManager.setDefaultMaxPerRoute(numThreads);
+ HttpConnectionParams.setStaleCheckingEnabled(clientParams, false);
+
final HttpStore httpStore = new HttpStore("test",
"localhost",
8080,
View
14 test/unit/voldemort/store/http/HttpStoreTest.java
@@ -16,7 +16,10 @@
package voldemort.store.http;
-import org.apache.commons.httpclient.HttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
@@ -65,8 +68,13 @@ public void setUp() throws Exception {
public <T extends Exception> void testBadUrlOrPort(String url, int port, Class<T> expected) {
ByteArray key = new ByteArray("test".getBytes());
RequestFormat requestFormat = new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V1);
- HttpClient client = new HttpClient();
- client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
+
+ ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager();
+
+ DefaultHttpClient client = new DefaultHttpClient(connectionManager);
+ HttpParams clientParams = client.getParams();
+ HttpConnectionParams.setConnectionTimeout(clientParams, 5000);
+
HttpStore badUrlHttpStore = new HttpStore("test", url, port, client, requestFormat, false);
try {
badUrlHttpStore.put(key,
View
31 test/unit/voldemort/store/readonly/swapper/StoreSwapperTest.java
@@ -27,10 +27,8 @@
import junit.framework.TestCase;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpConnectionManager;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -58,6 +56,7 @@
import com.google.common.collect.Maps;
/**
+*
*/
public class StoreSwapperTest extends TestCase {
@@ -155,11 +154,13 @@ public void testHttpStoreSwapper() throws Exception {
try {
// Use the http store swapper
- HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
- manager.getParams().setMaxTotalConnections(10);
- manager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION,
- 10);
- HttpClient client = new HttpClient(manager);
+ ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager();
+
+ connectionManager.setMaxTotal(10);
+ connectionManager.setDefaultMaxPerRoute(10);
+
+ DefaultHttpClient client = new DefaultHttpClient(connectionManager);
+
StoreSwapper swapper = new HttpStoreSwapper(cluster,
executor,
client,
@@ -196,11 +197,13 @@ public void testHttpStoreSwapperWithoutRollback() throws Exception {
try {
// Use the http store swapper
- HttpConnectionManager manager = new MultiThreadedHttpConnectionManager();
- manager.getParams().setMaxTotalConnections(10);
- manager.getParams().setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION,
- 10);
- HttpClient client = new HttpClient(manager);
+
+ ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager();
+
+ connectionManager.setMaxTotal(10);
+ connectionManager.setDefaultMaxPerRoute(10);
+
+ DefaultHttpClient client = new DefaultHttpClient(connectionManager);
StoreSwapper swapper = new HttpStoreSwapper(cluster,
executor,
client,

0 comments on commit c1efb91

Please sign in to comment.
Something went wrong with that request. Please try again.