Search in sources :

Example 1 with HttpServerImpl

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

the class SSLEngineTest method doTest.

private void doTest(SSLEngineOptions engine, boolean useAlpn, HttpVersion version, String error, String expectedSslContext, boolean expectCause) {
    server.close();
    HttpServerOptions options = new HttpServerOptions().setSslEngineOptions(engine).setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setKeyCertOptions(Cert.SERVER_PEM.get()).setSsl(true).setUseAlpn(useAlpn);
    server = vertx.createHttpServer(options);
    server.requestHandler(req -> {
        assertEquals(req.version(), version);
        assertTrue(req.isSSL());
        req.response().end();
    });
    try {
        startServer();
        if (error != null) {
            fail("Was expecting failure: " + error);
        }
    } catch (Exception e) {
        if (error == null) {
            fail(e);
        } else {
            assertEquals(error, e.getMessage());
            if (expectCause) {
                assertNotSame(e, e.getCause());
            }
            return;
        }
    }
    SSLHelper sslHelper = ((HttpServerImpl) server).sslHelper();
    SslContext ctx = sslHelper.getContext((VertxInternal) vertx);
    switch(expectedSslContext != null ? expectedSslContext : "jdk") {
        case "jdk":
            assertTrue(ctx instanceof JdkSslContext);
            break;
        case "openssl":
            assertTrue(ctx instanceof OpenSslContext);
            break;
    }
    client = vertx.createHttpClient(new HttpClientOptions().setSslEngineOptions(engine).setSsl(true).setUseAlpn(useAlpn).setTrustAll(true).setProtocolVersion(version));
    client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", onSuccess(req -> {
        req.send(onSuccess(resp -> {
            assertEquals(200, resp.statusCode());
            testComplete();
        }));
    }));
    await();
}
Also used : SSLHelper(io.vertx.core.net.impl.SSLHelper) VertxException(io.vertx.core.VertxException) HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) SSLEngineOptions(io.vertx.core.net.SSLEngineOptions) VertxInternal(io.vertx.core.impl.VertxInternal) JdkSslContext(io.netty.handler.ssl.JdkSslContext) SslContext(io.netty.handler.ssl.SslContext) OpenSslContext(io.netty.handler.ssl.OpenSslContext) Test(org.junit.Test) SSLHelper(io.vertx.core.net.impl.SSLHelper) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) HttpTestBase(io.vertx.core.http.HttpTestBase) HttpVersion(io.vertx.core.http.HttpVersion) HttpMethod(io.vertx.core.http.HttpMethod) Cert(io.vertx.test.tls.Cert) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) JdkSSLEngineOptions(io.vertx.core.net.JdkSSLEngineOptions) JdkSslContext(io.netty.handler.ssl.JdkSslContext) OpenSslContext(io.netty.handler.ssl.OpenSslContext) HttpServerOptions(io.vertx.core.http.HttpServerOptions) VertxException(io.vertx.core.VertxException) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) JdkSslContext(io.netty.handler.ssl.JdkSslContext) SslContext(io.netty.handler.ssl.SslContext) OpenSslContext(io.netty.handler.ssl.OpenSslContext)

Example 2 with HttpServerImpl

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

the class HttpConnectionEarlyResetTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    CountDownLatch listenLatch = new CountDownLatch(1);
    httpServer = vertx.createHttpServer().requestHandler(request -> {
    }).listen(8080, onSuccess(server -> listenLatch.countDown()));
    ((HttpServerImpl) httpServer).setConnectionExceptionHandler(t -> {
        caught.set(t);
        resetLatch.countDown();
    });
    awaitLatch(listenLatch);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl)

Example 3 with HttpServerImpl

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

the class SSLEngineTest method doTest.

private void doTest(SSLEngineOptions engine, boolean useAlpn, HttpVersion version, String error, String expectedSslContext, boolean expectCause) {
    server.close();
    HttpServerOptions options = new HttpServerOptions().setSslEngineOptions(engine).setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setKeyCertOptions(Cert.SERVER_PEM.get()).setSsl(true).setUseAlpn(useAlpn);
    try {
        server = vertx.createHttpServer(options);
    } catch (VertxException e) {
        e.printStackTrace();
        if (error == null) {
            fail(e);
        } else {
            assertEquals(error, e.getMessage());
            if (expectCause) {
                assertNotSame(e, e.getCause());
            }
        }
        return;
    }
    server.requestHandler(req -> {
        assertEquals(req.version(), version);
        assertTrue(req.isSSL());
        req.response().end();
    });
    server.listen(onSuccess(s -> {
        HttpServerImpl impl = (HttpServerImpl) s;
        SSLHelper sslHelper = impl.getSslHelper();
        SslContext ctx = sslHelper.getContext((VertxInternal) vertx);
        switch(expectedSslContext) {
            case "jdk":
                assertTrue(ctx instanceof JdkSslContext);
                break;
            case "openssl":
                assertTrue(ctx instanceof OpenSslContext);
                break;
        }
        client = vertx.createHttpClient(new HttpClientOptions().setSslEngineOptions(engine).setSsl(true).setUseAlpn(useAlpn).setTrustAll(true).setProtocolVersion(version));
        client.getNow(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath", resp -> {
            assertEquals(200, resp.statusCode());
            testComplete();
        });
    }));
    await();
}
Also used : VertxException(io.vertx.core.VertxException) HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) SSLEngineOptions(io.vertx.core.net.SSLEngineOptions) VertxInternal(io.vertx.core.impl.VertxInternal) JdkSslContext(io.netty.handler.ssl.JdkSslContext) SslContext(io.netty.handler.ssl.SslContext) OpenSslContext(io.netty.handler.ssl.OpenSslContext) Test(org.junit.Test) Cert(io.vertx.test.core.tls.Cert) SSLHelper(io.vertx.core.net.impl.SSLHelper) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) HttpTestBase(io.vertx.test.core.HttpTestBase) HttpVersion(io.vertx.core.http.HttpVersion) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) JdkSSLEngineOptions(io.vertx.core.net.JdkSSLEngineOptions) SSLHelper(io.vertx.core.net.impl.SSLHelper) VertxInternal(io.vertx.core.impl.VertxInternal) JdkSslContext(io.netty.handler.ssl.JdkSslContext) VertxException(io.vertx.core.VertxException) OpenSslContext(io.netty.handler.ssl.OpenSslContext) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpServerImpl(io.vertx.core.http.impl.HttpServerImpl) JdkSslContext(io.netty.handler.ssl.JdkSslContext) SslContext(io.netty.handler.ssl.SslContext) OpenSslContext(io.netty.handler.ssl.OpenSslContext)

Aggregations

HttpServerImpl (io.vertx.core.http.impl.HttpServerImpl)3 JdkSslContext (io.netty.handler.ssl.JdkSslContext)2 OpenSslContext (io.netty.handler.ssl.OpenSslContext)2 SslContext (io.netty.handler.ssl.SslContext)2 VertxException (io.vertx.core.VertxException)2 HttpClientOptions (io.vertx.core.http.HttpClientOptions)2 HttpServerOptions (io.vertx.core.http.HttpServerOptions)2 HttpVersion (io.vertx.core.http.HttpVersion)2 VertxInternal (io.vertx.core.impl.VertxInternal)2 JdkSSLEngineOptions (io.vertx.core.net.JdkSSLEngineOptions)2 OpenSSLEngineOptions (io.vertx.core.net.OpenSSLEngineOptions)2 SSLEngineOptions (io.vertx.core.net.SSLEngineOptions)2 SSLHelper (io.vertx.core.net.impl.SSLHelper)2 Test (org.junit.Test)2 HttpMethod (io.vertx.core.http.HttpMethod)1 HttpTestBase (io.vertx.core.http.HttpTestBase)1 HttpTestBase (io.vertx.test.core.HttpTestBase)1 Cert (io.vertx.test.core.tls.Cert)1 Cert (io.vertx.test.tls.Cert)1 CountDownLatch (java.util.concurrent.CountDownLatch)1