mirror of https://github.com/apache/jclouds.git
Issue 107: added proxy support, timeout parameters, and refactored ssl module
This commit is contained in:
parent
268bc2ec04
commit
7228d2ea04
|
@ -21,10 +21,9 @@ package org.jclouds.aws.ec2.config;
|
|||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.aws.ec2.EC2AsyncClient;
|
||||
import org.jclouds.aws.ec2.EC2Client;
|
||||
import org.jclouds.aws.ec2.reference.EC2Constants;
|
||||
import org.jclouds.aws.ec2.EC2PropertiesBuilder;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
import org.jclouds.logging.jdk.config.JDKLoggingModule;
|
||||
|
@ -52,22 +51,8 @@ public class EC2ContextModuleTest {
|
|||
new EC2ContextModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(EC2Constants.PROPERTY_AWS_ACCESSKEYID)).to("user");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(EC2Constants.PROPERTY_AWS_SECRETACCESSKEY)).to("key");
|
||||
bindConstant().annotatedWith(Jsr330.named(EC2Constants.PROPERTY_EC2_ENDPOINT))
|
||||
.to("http://localhost");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(EC2Constants.PROPERTY_AWS_EXPIREINTERVAL)).to(30);
|
||||
Jsr330.bindProperties(this.binder(), new EC2PropertiesBuilder("user", "key")
|
||||
.build());
|
||||
super.configure();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -66,6 +66,11 @@
|
|||
<artifactId>jets3t</artifactId>
|
||||
<version>0.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-enterprise</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-httpnio</artifactId>
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.aws.s3;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT;
|
||||
import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS;
|
||||
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT;
|
||||
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST;
|
||||
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
|
||||
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jclouds.enterprise.config.EnterpriseConfigurationModule;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.testng.ITestContext;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test(sequential = true, testName = "perftest.JCloudsNioPerformanceLiveTest", groups = { "live" })
|
||||
public class JCloudsEnterprisePerformanceLiveTest extends BaseJCloudsPerformanceLiveTest {
|
||||
|
||||
@Override
|
||||
@BeforeClass(groups = { "integration", "live" })
|
||||
public void setUpResourcesOnThisThread(ITestContext testContext) throws Exception {
|
||||
exec = Executors.newCachedThreadPool();
|
||||
String accesskeyid = System.getProperty("jclouds.test.user");
|
||||
String secretkey = System.getProperty("jclouds.test.key");
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(PROPERTY_SO_TIMEOUT, 5000 + "");
|
||||
overrides.setProperty(PROPERTY_CONNECTION_TIMEOUT, 5000 + "");
|
||||
overrides.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + "");
|
||||
overrides.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + "");
|
||||
overrides.setProperty(PROPERTY_IO_WORKER_THREADS, 50 + "");
|
||||
overrides.setProperty(PROPERTY_USER_THREADS, 0 + "");
|
||||
String contextName = "enterprise";
|
||||
overrideWithSysPropertiesAndPrint(overrides, contextName);
|
||||
context = S3ContextFactory.createContext(overrides, accesskeyid, secretkey,
|
||||
new NullLoggingModule(), new EnterpriseConfigurationModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
public S3AsyncClient getApi() {
|
||||
return (S3AsyncClient) context.getProviderSpecificContext().getAsyncApi();
|
||||
}
|
||||
}
|
|
@ -27,7 +27,8 @@ import java.util.concurrent.Future;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.enterprise.config.EnterpriseConfigurationModule;
|
||||
import org.jclouds.date.joda.config.JodaDateServiceModule;
|
||||
import org.jclouds.encryption.bouncycastle.config.BouncyCastleEncryptionServiceModule;
|
||||
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.testng.annotations.AfterClass;
|
||||
|
@ -191,8 +192,8 @@ public class JCloudsGaePerformanceLiveTest extends BaseJCloudsPerformanceLiveTes
|
|||
String contextName = "gae";
|
||||
overrideWithSysPropertiesAndPrint(overrides, contextName);
|
||||
this.perfContext = S3ContextFactory.createContext(overrides, accesskeyid, secretkey,
|
||||
new NullLoggingModule(), new EnterpriseConfigurationModule(),
|
||||
new GoogleAppEngineConfigurationModule());
|
||||
new NullLoggingModule(), new BouncyCastleEncryptionServiceModule(),
|
||||
new JodaDateServiceModule(), new GoogleAppEngineConfigurationModule());
|
||||
}
|
||||
|
||||
@AfterClass(groups = { "live" })
|
||||
|
|
|
@ -26,7 +26,8 @@ import static org.jclouds.Constants.PROPERTY_USER_THREADS;
|
|||
import java.util.Properties;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.jclouds.enterprise.config.EnterpriseConfigurationModule;
|
||||
import org.jclouds.date.joda.config.JodaDateServiceModule;
|
||||
import org.jclouds.encryption.bouncycastle.config.BouncyCastleEncryptionServiceModule;
|
||||
import org.jclouds.http.httpnio.config.NioTransformingHttpCommandExecutorServiceModule;
|
||||
import org.jclouds.logging.config.NullLoggingModule;
|
||||
import org.testng.ITestContext;
|
||||
|
@ -50,8 +51,8 @@ public class JCloudsNioPerformanceLiveTest extends BaseJCloudsPerformanceLiveTes
|
|||
String contextName = "nio";
|
||||
overrideWithSysPropertiesAndPrint(overrides, contextName);
|
||||
context = S3ContextFactory.createContext(overrides, accesskeyid, secretkey,
|
||||
new NullLoggingModule(), new EnterpriseConfigurationModule(),
|
||||
new NioTransformingHttpCommandExecutorServiceModule());
|
||||
new NullLoggingModule(), new BouncyCastleEncryptionServiceModule(),
|
||||
new JodaDateServiceModule(), new NioTransformingHttpCommandExecutorServiceModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.util.Map;
|
|||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.azure.storage.AzureBlob;
|
||||
import org.jclouds.azure.storage.blob.functions.ParseContainerPropertiesFromHeaders;
|
||||
import org.jclouds.azure.storage.blob.functions.ReturnFalseIfContainerAlreadyExists;
|
||||
|
@ -43,9 +42,7 @@ import org.jclouds.azure.storage.options.ListOptions;
|
|||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||
import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
|
||||
import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.encryption.internal.Base64;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
|
@ -366,24 +363,10 @@ public class AzureBlobAsyncClientTest {
|
|||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
Jsr330.bindProperties(this.binder(), new AzureBlobPropertiesBuilder("user", "key")
|
||||
.build());
|
||||
bind(URI.class).annotatedWith(AzureBlob.class).toInstance(
|
||||
URI.create("http://myaccount.blob.core.windows.net"));
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT)).to(
|
||||
"myaccount");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY)).to(
|
||||
Base64.encodeBytes("key".getBytes()));
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX)).to(
|
||||
"x-ms-meta-");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
|
||||
.to("1");
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
|
|
@ -39,9 +39,9 @@ import org.jclouds.azure.storage.queue.options.PutMessageOptions;
|
|||
import org.jclouds.azure.storage.reference.AzureStorageConstants;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.encryption.internal.Base64;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
|
|
|
@ -37,7 +37,7 @@ public interface Constants {
|
|||
* Amount of threads servicing the I/O of http connections.
|
||||
*/
|
||||
public static final String PROPERTY_IO_WORKER_THREADS = "jclouds.io_worker_threads";
|
||||
|
||||
|
||||
/**
|
||||
* Integer property. default (20)
|
||||
* <p/>
|
||||
|
@ -46,9 +46,10 @@ public interface Constants {
|
|||
public static final String PROPERTY_MAX_CONNECTIONS_PER_CONTEXT = "jclouds.max_connections_per_context";
|
||||
|
||||
/**
|
||||
* Integer property. default (12)
|
||||
* Integer property. default (0)
|
||||
* <p/>
|
||||
* Limits the amount of connections per host.
|
||||
* Limits the amount of connections per host. 0 means indirectly limited by
|
||||
* {@link #PROPERTY_MAX_CONNECTIONS_PER_CONTEXT}.
|
||||
*/
|
||||
public static final String PROPERTY_MAX_CONNECTIONS_PER_HOST = "jclouds.max_connections_per_host";
|
||||
|
||||
|
@ -66,6 +67,20 @@ public interface Constants {
|
|||
*/
|
||||
public static final String PROPERTY_MAX_CONNECTION_REUSE = "jclouds.max_connection_reuse";
|
||||
|
||||
/**
|
||||
* int property. default (60000)
|
||||
* <p/>
|
||||
* How many milliseconds to wait before a socket connection times out. 0 means infinity.
|
||||
*/
|
||||
public static final String PROPERTY_SO_TIMEOUT = "jclouds.so_timeout";
|
||||
|
||||
/**
|
||||
* Long property. default (60000)
|
||||
* <p/>
|
||||
* How many milliseconds to wait before a connection times out. 0 means infinity.
|
||||
*/
|
||||
public static final String PROPERTY_CONNECTION_TIMEOUT = "jclouds.connection_timeout";
|
||||
|
||||
/**
|
||||
* Boolean property.
|
||||
* <p/>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.jclouds;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT;
|
||||
import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS;
|
||||
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT;
|
||||
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST;
|
||||
|
@ -27,6 +28,7 @@ import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
|
|||
import static org.jclouds.Constants.PROPERTY_MAX_SESSION_FAILURES;
|
||||
import static org.jclouds.Constants.PROPERTY_PROXY_SYSTEM;
|
||||
import static org.jclouds.Constants.PROPERTY_RELAX_HOSTNAME;
|
||||
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
|
||||
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -57,10 +59,26 @@ public abstract class PropertiesBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.Constants.PROPERTY_SO_TIMEOUT
|
||||
*/
|
||||
public PropertiesBuilder withSOTimeout(long soTimeout) {
|
||||
properties.setProperty(PROPERTY_SO_TIMEOUT, Long.toString(soTimeout));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.Constants.PROPERTY_CONNECTION_TIMEOUT
|
||||
*/
|
||||
public PropertiesBuilder withConnectionTimeout(long connectionTimeout) {
|
||||
properties.setProperty(PROPERTY_CONNECTION_TIMEOUT, Long.toString(connectionTimeout));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.Constants.PROPERTY_MAX_RETRIES
|
||||
*/
|
||||
public PropertiesBuilder withHttpMaxRetries(int httpMaxRetries) {
|
||||
public PropertiesBuilder withMaxRetries(int httpMaxRetries) {
|
||||
properties.setProperty(PROPERTY_MAX_RETRIES, Integer.toString(httpMaxRetries));
|
||||
return this;
|
||||
}
|
||||
|
@ -68,7 +86,7 @@ public abstract class PropertiesBuilder {
|
|||
/**
|
||||
* @see org.jclouds.Constants.PROPERTY_MAX_REDIRECTS
|
||||
*/
|
||||
public PropertiesBuilder withHttpMaxRedirects(int httpMaxRedirects) {
|
||||
public PropertiesBuilder withMaxRedirects(int httpMaxRedirects) {
|
||||
properties.setProperty(PROPERTY_MAX_REDIRECTS, Integer.toString(httpMaxRedirects));
|
||||
return this;
|
||||
}
|
||||
|
@ -133,7 +151,9 @@ public abstract class PropertiesBuilder {
|
|||
protected Properties defaultProperties() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + "");
|
||||
props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 12 + "");
|
||||
props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + "");
|
||||
props.setProperty(PROPERTY_SO_TIMEOUT, 60000 + "");
|
||||
props.setProperty(PROPERTY_CONNECTION_TIMEOUT, 60000 + "");
|
||||
props.setProperty(PROPERTY_IO_WORKER_THREADS, 20 + "");
|
||||
props.setProperty(PROPERTY_USER_THREADS, 0 + "");
|
||||
props.setProperty(PROPERTY_MAX_CONNECTION_REUSE, 75 + "");
|
||||
|
|
|
@ -39,6 +39,9 @@ import java.util.List;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.util.Utils;
|
||||
|
||||
|
@ -51,11 +54,61 @@ import com.google.common.collect.SortedSetMultimap;
|
|||
import com.google.common.collect.TreeMultimap;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class HttpUtils {
|
||||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_RELAX_HOSTNAME)
|
||||
private boolean relaxHostname = false;
|
||||
|
||||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_PROXY_SYSTEM)
|
||||
private boolean systemProxies = System.getProperty("java.net.useSystemProxies") != null ? Boolean
|
||||
.parseBoolean(System.getProperty("java.net.useSystemProxies"))
|
||||
: false;
|
||||
|
||||
private final int globalMaxConnections;
|
||||
private final int globalMaxConnectionsPerHost;
|
||||
private final int connectionTimeout;
|
||||
private final int soTimeout;
|
||||
|
||||
@Inject
|
||||
public HttpUtils(@Named(Constants.PROPERTY_CONNECTION_TIMEOUT) int connectionTimeout,
|
||||
@Named(Constants.PROPERTY_SO_TIMEOUT) int soTimeout,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT) int globalMaxConnections,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int globalMaxConnectionsPerHost) {
|
||||
this.soTimeout = soTimeout;
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
this.globalMaxConnections = globalMaxConnections;
|
||||
this.globalMaxConnectionsPerHost = globalMaxConnectionsPerHost;
|
||||
}
|
||||
|
||||
public int getSocketOpenTimeout() {
|
||||
return soTimeout;
|
||||
}
|
||||
|
||||
public int getConnectionTimeout() {
|
||||
return connectionTimeout;
|
||||
}
|
||||
|
||||
public boolean relaxHostname() {
|
||||
return relaxHostname;
|
||||
}
|
||||
|
||||
public boolean useSystemProxies() {
|
||||
return systemProxies;
|
||||
}
|
||||
|
||||
public int getMaxConnections() {
|
||||
return globalMaxConnections;
|
||||
}
|
||||
|
||||
public int getMaxConnectionsPerHost() {
|
||||
return globalMaxConnectionsPerHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* keys to the map are only used for socket information, not path. In this case, you should
|
||||
|
|
|
@ -18,11 +18,20 @@
|
|||
*/
|
||||
package org.jclouds.http.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
||||
import org.jclouds.http.HttpCommandExecutorService;
|
||||
import org.jclouds.http.TransformingHttpCommandExecutorService;
|
||||
import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl;
|
||||
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
|
@ -44,9 +53,27 @@ public class JavaUrlHttpCommandExecutorServiceModule extends AbstractModule {
|
|||
protected void bindClient() {
|
||||
bind(HttpCommandExecutorService.class).to(JavaUrlHttpCommandExecutorService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
|
||||
bind(HostnameVerifier.class).to(LogToMapHostnameVerifier.class);
|
||||
bind(TransformingHttpCommandExecutorService.class).to(
|
||||
TransformingHttpCommandExecutorServiceImpl.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Used to get more information about HTTPS hostname wrong errors.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
static class LogToMapHostnameVerifier implements HostnameVerifier {
|
||||
@Resource
|
||||
private Logger logger = Logger.NULL;
|
||||
private final Map<String, String> sslMap = Maps.newHashMap();;
|
||||
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
logger.warn("hostname was %s while session was %s", hostname, session.getPeerHost());
|
||||
sslMap.put(hostname, session.getPeerHost());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -58,7 +58,7 @@ public abstract class BaseHttpCommandExecutorService<Q> implements HttpCommandEx
|
|||
@Named(Constants.LOGGER_HTTP_HEADERS)
|
||||
protected Logger headerLog = Logger.NULL;
|
||||
|
||||
private final HttpWire wire;
|
||||
protected final HttpWire wire;
|
||||
|
||||
@Inject
|
||||
protected BaseHttpCommandExecutorService(
|
||||
|
|
|
@ -27,26 +27,26 @@ import java.net.HttpURLConnection;
|
|||
import java.net.Proxy;
|
||||
import java.net.ProxySelector;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.http.HttpCommandExecutorService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Inject;
|
||||
|
@ -61,44 +61,54 @@ public class JavaUrlHttpCommandExecutorService extends
|
|||
BaseHttpCommandExecutorService<HttpURLConnection> {
|
||||
|
||||
public static final String USER_AGENT = "jclouds/1.0 java/" + System.getProperty("java.version");
|
||||
|
||||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_RELAX_HOSTNAME)
|
||||
private boolean relaxHostname = false;
|
||||
private final Map<String, String> sslMap;
|
||||
|
||||
@Inject(optional = true)
|
||||
@Named(Constants.PROPERTY_PROXY_SYSTEM)
|
||||
private boolean systemProxies = System.getProperty("java.net.useSystemProxies") != null ? Boolean
|
||||
.parseBoolean(System.getProperty("java.net.useSystemProxies"))
|
||||
: false;
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private final HostnameVerifier verifier;
|
||||
private final HttpUtils utils;
|
||||
|
||||
@Inject
|
||||
public JavaUrlHttpCommandExecutorService(
|
||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
||||
DelegatingRetryHandler retryHandler,
|
||||
DelegatingErrorHandler errorHandler,
|
||||
HttpWire wire,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT) final int globalMaxConnections,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) final int globalMaxConnectionsPerHost) {
|
||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler,
|
||||
HttpWire wire, HttpUtils utils, HostnameVerifier verifier) {
|
||||
super(ioWorkerExecutor, retryHandler, errorHandler, wire);
|
||||
sslMap = Maps.newHashMap();
|
||||
if (globalMaxConnections > 0)
|
||||
System.setProperty("http.maxConnections", String.valueOf(globalMaxConnections));
|
||||
if (utils.getMaxConnections() > 0)
|
||||
System.setProperty("http.maxConnections", String.valueOf(utils.getMaxConnections()));
|
||||
this.utils = utils;
|
||||
this.verifier = verifier;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Used to get more information about HTTPS hostname wrong errors.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
class LogToMapHostnameVerifier implements HostnameVerifier {
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
logger.warn("hostname was %s while session was %s", hostname, session.getPeerHost());
|
||||
sslMap.put(hostname, session.getPeerHost());
|
||||
return true;
|
||||
@Override
|
||||
protected HttpResponse invoke(HttpURLConnection connection) throws IOException,
|
||||
InterruptedException {
|
||||
HttpResponse response = new HttpResponse();
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = consumeOnClose(connection.getInputStream());
|
||||
} catch (IOException e) {
|
||||
in = bufferAndCloseStream(connection.getErrorStream());
|
||||
} catch (RuntimeException e) {
|
||||
Closeables.closeQuietly(in);
|
||||
Throwables.propagate(e);
|
||||
assert false : "should have propagated exception";
|
||||
}
|
||||
for (String header : connection.getHeaderFields().keySet()) {
|
||||
response.getHeaders().putAll(header, connection.getHeaderFields().get(header));
|
||||
}
|
||||
if (connection.getResponseCode() == 204) {
|
||||
Closeables.closeQuietly(in);
|
||||
in = null;
|
||||
} else if (in != null) {
|
||||
response.setContent(in);
|
||||
}
|
||||
response.setStatusCode(connection.getResponseCode());
|
||||
response.setMessage(connection.getResponseMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
public InputStream consumeOnClose(InputStream in) {
|
||||
return new ConsumeOnCloseInputStream(in);
|
||||
}
|
||||
|
||||
class ConsumeOnCloseInputStream extends FilterInputStream {
|
||||
|
@ -128,33 +138,6 @@ public class JavaUrlHttpCommandExecutorService extends
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpResponse invoke(HttpURLConnection connection) throws IOException,
|
||||
InterruptedException {
|
||||
HttpResponse response = new HttpResponse();
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = new ConsumeOnCloseInputStream(connection.getInputStream());
|
||||
} catch (IOException e) {
|
||||
in = bufferAndCloseStream(connection.getErrorStream());
|
||||
} catch (RuntimeException e) {
|
||||
Closeables.closeQuietly(in);
|
||||
Throwables.propagate(e);
|
||||
assert false : "should have propagated exception";
|
||||
}
|
||||
for (String header : connection.getHeaderFields().keySet()) {
|
||||
response.getHeaders().putAll(header, connection.getHeaderFields().get(header));
|
||||
}
|
||||
if (connection.getResponseCode() == 204) {
|
||||
Closeables.closeQuietly(in);
|
||||
in = null;
|
||||
} else if (in != null) {
|
||||
response.setContent(in);
|
||||
}
|
||||
response.setStatusCode(connection.getResponseCode());
|
||||
response.setMessage(connection.getResponseMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
private InputStream bufferAndCloseStream(InputStream inputStream) throws IOException {
|
||||
InputStream in = null;
|
||||
|
@ -173,7 +156,7 @@ public class JavaUrlHttpCommandExecutorService extends
|
|||
InterruptedException {
|
||||
URL url = request.getEndpoint().toURL();
|
||||
HttpURLConnection connection;
|
||||
if (systemProxies) {
|
||||
if (utils.useSystemProxies()) {
|
||||
System.setProperty("java.net.useSystemProxies", "true");
|
||||
Iterable<Proxy> proxies = ProxySelector.getDefault().select(request.getEndpoint());
|
||||
Proxy proxy = Iterables.getLast(proxies);
|
||||
|
@ -181,9 +164,9 @@ public class JavaUrlHttpCommandExecutorService extends
|
|||
} else {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
}
|
||||
if (relaxHostname && connection instanceof HttpsURLConnection) {
|
||||
if (utils.relaxHostname() && connection instanceof HttpsURLConnection) {
|
||||
HttpsURLConnection sslCon = (HttpsURLConnection) connection;
|
||||
sslCon.setHostnameVerifier(new LogToMapHostnameVerifier());
|
||||
sslCon.setHostnameVerifier(verifier);
|
||||
}
|
||||
connection.setDoOutput(true);
|
||||
connection.setAllowUserInteraction(false);
|
||||
|
|
|
@ -51,7 +51,7 @@ public class HttpPropertiesBuilderTest {
|
|||
return this;
|
||||
}
|
||||
};
|
||||
builder.withHttpMaxRetries(httpMaxRetries);
|
||||
builder.withMaxRetries(httpMaxRetries);
|
||||
|
||||
builder.limitIoWorkerThreadsTo(poolIoWorkerThreads);
|
||||
builder.withMaxClientReuse(poolMaxClientReuse);
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.jclouds.PropertiesBuilder;
|
|||
import org.jclouds.http.BaseJettyTest;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.IntegrationTestAsyncClient;
|
||||
import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl;
|
||||
import org.jclouds.http.TransformingHttpCommandImpl;
|
||||
|
@ -93,7 +94,7 @@ public class BackoffLimitedRetryHandlerTest {
|
|||
ExecutorService execService = Executors.newCachedThreadPool();
|
||||
JavaUrlHttpCommandExecutorService httpService = new JavaUrlHttpCommandExecutorService(
|
||||
execService, new DelegatingRetryHandler(), new DelegatingErrorHandler(),
|
||||
new HttpWire(), 1, 1);
|
||||
new HttpWire(), new HttpUtils(0, 500, 1, 1), null);
|
||||
executorService = new TransformingHttpCommandExecutorServiceImpl(httpService);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,31 +19,16 @@
|
|||
|
||||
package org.jclouds.http.apachehc;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.conn.params.ConnManagerParams;
|
||||
import org.apache.http.conn.params.ConnPerRoute;
|
||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
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.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
|
@ -52,7 +37,6 @@ import org.jclouds.http.handlers.DelegatingRetryHandler;
|
|||
import org.jclouds.http.internal.BaseHttpCommandExecutorService;
|
||||
import org.jclouds.http.internal.HttpWire;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -62,78 +46,39 @@ import com.google.inject.Inject;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class ApacheHCHttpCommandExecutorService extends
|
||||
BaseHttpCommandExecutorService<HttpEntityEnclosingRequest> {
|
||||
@VisibleForTesting
|
||||
boolean isOpen = true;
|
||||
private final BasicHttpParams params;
|
||||
private final ThreadSafeClientConnManager cm;
|
||||
private final ApacheHCUtils utils;
|
||||
BaseHttpCommandExecutorService<HttpUriRequest> {
|
||||
private final HttpClient client;
|
||||
|
||||
@Inject
|
||||
ApacheHCHttpCommandExecutorService(
|
||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
||||
DelegatingRetryHandler retryHandler,
|
||||
DelegatingErrorHandler errorHandler,
|
||||
HttpWire wire,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT) final int globalMaxConnections,
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) final int globalMaxConnectionsPerHost,
|
||||
ApacheHCUtils utils) {
|
||||
DelegatingRetryHandler retryHandler, DelegatingErrorHandler errorHandler,
|
||||
HttpWire wire, HttpClient client) {
|
||||
super(ioWorkerExecutor, retryHandler, errorHandler, wire);
|
||||
this.utils = utils;
|
||||
params = new BasicHttpParams();
|
||||
// TODO: have this use our executor service, if possible
|
||||
if (globalMaxConnections > 0)
|
||||
ConnManagerParams.setMaxTotalConnections(params, globalMaxConnections);
|
||||
if (globalMaxConnectionsPerHost > 0) {
|
||||
ConnPerRoute connectionsPerRoute = new ConnPerRouteBean(globalMaxConnectionsPerHost);
|
||||
ConnManagerParams.setMaxConnectionsPerRoute(params, connectionsPerRoute);
|
||||
}
|
||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
||||
cm = new ThreadSafeClientConnManager(params, schemeRegistry);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpEntityEnclosingRequest convert(HttpRequest request) throws IOException {
|
||||
return utils.convertToApacheRequest(request);
|
||||
protected HttpUriRequest convert(HttpRequest request) throws IOException {
|
||||
return ApacheHCUtils.convertToApacheRequest(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpResponse invoke(HttpEntityEnclosingRequest nativeRequest) throws IOException {
|
||||
checkState(isOpen, "http executor not open");
|
||||
protected HttpResponse invoke(HttpUriRequest nativeRequest) throws IOException {
|
||||
org.apache.http.HttpResponse nativeResponse = executeRequest(nativeRequest);
|
||||
return utils.convertToJCloudsResponse(nativeResponse);
|
||||
return ApacheHCUtils.convertToJCloudsResponse(nativeResponse);
|
||||
}
|
||||
|
||||
private org.apache.http.HttpResponse executeRequest(HttpEntityEnclosingRequest nativeRequest)
|
||||
private org.apache.http.HttpResponse executeRequest(HttpUriRequest nativeRequest)
|
||||
throws IOException, ClientProtocolException {
|
||||
URI endpoint = URI.create(nativeRequest.getRequestLine().getUri());
|
||||
HttpClient client = new DefaultHttpClient(cm, params);
|
||||
HttpHost host = new HttpHost(endpoint.getHost(), endpoint.getPort(), endpoint.getScheme());
|
||||
org.apache.http.HttpResponse nativeResponse = client.execute(host, nativeRequest);
|
||||
return nativeResponse;
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void close() {
|
||||
// TODO test
|
||||
isOpen = false;
|
||||
cm.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
close();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanup(HttpEntityEnclosingRequest nativeResponse) {
|
||||
protected void cleanup(HttpUriRequest nativeResponse) {
|
||||
// No cleanup necessary
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,22 +24,26 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.HttpMethod;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.FileEntity;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.Payload;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,31 +51,42 @@ import org.jclouds.logging.Logger;
|
|||
*/
|
||||
@Singleton
|
||||
public class ApacheHCUtils {
|
||||
|
||||
public static final String USER_AGENT = "jclouds/1.0 httpclient/4.0.1";
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
public HttpEntityEnclosingRequest convertToApacheRequest(HttpRequest request) {
|
||||
|
||||
String uri = request.getEndpoint().toASCIIString();
|
||||
if (request.getEndpoint().getQuery() != null)
|
||||
uri += "?" + request.getEndpoint().getQuery();
|
||||
BasicHttpEntityEnclosingRequest apacheRequest = new BasicHttpEntityEnclosingRequest(request
|
||||
.getMethod(), uri, HttpVersion.HTTP_1_1);
|
||||
|
||||
public static HttpUriRequest convertToApacheRequest(HttpRequest request) {
|
||||
HttpUriRequest apacheRequest;
|
||||
if (request.getMethod().equals(HttpMethod.HEAD)) {
|
||||
apacheRequest = new HttpHead(request.getEndpoint());
|
||||
} else if (request.getMethod().equals(HttpMethod.GET)) {
|
||||
apacheRequest = new HttpGet(request.getEndpoint());
|
||||
} else if (request.getMethod().equals(HttpMethod.DELETE)) {
|
||||
apacheRequest = new HttpDelete(request.getEndpoint());
|
||||
} else if (request.getMethod().equals(HttpMethod.PUT)) {
|
||||
apacheRequest = new HttpPut(request.getEndpoint());
|
||||
} else if (request.getMethod().equals(HttpMethod.POST)) {
|
||||
apacheRequest = new HttpPost(request.getEndpoint());
|
||||
} else {
|
||||
throw new UnsupportedOperationException(request.getMethod());
|
||||
}
|
||||
Payload payload = request.getPayload();
|
||||
|
||||
// Since we may remove headers, ensure they are added to the apache
|
||||
// request after this block
|
||||
if (payload != null) {
|
||||
String lengthString = request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
||||
if (lengthString == null) {
|
||||
throw new IllegalStateException("no Content-Length header on request: " + apacheRequest);
|
||||
if (apacheRequest instanceof HttpEntityEnclosingRequest) {
|
||||
if (payload != null) {
|
||||
String lengthString = request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH);
|
||||
if (lengthString == null) {
|
||||
throw new IllegalStateException("no Content-Length header on request: "
|
||||
+ apacheRequest);
|
||||
}
|
||||
long contentLength = Long.parseLong(lengthString);
|
||||
String contentType = request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
||||
addEntityForContent(HttpEntityEnclosingRequest.class.cast(apacheRequest), payload
|
||||
.getRawContent(), contentType, contentLength);
|
||||
}
|
||||
long contentLength = Long.parseLong(lengthString);
|
||||
String contentType = request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE);
|
||||
addEntityForContent(apacheRequest, payload.getRawContent(), contentType, contentLength);
|
||||
} else {
|
||||
apacheRequest.addHeader(HttpHeaders.CONTENT_LENGTH, "0");
|
||||
}
|
||||
|
||||
for (String header : request.getHeaders().keySet()) {
|
||||
|
@ -81,11 +96,10 @@ public class ApacheHCUtils {
|
|||
apacheRequest.addHeader(header, value);
|
||||
}
|
||||
apacheRequest.addHeader(HttpHeaders.USER_AGENT, USER_AGENT);
|
||||
|
||||
return apacheRequest;
|
||||
}
|
||||
|
||||
public void addEntityForContent(HttpEntityEnclosingRequest apacheRequest, Object content,
|
||||
public static void addEntityForContent(HttpEntityEnclosingRequest apacheRequest, Object content,
|
||||
String contentType, long length) {
|
||||
if (content instanceof InputStream) {
|
||||
InputStream inputStream = (InputStream) content;
|
||||
|
@ -117,12 +131,13 @@ public class ApacheHCUtils {
|
|||
assert (apacheRequest.getEntity() != null);
|
||||
}
|
||||
|
||||
public HttpResponse convertToJCloudsResponse(org.apache.http.HttpResponse apacheResponse)
|
||||
public static HttpResponse convertToJCloudsResponse(org.apache.http.HttpResponse apacheResponse)
|
||||
throws IOException {
|
||||
|
||||
HttpResponse response = new HttpResponse();
|
||||
if (apacheResponse.getEntity() != null) {
|
||||
response
|
||||
.setContent(new ConsumeOnCloseInputStream(apacheResponse.getEntity().getContent()));
|
||||
// response.setContent(consumeOnClose(apacheResponse.getEntity()));
|
||||
response.setContent(apacheResponse.getEntity().getContent());
|
||||
}
|
||||
for (Header header : apacheResponse.getAllHeaders()) {
|
||||
response.getHeaders().put(header.getName(), header.getValue());
|
||||
|
@ -132,10 +147,19 @@ public class ApacheHCUtils {
|
|||
return response;
|
||||
}
|
||||
|
||||
class ConsumeOnCloseInputStream extends FilterInputStream {
|
||||
public static InputStream consumeOnClose(HttpEntity httpEntity) throws IllegalStateException,
|
||||
IOException {
|
||||
return new ConsumeOnCloseInputStream(httpEntity);
|
||||
}
|
||||
|
||||
protected ConsumeOnCloseInputStream(InputStream in) {
|
||||
super(in);
|
||||
static class ConsumeOnCloseInputStream extends FilterInputStream {
|
||||
|
||||
private final HttpEntity httpEntity;
|
||||
|
||||
protected ConsumeOnCloseInputStream(HttpEntity httpEntity) throws IllegalStateException,
|
||||
IOException {
|
||||
super(httpEntity.getContent());
|
||||
this.httpEntity = httpEntity;
|
||||
}
|
||||
|
||||
boolean closed;
|
||||
|
@ -144,13 +168,8 @@ public class ApacheHCUtils {
|
|||
public void close() throws IOException {
|
||||
try {
|
||||
if (!closed) {
|
||||
int result = 0;
|
||||
while (result != -1) {
|
||||
result = read();
|
||||
}
|
||||
httpEntity.consumeContent();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.warn(e, "error reading stream");
|
||||
} finally {
|
||||
closed = true;
|
||||
super.close();
|
||||
|
|
|
@ -18,13 +18,44 @@
|
|||
*/
|
||||
package org.jclouds.http.apachehc.config;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.ProxySelector;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.params.ConnManagerParams;
|
||||
import org.apache.http.conn.params.ConnPerRoute;
|
||||
import org.apache.http.conn.params.ConnPerRouteBean;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
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.ProxySelectorRoutePlanner;
|
||||
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
|
||||
import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.CoreConnectionPNames;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.jclouds.http.HttpCommandExecutorService;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.TransformingHttpCommandExecutorService;
|
||||
import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl;
|
||||
import org.jclouds.http.apachehc.ApacheHCHttpCommandExecutorService;
|
||||
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
/**
|
||||
|
@ -43,6 +74,89 @@ public class ApacheHCHttpCommandExecutorServiceModule extends AbstractModule {
|
|||
bindClient();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
HttpParams newBasicHttpParams(HttpUtils utils) {
|
||||
BasicHttpParams params = new BasicHttpParams();
|
||||
|
||||
params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
|
||||
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true)
|
||||
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(
|
||||
CoreProtocolPNames.ORIGIN_SERVER, "jclouds/1.0");
|
||||
|
||||
if (utils.getConnectionTimeout() > 0) {
|
||||
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, utils
|
||||
.getConnectionTimeout());
|
||||
}
|
||||
|
||||
if (utils.getSocketOpenTimeout() > 0) {
|
||||
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, utils.getSocketOpenTimeout());
|
||||
}
|
||||
|
||||
if (utils.getMaxConnections() > 0)
|
||||
ConnManagerParams.setMaxTotalConnections(params, utils.getMaxConnections());
|
||||
|
||||
if (utils.getMaxConnectionsPerHost() > 0) {
|
||||
ConnPerRoute connectionsPerRoute = new ConnPerRouteBean(utils.getMaxConnectionsPerHost());
|
||||
ConnManagerParams.setMaxConnectionsPerRoute(params, connectionsPerRoute);
|
||||
}
|
||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
||||
return params;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
X509HostnameVerifier newHostnameVerifier(HttpUtils utils) {
|
||||
return utils.relaxHostname() ? SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
|
||||
: SSLSocketFactory.STRICT_HOSTNAME_VERIFIER;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
ClientConnectionManager newClientConnectionManager(HttpParams params,
|
||||
X509HostnameVerifier verifier, Closer closer) throws NoSuchAlgorithmException,
|
||||
KeyManagementException {
|
||||
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
|
||||
Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
|
||||
SSLContext context = SSLContext.getInstance("TLS");
|
||||
|
||||
context.init(null, null, null);
|
||||
SSLSocketFactory sf = new SSLSocketFactory(context);
|
||||
sf.setHostnameVerifier(verifier);
|
||||
|
||||
Scheme https = new Scheme("https", sf, 443);
|
||||
|
||||
SchemeRegistry sr = new SchemeRegistry();
|
||||
sr.register(http);
|
||||
sr.register(https);
|
||||
|
||||
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
|
||||
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
||||
final ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
|
||||
closer.addToClose(new Closeable() {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
cm.shutdown();
|
||||
}
|
||||
});
|
||||
return cm;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
HttpClient newDefaultHttpClient(HttpUtils utils, BasicHttpParams params,
|
||||
ClientConnectionManager cm) {
|
||||
DefaultHttpClient client = new DefaultHttpClient(cm, params);
|
||||
if (utils.useSystemProxies()) {
|
||||
ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(client
|
||||
.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault());
|
||||
client.setRoutePlanner(routePlanner);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
protected void bindClient() {
|
||||
bind(HttpCommandExecutorService.class).to(ApacheHCHttpCommandExecutorService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.http.apachehc;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_IO_WORKER_THREADS;
|
||||
import static org.jclouds.Constants.*;
|
||||
import static org.jclouds.Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST;
|
||||
import static org.jclouds.Constants.PROPERTY_USER_THREADS;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.http.BaseHttpCommandExecutorServiceTest;
|
||||
|
@ -33,13 +38,21 @@ import com.google.inject.Module;
|
|||
*/
|
||||
@Test
|
||||
public class ApacheHCHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorServiceTest {
|
||||
static {
|
||||
System.setProperty("http.conn-manager.timeout", 1000 + "");
|
||||
}
|
||||
|
||||
protected Module createConnectionModule() {
|
||||
return new ApacheHCHttpCommandExecutorServiceModule();
|
||||
}
|
||||
|
||||
protected void addConnectionProperties(Properties props) {
|
||||
|
||||
props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + "");
|
||||
props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + "");
|
||||
props.setProperty(PROPERTY_CONNECTION_TIMEOUT, 100 + "");
|
||||
props.setProperty(PROPERTY_SO_TIMEOUT, 100 + "");
|
||||
props.setProperty(PROPERTY_IO_WORKER_THREADS, 3 + "");
|
||||
props.setProperty(PROPERTY_USER_THREADS, 0 + "");
|
||||
}
|
||||
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.http.httpnio.config;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
@ -36,6 +36,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.apache.http.ConnectionReuseStrategy;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpVersion;
|
||||
import org.apache.http.impl.DefaultConnectionReuseStrategy;
|
||||
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
|
||||
import org.apache.http.nio.NHttpConnection;
|
||||
|
@ -50,6 +51,7 @@ import org.apache.http.params.BasicHttpParams;
|
|||
import org.apache.http.params.CoreConnectionPNames;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.params.HttpProtocolParams;
|
||||
import org.apache.http.protocol.BasicHttpProcessor;
|
||||
import org.apache.http.protocol.RequestConnControl;
|
||||
import org.apache.http.protocol.RequestContent;
|
||||
|
@ -58,6 +60,7 @@ import org.apache.http.protocol.RequestTargetHost;
|
|||
import org.apache.http.protocol.RequestUserAgent;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.http.HttpCommandRendezvous;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.TransformingHttpCommandExecutorService;
|
||||
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
|
||||
import org.jclouds.http.httpnio.pool.NioHttpCommandConnectionPool;
|
||||
|
@ -101,15 +104,26 @@ public class NioTransformingHttpCommandExecutorServiceModule extends
|
|||
return httpproc;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public HttpParams provideHttpParams() {
|
||||
HttpParams params = new BasicHttpParams();
|
||||
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(
|
||||
CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).setBooleanParameter(
|
||||
CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(
|
||||
CoreConnectionPNames.TCP_NODELAY, true).setParameter(
|
||||
CoreProtocolPNames.ORIGIN_SERVER, "jclouds/1.0");
|
||||
@Provides
|
||||
HttpParams newBasicHttpParams(HttpUtils utils) {
|
||||
BasicHttpParams params = new BasicHttpParams();
|
||||
|
||||
params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
|
||||
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, true)
|
||||
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(
|
||||
CoreProtocolPNames.ORIGIN_SERVER, "jclouds/1.0");
|
||||
|
||||
if (utils.getConnectionTimeout() > 0) {
|
||||
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, utils
|
||||
.getConnectionTimeout());
|
||||
}
|
||||
|
||||
if (utils.getSocketOpenTimeout() > 0) {
|
||||
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, utils.getSocketOpenTimeout());
|
||||
}
|
||||
|
||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
||||
return params;
|
||||
}
|
||||
|
||||
|
@ -198,9 +212,9 @@ public class NioTransformingHttpCommandExecutorServiceModule extends
|
|||
}
|
||||
|
||||
@Override
|
||||
public BlockingQueue<NHttpConnection> provideAvailablePool(
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int maxConnectionsPerHost) throws Exception {
|
||||
return new ArrayBlockingQueue<NHttpConnection>(maxConnectionsPerHost, true);
|
||||
public BlockingQueue<NHttpConnection> provideAvailablePool(HttpUtils utils) throws Exception {
|
||||
return new ArrayBlockingQueue<NHttpConnection>(utils.getMaxConnectionsPerHost() != 0 ? utils
|
||||
.getMaxConnectionsPerHost() : utils.getMaxConnections(), true);
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -22,9 +22,7 @@ import java.util.concurrent.BlockingQueue;
|
|||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.lifecycle.config.LifeCycleModule;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -36,7 +34,6 @@ import com.google.inject.Provides;
|
|||
*/
|
||||
public abstract class ConnectionPoolCommandExecutorServiceModule<C> extends AbstractModule {
|
||||
|
||||
|
||||
protected void configure() {
|
||||
install(new LifeCycleModule());
|
||||
bind(AtomicInteger.class).toInstance(new AtomicInteger());// max errors
|
||||
|
@ -45,9 +42,7 @@ public abstract class ConnectionPoolCommandExecutorServiceModule<C> extends Abst
|
|||
|
||||
@Provides
|
||||
// @Singleton per uri...
|
||||
public abstract BlockingQueue<C> provideAvailablePool(
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int maxConnectionsPerHost)
|
||||
throws Exception;
|
||||
public abstract BlockingQueue<C> provideAvailablePool(HttpUtils utils) throws Exception;
|
||||
|
||||
/**
|
||||
* controls production and destruction of real connections.
|
||||
|
@ -59,9 +54,8 @@ public abstract class ConnectionPoolCommandExecutorServiceModule<C> extends Abst
|
|||
*/
|
||||
@Provides
|
||||
// @Singleton per uri...
|
||||
public Semaphore provideTotalConnectionSemaphore(
|
||||
@Named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST) int maxConnectionsPerHost)
|
||||
throws Exception {
|
||||
return new Semaphore(maxConnectionsPerHost, true);
|
||||
public Semaphore provideTotalConnectionSemaphore(HttpUtils utils) throws Exception {
|
||||
return new Semaphore(utils.getMaxConnectionsPerHost() != 0 ? utils.getMaxConnectionsPerHost()
|
||||
: utils.getMaxConnections(), true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.net.URI;
|
|||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
|
@ -84,13 +83,8 @@ public class PCSCloudTest {
|
|||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(PCS.class)
|
||||
.toInstance(URI.create("http://localhost:8080"));
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
|
||||
.to("1");
|
||||
Jsr330.bindProperties(this.binder(), new PCSPropertiesBuilder(URI
|
||||
.create("http://localhost:8080"), "user", "key").build());
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
|
|
@ -21,7 +21,8 @@ package org.jclouds.mezeo.pcs2.config;
|
|||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
|
@ -31,8 +32,8 @@ import org.jclouds.http.handlers.DelegatingRetryHandler;
|
|||
import org.jclouds.http.handlers.RedirectionRetryHandler;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.mezeo.pcs2.PCSPropertiesBuilder;
|
||||
import org.jclouds.mezeo.pcs2.handlers.PCSClientErrorRetryHandler;
|
||||
import org.jclouds.mezeo.pcs2.reference.PCSConstants;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -49,18 +50,8 @@ public class PCSContextModuleTest {
|
|||
return Guice.createInjector(new PCSRestClientModule(), new PCSContextModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(Jsr330.named(PCSConstants.PROPERTY_PCS2_USER)).to("user");
|
||||
bindConstant().annotatedWith(Jsr330.named(PCSConstants.PROPERTY_PCS2_PASSWORD)).to(
|
||||
"key");
|
||||
bindConstant().annotatedWith(Jsr330.named(PCSConstants.PROPERTY_PCS2_ENDPOINT)).to(
|
||||
"http://localhost");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
|
||||
.to("1");
|
||||
Jsr330.bindProperties(this.binder(), new PCSPropertiesBuilder(URI
|
||||
.create("http://localhost:8080"), "user", "key").build());
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.net.URI;
|
|||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
|
@ -77,13 +76,8 @@ public class SDNAuthenticationTest {
|
|||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(SDN.class)
|
||||
.toInstance(URI.create("http://localhost:8080"));
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
|
||||
.to("1");
|
||||
Jsr330.bindProperties(this.binder(), new SDNPropertiesBuilder("user", "key", "key",
|
||||
"key").build());
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
@ -96,5 +90,4 @@ public class SDNAuthenticationTest {
|
|||
.get(new TypeLiteral<RestAnnotationProcessor<SDNAuthentication>>() {
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,13 +27,13 @@ import java.net.URI;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.ext.RuntimeDelegate;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.nirvanix.sdn.SDNPropertiesBuilder;
|
||||
import org.jclouds.nirvanix.sdn.SessionToken;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.config.RestModule;
|
||||
|
@ -109,14 +109,8 @@ public class AddSessionTokenToRequestTest {
|
|||
protected void configure() {
|
||||
RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
|
||||
bind(DateService.class);
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
|
||||
Jsr330.bindProperties(this.binder(), new SDNPropertiesBuilder("appkey",
|
||||
"appname", "username", "password").build());
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
|
|
@ -30,12 +30,11 @@ import java.net.URI;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.ext.RuntimeDelegate;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
||||
import org.jclouds.nirvanix.sdn.SDNPropertiesBuilder;
|
||||
import org.jclouds.rest.annotations.EndpointParam;
|
||||
import org.jclouds.rest.config.RestModule;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
@ -107,20 +106,8 @@ public class InsertUserContextIntoPathTest {
|
|||
expect(sessionManager.getSessionToken()).andReturn("token").anyTimes();
|
||||
replay(sessionManager);
|
||||
bind(AddSessionTokenToRequest.class).toInstance(sessionManager);
|
||||
bindConstant().annotatedWith(Jsr330.named(SDNConstants.PROPERTY_SDN_APPKEY))
|
||||
.to("appKey");
|
||||
bindConstant().annotatedWith(Jsr330.named(SDNConstants.PROPERTY_SDN_USERNAME))
|
||||
.to("username");
|
||||
bindConstant().annotatedWith(Jsr330.named(SDNConstants.PROPERTY_SDN_APPNAME))
|
||||
.to("appname");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
|
||||
Jsr330.bindProperties(this.binder(), new SDNPropertiesBuilder("appkey",
|
||||
"appname", "username", "password").build());
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Collections;
|
|||
|
||||
import javax.ws.rs.HttpMethod;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
|
@ -79,15 +78,10 @@ public class RackspaceAuthenticationTest {
|
|||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
Jsr330.bindProperties(this.binder(), new RackspacePropertiesBuilder("user", "key")
|
||||
.build());
|
||||
bind(URI.class).annotatedWith(Authentication.class).toInstance(
|
||||
URI.create("http://localhost:8080"));
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
|
||||
.to("1");
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
|
|
@ -39,7 +39,6 @@ import javax.ws.rs.HttpMethod;
|
|||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
|
@ -49,6 +48,7 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.rackspace.Authentication;
|
||||
import org.jclouds.rackspace.CloudServers;
|
||||
import org.jclouds.rackspace.RackspacePropertiesBuilder;
|
||||
import org.jclouds.rackspace.cloudservers.domain.BackupSchedule;
|
||||
import org.jclouds.rackspace.cloudservers.domain.DailyBackup;
|
||||
import org.jclouds.rackspace.cloudservers.domain.RebootType;
|
||||
|
@ -999,15 +999,10 @@ public class CloudServersClientTest {
|
|||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
Jsr330.bindProperties(this.binder(), new RackspacePropertiesBuilder("user", "key")
|
||||
.build());
|
||||
bind(URI.class).annotatedWith(CloudServers.class).toInstance(
|
||||
URI.create("http://localhost:8080"));
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
|
||||
.to("1");
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.rimuhosting.miro.config;
|
|||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.HttpRetryHandler;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
|
@ -34,7 +33,7 @@ import org.jclouds.http.handlers.DelegatingRetryHandler;
|
|||
import org.jclouds.http.handlers.RedirectionRetryHandler;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.rimuhosting.miro.reference.RimuHostingConstants;
|
||||
import org.jclouds.rimuhosting.miro.RimuHostingPropertiesBuilder;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -48,25 +47,12 @@ import com.google.inject.Injector;
|
|||
public class RimuHostingContextModuleTest {
|
||||
|
||||
Injector createInjector() {
|
||||
return Guice.createInjector(
|
||||
new RimuHostingRestClientModule(),
|
||||
return Guice.createInjector(new RimuHostingRestClientModule(),
|
||||
new RimuHostingContextModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_APIKEY)).to(
|
||||
"apikey");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(RimuHostingConstants.PROPERTY_RIMUHOSTING_ENDPOINT)).to(
|
||||
"http://localhost");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)).to("1");
|
||||
Jsr330.bindProperties(this.binder(),
|
||||
new RimuHostingPropertiesBuilder("apikey").build());
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.twitter.config;
|
|||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.HttpRetryHandler;
|
||||
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||
|
@ -34,7 +33,7 @@ import org.jclouds.http.handlers.DelegatingRetryHandler;
|
|||
import org.jclouds.http.handlers.RedirectionRetryHandler;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.twitter.reference.TwitterConstants;
|
||||
import org.jclouds.twitter.TwitterPropertiesBuilder;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -51,19 +50,8 @@ public class TwitterContextModuleTest {
|
|||
return Guice.createInjector(new TwitterRestClientModule(), new TwitterContextModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(Jsr330.named(TwitterConstants.PROPERTY_TWITTER_USER)).to(
|
||||
"user");
|
||||
bindConstant().annotatedWith(Jsr330.named(TwitterConstants.PROPERTY_TWITTER_PASSWORD))
|
||||
.to("password");
|
||||
bindConstant().annotatedWith(Jsr330.named(TwitterConstants.PROPERTY_TWITTER_ENDPOINT))
|
||||
.to("http://localhost");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS))
|
||||
.to("1");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)).to("1");
|
||||
bindConstant().annotatedWith(
|
||||
Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)).to("0");
|
||||
bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST))
|
||||
.to("1");
|
||||
Jsr330.bindProperties(this.binder(), new TwitterPropertiesBuilder("user", "pass")
|
||||
.build());
|
||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
|
|
Loading…
Reference in New Issue