use of io.vertx.core.http.HttpClientOptions in project strimzi by strimzi.
the class Main method isOnOpenShift.
static Future<Boolean> isOnOpenShift(Vertx vertx, KubernetesClient client) {
URL kubernetesApi = client.getMasterUrl();
Future<Boolean> fut = Future.future();
HttpClientOptions httpClientOptions = new HttpClientOptions();
httpClientOptions.setDefaultHost(kubernetesApi.getHost());
if (kubernetesApi.getPort() == -1) {
httpClientOptions.setDefaultPort(kubernetesApi.getDefaultPort());
} else {
httpClientOptions.setDefaultPort(kubernetesApi.getPort());
}
if (kubernetesApi.getProtocol().equals("https")) {
httpClientOptions.setSsl(true);
httpClientOptions.setTrustAll(true);
}
HttpClient httpClient = vertx.createHttpClient(httpClientOptions);
httpClient.getNow("/oapi", res -> {
if (res.statusCode() == HttpResponseStatus.OK.code()) {
log.debug("{} returned {}. We are on OpenShift.", res.request().absoluteURI(), res.statusCode());
// We should be on OpenShift based on the /oapi result. We can now safely try isAdaptable() to be 100% sure.
Boolean isOpenShift = Boolean.TRUE.equals(client.isAdaptable(OpenShiftClient.class));
fut.complete(isOpenShift);
} else {
log.debug("{} returned {}. We are not on OpenShift.", res.request().absoluteURI(), res.statusCode());
fut.complete(Boolean.FALSE);
}
});
return fut;
}
use of io.vertx.core.http.HttpClientOptions in project vertx-sync by vert-x3.
the class TestVerticle method testFiberHandler.
@Suspendable
protected void testFiberHandler() {
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestHandler(fiberHandler(req -> {
String res = awaitResult(h -> ai.methodWithParamsAndHandlerNoReturn("oranges", 23, h));
assertEquals("oranges23", res);
req.response().end();
}));
server.listen(res -> {
assertTrue(res.succeeded());
HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080));
client.getNow("/somepath", resp -> {
assertTrue(resp.statusCode() == 200);
client.close();
server.close(res2 -> {
complete();
});
});
});
}
use of io.vertx.core.http.HttpClientOptions in project java-chassis by ServiceComb.
the class TestVertxTLSBuilder method testbuildClientOptionsBase.
@Test
public void testbuildClientOptionsBase() {
SSLOption option = SSLOption.buildFromYaml("rest.consumer");
SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
HttpClientOptions serverOptions = new HttpClientOptions();
VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions);
Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
Assert.assertEquals(serverOptions.isTrustAll(), true);
}
use of io.vertx.core.http.HttpClientOptions in project java-chassis by ServiceComb.
the class TestVertxTLSBuilder method testbuildClientOptionsBaseSTORE_PKCS12.
@Test
public void testbuildClientOptionsBaseSTORE_PKCS12() {
SSLOption option = SSLOption.buildFromYaml("rest.consumer");
SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
HttpClientOptions serverOptions = new HttpClientOptions();
new MockUp<SSLOption>() {
@Mock
public String getTrustStoreType() {
return "PKCS12";
}
};
VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions);
Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
Assert.assertEquals(serverOptions.isTrustAll(), true);
}
use of io.vertx.core.http.HttpClientOptions in project java-chassis by ServiceComb.
the class TestVertxTLSBuilder method testbuildClientOptionsBaseFileNull.
@Test
public void testbuildClientOptionsBaseFileNull() {
SSLOption option = SSLOption.buildFromYaml("rest.consumer");
option.setKeyStore(null);
option.setTrustStore(null);
option.setCrl(null);
SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
HttpClientOptions serverOptions = new HttpClientOptions();
VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions);
Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
Assert.assertEquals(serverOptions.isTrustAll(), true);
}
Aggregations