Search in sources :

Example 26 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class VertxTracerFactoryTest method testNoOptions.

@Test
public void testNoOptions() {
    VertxInternal v = (VertxInternal) Vertx.vertx();
    assertNull(v.tracer());
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) Test(org.junit.Test)

Example 27 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class MetricsOptionsTest method testMetricsFromServiceLoader.

@Test
public void testMetricsFromServiceLoader() {
    vertx.close();
    MetricsOptions metricsOptions = new MetricsOptions().setEnabled(true);
    VertxOptions options = new VertxOptions().setMetricsOptions(metricsOptions);
    vertx = createVertxLoadingMetricsFromMetaInf(options, "io.vertx.test.fakemetrics.FakeMetricsFactory");
    VertxMetrics metrics = ((VertxInternal) vertx).metricsSPI();
    assertNotNull(metrics);
    assertTrue(metrics instanceof FakeVertxMetrics);
    assertEquals(metricsOptions.isEnabled(), ((FakeVertxMetrics) metrics).options().isEnabled());
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) FakeVertxMetrics(io.vertx.test.fakemetrics.FakeVertxMetrics) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) VertxInternal(io.vertx.core.impl.VertxInternal) FakeVertxMetrics(io.vertx.test.fakemetrics.FakeVertxMetrics) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 28 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class MetricsOptionsTest method testMetricsEnabledWithoutConfig.

@Test
public void testMetricsEnabledWithoutConfig() {
    vertx.close();
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true)));
    VertxMetrics metrics = ((VertxInternal) vertx).metricsSPI();
    assertNull(metrics);
}
Also used : MetricsOptions(io.vertx.core.metrics.MetricsOptions) FakeVertxMetrics(io.vertx.test.fakemetrics.FakeVertxMetrics) DummyVertxMetrics(io.vertx.core.metrics.impl.DummyVertxMetrics) VertxInternal(io.vertx.core.impl.VertxInternal) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 29 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class SSLHelper method getTrustMgrFactory.

private TrustManagerFactory getTrustMgrFactory(VertxInternal vertx, String serverName) throws Exception {
    TrustManager[] mgrs = null;
    if (trustAll) {
        mgrs = new TrustManager[] { createTrustAllTrustManager() };
    } else if (trustOptions != null) {
        if (serverName != null) {
            Function<String, TrustManager[]> mapper = trustOptions.trustManagerMapper(vertx);
            if (mapper != null) {
                mgrs = mapper.apply(serverName);
            }
            if (mgrs == null) {
                TrustManagerFactory fact = trustOptions.getTrustManagerFactory(vertx);
                if (fact != null) {
                    mgrs = fact.getTrustManagers();
                }
            }
        } else {
            TrustManagerFactory fact = trustOptions.getTrustManagerFactory(vertx);
            if (fact != null) {
                mgrs = fact.getTrustManagers();
            }
        }
    }
    if (mgrs == null) {
        return null;
    }
    if (crlPaths != null && crlValues != null && (crlPaths.size() > 0 || crlValues.size() > 0)) {
        Stream<Buffer> tmp = crlPaths.stream().map(path -> vertx.resolveFile(path).getAbsolutePath()).map(vertx.fileSystem()::readFileBlocking);
        tmp = Stream.concat(tmp, crlValues.stream());
        CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
        ArrayList<CRL> crls = new ArrayList<>();
        for (Buffer crlValue : tmp.collect(Collectors.toList())) {
            crls.addAll(certificatefactory.generateCRLs(new ByteArrayInputStream(crlValue.getBytes())));
        }
        mgrs = createUntrustRevokedCertTrustManager(mgrs, crls);
    }
    return new VertxTrustManagerFactory(mgrs);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) VertxException(io.vertx.core.VertxException) X509Certificate(java.security.cert.X509Certificate) java.util(java.util) LoggerFactory(io.vertx.core.impl.logging.LoggerFactory) CertificateFactory(java.security.cert.CertificateFactory) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Function(java.util.function.Function) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) ByteArrayInputStream(java.io.ByteArrayInputStream) KeyCertOptions(io.vertx.core.net.KeyCertOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) CRL(java.security.cert.CRL) Mapping(io.netty.util.Mapping) JdkSSLEngineOptions(io.vertx.core.net.JdkSSLEngineOptions) SocketAddress(io.vertx.core.net.SocketAddress) TCPSSLOptions(io.vertx.core.net.TCPSSLOptions) Logger(io.vertx.core.impl.logging.Logger) SSLEngineOptions(io.vertx.core.net.SSLEngineOptions) VertxInternal(io.vertx.core.impl.VertxInternal) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CertificateException(java.security.cert.CertificateException) io.netty.handler.ssl(io.netty.handler.ssl) Collectors(java.util.stream.Collectors) NetClientOptions(io.vertx.core.net.NetClientOptions) TimeUnit(java.util.concurrent.TimeUnit) TrustOptions(io.vertx.core.net.TrustOptions) NetServerOptions(io.vertx.core.net.NetServerOptions) Certificate(java.security.cert.Certificate) Stream(java.util.stream.Stream) Buffer(io.vertx.core.buffer.Buffer) ClientOptionsBase(io.vertx.core.net.ClientOptionsBase) ClientAuth(io.vertx.core.http.ClientAuth) javax.net.ssl(javax.net.ssl) CertificateFactory(java.security.cert.CertificateFactory) Function(java.util.function.Function) ByteArrayInputStream(java.io.ByteArrayInputStream) CRL(java.security.cert.CRL)

Example 30 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.

the class ChannelProvider method handleConnect.

private void handleConnect(Handler<Channel> handler, SocketAddress remoteAddress, SocketAddress peerAddress, String serverName, boolean ssl, boolean useAlpn, Promise<Channel> channelHandler) {
    VertxInternal vertx = context.owner();
    bootstrap.resolver(vertx.nettyAddressResolverGroup());
    bootstrap.handler(new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) {
            initSSL(handler, peerAddress, serverName, ssl, useAlpn, ch, channelHandler);
        }
    });
    ChannelFuture fut = bootstrap.connect(vertx.transport().convert(remoteAddress));
    fut.addListener(res -> {
        if (res.isSuccess()) {
            connected(handler, fut.channel(), ssl, channelHandler);
        } else {
            channelHandler.setFailure(res.cause());
        }
    });
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal)

Aggregations

VertxInternal (io.vertx.core.impl.VertxInternal)100 Test (org.junit.Test)73 CountDownLatch (java.util.concurrent.CountDownLatch)46 VertxOptions (io.vertx.core.VertxOptions)30 JsonObject (io.vertx.core.json.JsonObject)29 Buffer (io.vertx.core.buffer.Buffer)28 File (java.io.File)27 AtomicReference (java.util.concurrent.atomic.AtomicReference)27 VertxException (io.vertx.core.VertxException)24 HttpClient (io.vertx.core.http.HttpClient)24 NetClient (io.vertx.core.net.NetClient)24 TimeUnit (java.util.concurrent.TimeUnit)24 NetServerOptions (io.vertx.core.net.NetServerOptions)23 InetAddress (java.net.InetAddress)23 Channel (io.netty.channel.Channel)22 InetSocketAddress (java.net.InetSocketAddress)22 CompletableFuture (java.util.concurrent.CompletableFuture)22 NetServer (io.vertx.core.net.NetServer)21 ChannelFuture (io.netty.channel.ChannelFuture)20 Bootstrap (io.netty.bootstrap.Bootstrap)19