use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project xray-maven-plugin by Xray-App.
the class CommonUtils method getHttpClient.
public static OkHttpClient getHttpClient(Boolean useInternalTestProxy, Boolean ignoreSslErrors, Integer timeout) throws Exception {
OkHttpClient client;
OkHttpClient.Builder newBuilder = new OkHttpClient.Builder();
if (isTrue(ignoreSslErrors) || isTrue(useInternalTestProxy)) {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
} };
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
newBuilder.sslSocketFactory(sslContext.getSocketFactory(), (X509TrustManager) trustAllCerts[0]);
newBuilder.hostnameVerifier((host, session) -> true);
}
if (isTrue(useInternalTestProxy)) {
String hostname = "localhost";
int port = 18080;
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(hostname, port));
client = newBuilder.connectTimeout(timeout, TimeUnit.SECONDS).readTimeout(timeout, TimeUnit.SECONDS).writeTimeout(timeout, TimeUnit.SECONDS).callTimeout(timeout, TimeUnit.SECONDS).proxy(proxy).build();
} else {
client = newBuilder.connectTimeout(timeout, TimeUnit.SECONDS).readTimeout(timeout, TimeUnit.SECONDS).writeTimeout(timeout, TimeUnit.SECONDS).callTimeout(timeout, TimeUnit.SECONDS).build();
}
return client;
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project hetu-core by openlookeng.
the class QueryRunner method startInternalQuery.
private StatementClient startInternalQuery(ClientSession session, String query) {
OkHttpClient.Builder builder = httpClient.newBuilder();
sslSetup.accept(builder);
OkHttpClient client = builder.build();
return newStatementClient(client, session, query);
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project hetu-core by openlookeng.
the class TestDataCenterClientAuth method assertToken.
private void assertToken(String accessToken) throws SQLException {
String serverUri = "https://localhost:" + this.server.getHttpsAddress().getPort();
DataCenterConfig config = new DataCenterConfig().setConnectionUrl(URI.create(serverUri)).setConnectionUser("test").setSsl(true).setAccessToken(accessToken).setSslTrustStorePath(getResource("localhost.truststore").getPath()).setSslTrustStorePassword("changeit");
OkHttpClient httpClient = DataCenterStatementClientFactory.newHttpClient(config);
try {
DataCenterClient client = new DataCenterClient(config, httpClient, typeManager);
Set<String> schemaNames = client.getSchemaNames("tpch");
assertTrue(schemaNames.contains("tiny"));
assertEquals(schemaNames.size(), 9);
} catch (Throwable t) {
if (t.getCause() instanceof SQLException) {
throw (SQLException) t.getCause();
}
throw t;
} finally {
httpClient.dispatcher().executorService().shutdown();
httpClient.connectionPool().evictAll();
}
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project junit-servers by mjeanroy.
the class OkHttpClientTest method it_should_implement_to_string.
@Test
void it_should_implement_to_string() {
final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
final HttpClient client = createDefaultClient(server);
final okhttp3.OkHttpClient internalClient = readPrivate(client, "client");
assertThat(client).hasToString("OkHttpClient{" + "configuration: HttpClientConfiguration{" + "followRedirect: true, " + "defaultHeaders: {}, " + "defaultCookies: []" + "}, " + "server: MockEmbeddedServer, " + "client: " + internalClient.toString() + ", " + "destroyed: false" + "}");
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project the-blue-alliance-android by the-blue-alliance.
the class HttpModule method getOkHttp.
@Provides
@Singleton
public OkHttpClient getOkHttp(Cache responseCache, APIv3RequestInterceptor interceptor) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.addInterceptor(interceptor);
if (Utilities.isDebuggable()) {
builder.addNetworkInterceptor(new StethoInterceptor());
}
builder.cache(responseCache);
return builder.build();
}
Aggregations