use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class SSLHelper method getTrustMgrFactory.
private TrustManagerFactory getTrustMgrFactory(VertxInternal vertx) throws Exception {
TrustManagerFactory fact;
if (trustAll) {
TrustManager[] mgrs = new TrustManager[] { createTrustAllTrustManager() };
fact = new VertxTrustManagerFactory(mgrs);
} else if (trustOptions != null) {
fact = trustOptions.getTrustManagerFactory(vertx);
} else {
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())));
}
TrustManager[] mgrs = createUntrustRevokedCertTrustManager(fact.getTrustManagers(), crls);
fact = new VertxTrustManagerFactory(mgrs);
}
return fact;
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HostnameResolutionTest method testMultipleSearchDomain.
@Test
public void testMultipleSearchDomain() throws Exception {
Map<String, String> records = new HashMap<>();
records.put("host1.foo.com", "127.0.0.1");
records.put("host2.bar.com", "127.0.0.2");
records.put("host3.bar.com", "127.0.0.3");
records.put("host3.foo.com", "127.0.0.4");
dnsServer.stop();
dnsServer = FakeDNSServer.testResolveA(records);
dnsServer.start();
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).addSearchDomain("foo.com").addSearchDomain("bar.com")));
// "host1" resolves via the "foo.com" search path
CountDownLatch latch1 = new CountDownLatch(1);
vertx.resolveAddress("host1", onSuccess(resolved -> {
assertEquals("127.0.0.1", resolved.getHostAddress());
latch1.countDown();
}));
awaitLatch(latch1);
// "host2" resolves via the "bar.com" search path
CountDownLatch latch2 = new CountDownLatch(1);
vertx.resolveAddress("host2", onSuccess(resolved -> {
assertEquals("127.0.0.2", resolved.getHostAddress());
latch2.countDown();
}));
awaitLatch(latch2);
// "host3" resolves via the the "foo.com" search path as it is the first one
CountDownLatch latch3 = new CountDownLatch(1);
vertx.resolveAddress("host3", onSuccess(resolved -> {
assertEquals("127.0.0.4", resolved.getHostAddress());
latch3.countDown();
}));
awaitLatch(latch3);
// "host4" does not resolve
vertx.resolveAddress("host4", onFailure(cause -> {
assertTrue(cause instanceof UnknownHostException);
testComplete();
}));
await();
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HostnameResolutionTest method testSearchDomainWithNdots0.
@Test
public void testSearchDomainWithNdots0() throws Exception {
Map<String, String> records = new HashMap<>();
records.put("host1", "127.0.0.2");
records.put("host1.foo.com", "127.0.0.3");
dnsServer.stop();
dnsServer = FakeDNSServer.testResolveA(records);
dnsServer.start();
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().addServer(dnsServerAddress.getAddress().getHostAddress() + ":" + dnsServerAddress.getPort()).setOptResourceEnabled(false).addSearchDomain("foo.com").setNdots(0)));
// "host1" resolves directly as ndots = 0
CountDownLatch latch1 = new CountDownLatch(1);
vertx.resolveAddress("host1", onSuccess(resolved -> {
assertEquals("127.0.0.2", resolved.getHostAddress());
latch1.countDown();
}));
awaitLatch(latch1);
// "host1.foo.com" resolves to host1.foo.com
CountDownLatch latch2 = new CountDownLatch(1);
vertx.resolveAddress("host1.foo.com", onSuccess(resolved -> {
assertEquals("127.0.0.3", resolved.getHostAddress());
latch2.countDown();
}));
awaitLatch(latch2);
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HostnameResolutionTest method testResolveFromBuffer.
@Test
public void testResolveFromBuffer() {
VertxInternal vertx = (VertxInternal) vertx(new VertxOptions().setAddressResolverOptions(new AddressResolverOptions().setHostsValue(Buffer.buffer("192.168.0.15 server.net"))));
vertx.resolveAddress("server.net", onSuccess(addr -> {
assertEquals("192.168.0.15", addr.getHostAddress());
assertEquals("server.net", addr.getHostName());
testComplete();
}));
await();
}
use of io.vertx.core.impl.VertxInternal in project vert.x by eclipse.
the class HostnameResolutionTest method testAsyncResolveConnectIsNotifiedOnChannelEventLoop.
@Test
public void testAsyncResolveConnectIsNotifiedOnChannelEventLoop() throws Exception {
CountDownLatch listenLatch = new CountDownLatch(1);
NetServer s = vertx.createNetServer().connectHandler(so -> {
});
s.listen(1234, "localhost", onSuccess(v -> listenLatch.countDown()));
awaitLatch(listenLatch);
AtomicReference<Thread> channelThread = new AtomicReference<>();
CountDownLatch connectLatch = new CountDownLatch(1);
Bootstrap bootstrap = new Bootstrap();
bootstrap.channel(NioSocketChannel.class);
bootstrap.group(vertx.nettyEventLoopGroup());
bootstrap.resolver(((VertxInternal) vertx).nettyAddressResolverGroup());
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
channelThread.set(Thread.currentThread());
connectLatch.countDown();
}
});
ChannelFuture channelFut = bootstrap.connect("localhost", 1234);
awaitLatch(connectLatch);
channelFut.addListener(v -> {
assertTrue(v.isSuccess());
assertEquals(channelThread.get(), Thread.currentThread());
testComplete();
});
await();
}
Aggregations