Search in sources :

Example 21 with HttpServerOptions

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

the class HTTP2Examples method example0.

public void example0(Vertx vertx) {
    HttpServerOptions options = new HttpServerOptions().setUseAlpn(true).setSsl(true).setKeyStoreOptions(new JksOptions().setPath("/path/to/my/keystore"));
    HttpServer server = vertx.createHttpServer(options);
}
Also used : JksOptions(io.vertx.core.net.JksOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpServer(io.vertx.core.http.HttpServer)

Example 22 with HttpServerOptions

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

the class HttpTest method testListenInvalidPort.

@Test
public void testListenInvalidPort() throws Exception {
    /* Port 7 is free for use by any application in Windows, so this test fails. */
    Assume.assumeFalse(System.getProperty("os.name").startsWith("Windows"));
    server.close();
    server = vertx.createHttpServer(new HttpServerOptions().setPort(7));
    server.requestHandler(noOpHandler()).listen(onFailure(server -> testComplete()));
    await();
}
Also used : VertxException(io.vertx.core.VertxException) MultiMap(io.vertx.core.MultiMap) TimeoutException(java.util.concurrent.TimeoutException) Context(io.vertx.core.Context) InetAddress(java.net.InetAddress) HttpFrame(io.vertx.core.http.HttpFrame) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestLoggerFactory(io.vertx.test.netty.TestLoggerFactory) HttpHeaders(io.vertx.core.http.HttpHeaders) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) UUID(java.util.UUID) Future(io.vertx.core.Future) FileNotFoundException(java.io.FileNotFoundException) Nullable(io.vertx.codegen.annotations.Nullable) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpServerResponse(io.vertx.core.http.HttpServerResponse) AbstractVerticle(io.vertx.core.AbstractVerticle) WorkerContext(io.vertx.core.impl.WorkerContext) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) IntStream(java.util.stream.IntStream) HeadersAdaptor(io.vertx.core.http.impl.HeadersAdaptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) TestUtils.assertNullPointerException(io.vertx.test.core.TestUtils.assertNullPointerException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) OutputStreamWriter(java.io.OutputStreamWriter) Assume(org.junit.Assume) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpConnection(io.vertx.core.http.HttpConnection) BufferedWriter(java.io.BufferedWriter) Vertx(io.vertx.core.Vertx) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) EventLoopContext(io.vertx.core.impl.EventLoopContext) URLEncoder(java.net.URLEncoder) Rule(org.junit.Rule) DeploymentOptions(io.vertx.core.DeploymentOptions) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) InternalLoggerFactory(io.netty.util.internal.logging.InternalLoggerFactory) Handler(io.vertx.core.Handler) Collections(java.util.Collections) TestUtils.assertIllegalStateException(io.vertx.test.core.TestUtils.assertIllegalStateException) TemporaryFolder(org.junit.rules.TemporaryFolder) TestUtils.assertIllegalArgumentException(io.vertx.test.core.TestUtils.assertIllegalArgumentException) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Test(org.junit.Test)

Example 23 with HttpServerOptions

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

the class Http2Test method testServerOpenSSL.

@Test
public void testServerOpenSSL() throws Exception {
    HttpServerOptions opts = new HttpServerOptions().setPort(DEFAULT_HTTPS_PORT).setHost(DEFAULT_HTTPS_HOST).setUseAlpn(true).setSsl(true).addEnabledCipherSuite(// Non Diffie-helman -> debuggable in wireshark
    "TLS_RSA_WITH_AES_128_CBC_SHA").setPemKeyCertOptions(Cert.SERVER_PEM.get()).setSslEngineOptions(new OpenSSLEngineOptions());
    server.close();
    client.close();
    client = vertx.createHttpClient(createBaseClientOptions());
    server = vertx.createHttpServer(opts);
    server.requestHandler(req -> {
        req.response().end();
    });
    CountDownLatch latch = new CountDownLatch(1);
    System.out.println("starting");
    try {
        server.listen(onSuccess(v -> latch.countDown()));
    } catch (Throwable e) {
        e.printStackTrace();
    }
    System.out.println("listening");
    awaitLatch(latch);
    client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
        assertEquals(200, resp.statusCode());
        testComplete();
    }).exceptionHandler(this::fail).end();
    await();
}
Also used : Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) Http2Settings(io.vertx.core.http.Http2Settings) Cert(io.vertx.test.core.tls.Cert) Context(io.vertx.core.Context) TimeUnit(java.util.concurrent.TimeUnit) HttpClientRequest(io.vertx.core.http.HttpClientRequest) CountDownLatch(java.util.concurrent.CountDownLatch) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) Buffer(io.vertx.core.buffer.Buffer) NetServer(io.vertx.core.net.NetServer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpServerResponse(io.vertx.core.http.HttpServerResponse) PemKeyCertOptions(io.vertx.core.net.PemKeyCertOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) StreamResetException(io.vertx.core.http.StreamResetException) HttpServerOptions(io.vertx.core.http.HttpServerOptions) CountDownLatch(java.util.concurrent.CountDownLatch) OpenSSLEngineOptions(io.vertx.core.net.OpenSSLEngineOptions) Test(org.junit.Test)

Example 24 with HttpServerOptions

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

the class HttpTest method testUseInMultithreadedWorker.

@Test
public void testUseInMultithreadedWorker() throws Exception {
    class MyVerticle extends AbstractVerticle {

        @Override
        public void start() {
            assertIllegalStateException(() -> server = vertx.createHttpServer(new HttpServerOptions()));
            assertIllegalStateException(() -> client = vertx.createHttpClient(new HttpClientOptions()));
            testComplete();
        }
    }
    MyVerticle verticle = new MyVerticle();
    vertx.deployVerticle(verticle, new DeploymentOptions().setWorker(true).setMultiThreaded(true));
    await();
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 25 with HttpServerOptions

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

the class HttpMetricsTest method testServerConnectionClosed.

private void testServerConnectionClosed(HttpVersion protocol) throws Exception {
    server.close();
    server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setIdleTimeout(2));
    server.requestHandler(req -> {
        FakeHttpServerMetrics metrics = FakeMetricsBase.getMetrics(server);
        HttpServerMetric metric = metrics.getMetric(req);
        assertNotNull(metric);
        assertFalse(metric.failed.get());
        req.response().closeHandler(v -> {
            assertNull(metrics.getMetric(req));
            assertTrue(metric.failed.get());
            testComplete();
        });
    });
    startServer();
    client = vertx.createHttpClient(new HttpClientOptions().setProtocolVersion(protocol));
    HttpClientRequest req = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
    req.handler(resp -> {
    }).end();
    await();
}
Also used : FakeMetricsBase(io.vertx.test.fakemetrics.FakeMetricsBase) FakeMetricsFactory(io.vertx.test.fakemetrics.FakeMetricsFactory) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) HttpServer(io.vertx.core.http.HttpServer) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpClientRequest(io.vertx.core.http.HttpClientRequest) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) CountDownLatch(java.util.concurrent.CountDownLatch) Buffer(io.vertx.core.buffer.Buffer) MetricsOptions(io.vertx.core.metrics.MetricsOptions) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerResponse(io.vertx.core.http.HttpServerResponse) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpClientMetric(io.vertx.test.fakemetrics.HttpClientMetric) HttpClient(io.vertx.core.http.HttpClient) FakeHttpClientMetrics(io.vertx.test.fakemetrics.FakeHttpClientMetrics) HttpClientRequest(io.vertx.core.http.HttpClientRequest) FakeHttpServerMetrics(io.vertx.test.fakemetrics.FakeHttpServerMetrics) HttpServerMetric(io.vertx.test.fakemetrics.HttpServerMetric) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Aggregations

HttpServerOptions (io.vertx.core.http.HttpServerOptions)27 Test (org.junit.Test)20 HttpClientOptions (io.vertx.core.http.HttpClientOptions)11 HttpServer (io.vertx.core.http.HttpServer)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 HttpClient (io.vertx.core.http.HttpClient)8 Buffer (io.vertx.core.buffer.Buffer)7 HttpClientRequest (io.vertx.core.http.HttpClientRequest)7 HttpMethod (io.vertx.core.http.HttpMethod)7 HttpServerResponse (io.vertx.core.http.HttpServerResponse)7 Context (io.vertx.core.Context)6 Vertx (io.vertx.core.Vertx)6 HttpVersion (io.vertx.core.http.HttpVersion)6 NetSocket (io.vertx.core.net.NetSocket)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Handler (io.vertx.core.Handler)5 MultiMap (io.vertx.core.MultiMap)5 SSLHelper (io.vertx.core.net.impl.SSLHelper)5 AbstractVerticle (io.vertx.core.AbstractVerticle)4