Search in sources :

Example 91 with HttpClientOptions

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;
}
Also used : HttpClient(io.vertx.core.http.HttpClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) URL(java.net.URL) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 92 with HttpClientOptions

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();
            });
        });
    });
}
Also used : VertxException(io.vertx.core.VertxException) Strand(co.paralleluniverse.strands.Strand) HttpServer(io.vertx.core.http.HttpServer) Context(io.vertx.core.Context) Is(org.hamcrest.core.Is) Channel(co.paralleluniverse.strands.channels.Channel) Suspendable(co.paralleluniverse.fibers.Suspendable) EventBus(io.vertx.core.eventbus.EventBus) SyncVerticle(io.vertx.ext.sync.SyncVerticle) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReturnedInterface(io.vertx.ext.sync.testmodel.ReturnedInterface) Channels(co.paralleluniverse.strands.channels.Channels) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Method(java.lang.reflect.Method) Sync(io.vertx.ext.sync.Sync) AsyncInterface(io.vertx.ext.sync.testmodel.AsyncInterface) Vertx(io.vertx.core.Vertx) HandlerReceiverAdaptor(io.vertx.ext.sync.HandlerReceiverAdaptor) Message(io.vertx.core.eventbus.Message) SuspendExecution(co.paralleluniverse.fibers.SuspendExecution) TimeUnit(java.util.concurrent.TimeUnit) ReceivePort(co.paralleluniverse.strands.channels.ReceivePort) HttpServerOptions(io.vertx.core.http.HttpServerOptions) AsyncInterfaceImpl(io.vertx.ext.sync.testmodel.AsyncInterfaceImpl) Assert(org.junit.Assert) HttpClient(io.vertx.core.http.HttpClient) HttpClient(io.vertx.core.http.HttpClient) HttpServer(io.vertx.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Suspendable(co.paralleluniverse.fibers.Suspendable)

Example 93 with HttpClientOptions

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);
}
Also used : SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption) SSLCustom(org.apache.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 94 with HttpClientOptions

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);
}
Also used : MockUp(mockit.MockUp) SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption) SSLCustom(org.apache.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 95 with HttpClientOptions

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);
}
Also used : SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption) SSLCustom(org.apache.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Aggregations

HttpClientOptions (io.vertx.core.http.HttpClientOptions)101 Test (org.junit.Test)51 HttpClient (io.vertx.core.http.HttpClient)27 HttpClientRequest (io.vertx.core.http.HttpClientRequest)23 HttpServerOptions (io.vertx.core.http.HttpServerOptions)19 CountDownLatch (java.util.concurrent.CountDownLatch)15 HttpMethod (io.vertx.core.http.HttpMethod)14 SSLCustom (org.apache.servicecomb.foundation.ssl.SSLCustom)14 SSLOption (org.apache.servicecomb.foundation.ssl.SSLOption)14 HttpVersion (io.vertx.core.http.HttpVersion)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 Vertx (io.vertx.core.Vertx)11 MockUp (mockit.MockUp)11 DeploymentOptions (io.vertx.core.DeploymentOptions)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Buffer (io.vertx.core.buffer.Buffer)9 HttpServer (io.vertx.core.http.HttpServer)8 HttpServerResponse (io.vertx.core.http.HttpServerResponse)8 VertxOptions (io.vertx.core.VertxOptions)7 VertxInternal (io.vertx.core.impl.VertxInternal)7