Skip to content

Instantly share code, notes, and snippets.

@alexlehm
Created July 11, 2016 23:30
Show Gist options
  • Save alexlehm/8b609f70c848453ab7da5b360b740db0 to your computer and use it in GitHub Desktop.
Save alexlehm/8b609f70c848453ab7da5b360b740db0 to your computer and use it in GitHub Desktop.
NetClientTLSConnectTest.java
package cx.lehmann.vertx;
import org.junit.Test;
import org.junit.runner.RunWith;
import io.vertx.core.Vertx;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.core.net.NetClient;
import io.vertx.core.net.NetClientOptions;
import io.vertx.core.net.NetSocket;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
@RunWith(VertxUnitRunner.class)
public class NetClientTLSConnectTest {
private static final Logger log = LoggerFactory.getLogger(NetClientTLSConnectTest.class);
private Vertx vertx = Vertx.vertx();
@Test
public void test(TestContext context) {
log.info("test starting");
Async async = context.async();
NetClientOptions options = new NetClientOptions();
options.setHostnameVerificationAlgorithm("HTTPS");
NetClient client = vertx.createNetClient(options);
client.connect(443, "www.yahoo.com", ar -> {
if (ar.succeeded()) {
NetSocket ns = ar.result();
ns.exceptionHandler(th -> {
context.fail(th);
});
ns.upgradeToSsl(v -> {
log.info("connect succeeded");
async.complete();
});
} else {
context.fail(ar.cause());
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment