Search in sources :

Example 26 with HttpServerOptions

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

the class HttpRequestStreamTest method testClosingServerClosesRequestStreamEndHandler.

@Test
public void testClosingServerClosesRequestStreamEndHandler() {
    this.server = vertx.createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT));
    ReadStream<HttpServerRequest> stream = server.requestStream();
    AtomicBoolean closed = new AtomicBoolean();
    stream.endHandler(v -> closed.set(true));
    stream.handler(req -> {
    });
    server.listen(ar -> {
        assertTrue(ar.succeeded());
        assertFalse(closed.get());
        server.close(v -> {
            assertTrue(ar.succeeded());
            assertTrue(closed.get());
            testComplete();
        });
    });
    await();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpServerRequest(io.vertx.core.http.HttpServerRequest) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Test(org.junit.Test)

Example 27 with HttpServerOptions

use of io.vertx.core.http.HttpServerOptions in project java-chassis by ServiceComb.

the class GrpcVerticle method startListen.

protected void startListen(Future<Void> startFuture) {
    // 如果本地未配置grpc地址,则表示不必监听,只需要作为客户端使用即可
    if (StringUtils.isEmpty(this.endpoint)) {
        LOGGER.warn("grpc listen address is not configured, will not listen.");
        startFuture.complete();
        return;
    }
    Router mainRouter = Router.router(vertx);
    mainRouter.route().handler(new GrpcBodyHandler());
    new GrpcServer(mainRouter);
    HttpServerOptions serverOptions = new HttpServerOptions();
    serverOptions.setAcceptBacklog(ACCEPT_BACKLOG);
    serverOptions.setSendBufferSize(SEND_BUFFER_SIZE);
    serverOptions.setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
    serverOptions.setUsePooledBuffers(true);
    String key = System.getProperty("store.key");
    if (key != null && !key.isEmpty()) {
        serverOptions.setUseAlpn(true);
        serverOptions.setSsl(true);
        serverOptions.setKeyStoreOptions(new JksOptions().setPath(System.getProperty("store.key")).setPassword(System.getProperty("store.pass")));
    }
    HttpServer server = vertx.createHttpServer(serverOptions).requestHandler(mainRouter::accept);
    IpPort ipPort = NetUtils.parseIpPortFromURI(this.endpoint);
    if (ipPort == null) {
        LOGGER.error("wrong grpc listen address {}", this.endpoint);
        return;
    }
    startListen(server, ipPort, startFuture);
}
Also used : JksOptions(io.vertx.core.net.JksOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) IpPort(io.servicecomb.foundation.common.net.IpPort)

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