mirror of https://github.com/apache/jclouds.git
moved io out of injector and into supplier code
This commit is contained in:
parent
3bce2e0d94
commit
5015c169e4
|
@ -19,14 +19,12 @@
|
||||||
|
|
||||||
package org.jclouds.http.config;
|
package org.jclouds.http.config;
|
||||||
|
|
||||||
import java.security.KeyManagementException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
@ -40,10 +38,13 @@ import org.jclouds.http.TransformingHttpCommandExecutorServiceImpl;
|
||||||
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
|
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configures {@link JavaUrlHttpCommandExecutorService}.
|
* Configures {@link JavaUrlHttpCommandExecutorService}.
|
||||||
|
@ -65,6 +66,9 @@ public class JavaUrlHttpCommandExecutorServiceModule extends AbstractModule {
|
||||||
bind(HostnameVerifier.class).to(LogToMapHostnameVerifier.class);
|
bind(HostnameVerifier.class).to(LogToMapHostnameVerifier.class);
|
||||||
bind(TransformingHttpCommandExecutorService.class).to(TransformingHttpCommandExecutorServiceImpl.class).in(
|
bind(TransformingHttpCommandExecutorService.class).to(TransformingHttpCommandExecutorServiceImpl.class).in(
|
||||||
Scopes.SINGLETON);
|
Scopes.SINGLETON);
|
||||||
|
bind(new TypeLiteral<Supplier<SSLContext>>() {
|
||||||
|
}).annotatedWith(Names.named("untrusted")).to(new TypeLiteral<UntrustedSSLContextSupplier>() {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,14 +90,28 @@ public class JavaUrlHttpCommandExecutorServiceModule extends AbstractModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("untrusted")
|
public static class UntrustedSSLContextSupplier implements Supplier<SSLContext> {
|
||||||
SSLContext provideUntrustedSSLContext(TrustAllCerts trustAllCerts) throws NoSuchAlgorithmException,
|
private final TrustAllCerts trustAllCerts;
|
||||||
KeyManagementException {
|
|
||||||
SSLContext sc = SSLContext.getInstance("SSL");
|
@Inject
|
||||||
sc.init(null, new TrustManager[] { trustAllCerts }, new SecureRandom());
|
UntrustedSSLContextSupplier(TrustAllCerts trustAllCerts) {
|
||||||
return sc;
|
this.trustAllCerts = trustAllCerts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SSLContext get() {
|
||||||
|
try {
|
||||||
|
SSLContext sc;
|
||||||
|
sc = SSLContext.getInstance("SSL");
|
||||||
|
sc.init(null, new TrustManager[] { trustAllCerts }, new SecureRandom());
|
||||||
|
return sc;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Throwables.propagate(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,7 +44,6 @@ import java.util.concurrent.ExecutorService;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.net.ssl.HostnameVerifier;
|
import javax.net.ssl.HostnameVerifier;
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
@ -64,6 +63,7 @@ import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
import com.google.common.collect.LinkedHashMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
@ -79,7 +79,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
||||||
public static final String USER_AGENT = "jclouds/1.0 java/" + System.getProperty("java.version");
|
public static final String USER_AGENT = "jclouds/1.0 java/" + System.getProperty("java.version");
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
private final Provider<SSLContext> untrustedSSLContextProvider;
|
private final Supplier<SSLContext> untrustedSSLContextProvider;
|
||||||
private final HostnameVerifier verifier;
|
private final HostnameVerifier verifier;
|
||||||
private final Field methodField;
|
private final Field methodField;
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
|
||||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
||||||
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
|
DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
|
||||||
DelegatingErrorHandler errorHandler, HttpWire wire, HostnameVerifier verifier,
|
DelegatingErrorHandler errorHandler, HttpWire wire, HostnameVerifier verifier,
|
||||||
@Named("untrusted") Provider<SSLContext> untrustedSSLContextProvider) throws SecurityException,
|
@Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider) throws SecurityException,
|
||||||
NoSuchFieldException {
|
NoSuchFieldException {
|
||||||
super(utils, ioWorkerExecutor, retryHandler, ioRetryHandler, errorHandler, wire);
|
super(utils, ioWorkerExecutor, retryHandler, ioRetryHandler, errorHandler, wire);
|
||||||
if (utils.getMaxConnections() > 0)
|
if (utils.getMaxConnections() > 0)
|
||||||
|
|
|
@ -51,6 +51,7 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ public class BackoffLimitedRetryHandlerTest {
|
||||||
public boolean verify(String hostname, SSLSession session) {
|
public boolean verify(String hostname, SSLSession session) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}, new Provider<SSLContext>() {
|
}, new Supplier<SSLContext>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SSLContext get() {
|
public SSLContext get() {
|
||||||
|
|
Loading…
Reference in New Issue