use of org.openstack4j.core.transport.Config in project openstack4j by ContainX.
the class HttpCommand method populateHeaders.
private void populateHeaders() throws IOException {
if (request.getConfig() != null && request.getConfig().getProxy() != null) {
Config config = request.getConfig();
Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(config.getProxy().getRawHost(), config.getProxy().getPort()));
connection = (HttpURLConnection) connectionUrl.openConnection(proxy);
} else {
connection = (HttpURLConnection) connectionUrl.openConnection();
}
connection.setRequestProperty("Content-Type", request.getContentType());
connection.setRequestProperty("Accept", MediaType.JSON_UTF_8.toString());
if (!request.hasHeaders()) {
return;
}
for (Map.Entry<String, Object> h : request.getHeaders().entrySet()) {
connection.setRequestProperty(h.getKey(), String.valueOf(h.getValue()));
}
}
use of org.openstack4j.core.transport.Config in project openstack4j by ContainX.
the class HttpCommand method initialize.
private void initialize() {
OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
Config config = request.getConfig();
if (config.getProxy() != null) {
okHttpClientBuilder.proxy(new Proxy(Type.HTTP, new InetSocketAddress(config.getProxy().getRawHost(), config.getProxy().getPort())));
}
if (config.getConnectTimeout() > 0)
okHttpClientBuilder.connectTimeout(config.getConnectTimeout(), TimeUnit.MILLISECONDS);
if (config.getReadTimeout() > 0)
okHttpClientBuilder.readTimeout(config.getReadTimeout(), TimeUnit.MILLISECONDS);
if (config.isIgnoreSSLVerification()) {
okHttpClientBuilder.hostnameVerifier(UntrustedSSL.getHostnameVerifier());
okHttpClientBuilder.sslSocketFactory(UntrustedSSL.getSSLContext().getSocketFactory());
}
if (config.getSslContext() != null)
okHttpClientBuilder.sslSocketFactory(config.getSslContext().getSocketFactory());
if (config.getHostNameVerifier() != null)
okHttpClientBuilder.hostnameVerifier(config.getHostNameVerifier());
if (HttpLoggingFilter.isLoggingEnabled()) {
okHttpClientBuilder.addInterceptor(new LoggingInterceptor());
}
client = okHttpClientBuilder.build();
clientReq = new Request.Builder();
populateHeaders(request);
populateQueryParams(request);
}
use of org.openstack4j.core.transport.Config in project openstack4j by ContainX.
the class ServiceVersionTests method thatComputeV21IsReturned.
@Test
public void thatComputeV21IsReturned() {
Config config = Config.newConfig().withResolver(LatestServiceVersionResolver.INSTANCE);
assertTrue(session().useConfig(config).getEndpoint(ServiceType.COMPUTE).contains("/v2.1/"), "Endpoint was not version 2.1");
}
use of org.openstack4j.core.transport.Config in project openstack4j by ContainX.
the class ConfigTest method testUnequalConfigHostnameVerifier.
@Test
public void testUnequalConfigHostnameVerifier() {
Config firstConfig = Config.newConfig();
firstConfig.withHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// TODO Auto-generated method stub
return false;
}
});
Config secondConfig = Config.newConfig();
Assert.assertNotEquals(firstConfig, secondConfig);
}
use of org.openstack4j.core.transport.Config in project openstack4j by ContainX.
the class ConfigTest method testUnequalConfigSsl.
@Test
public void testUnequalConfigSsl() {
Config firstConfig = Config.newConfig();
try {
SSLContext firstSslContext = SSLContext.getInstance("SSL");
firstSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
firstConfig.withSSLContext(firstSslContext);
} catch (Exception e) {
e.printStackTrace();
}
Config secondConfig = Config.newConfig();
try {
SSLContext secondSslContext = SSLContext.getInstance("SSL");
secondSslContext.init(null, new TrustManager[] { null }, new SecureRandom());
secondConfig.withSSLContext(secondSslContext);
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertNotEquals(firstConfig, secondConfig);
}
Aggregations