@Override protected void startInternal() { DisposableServer server = this.reactorServer.handle(this.reactorHandler).bind().block(); setPort(server.address().getPort()); this.serverRef.set(server); }
@Override protected void startInternal() { DisposableServer server = this.reactorServer.handle(this.reactorHandler).bind().block(); setPort(server.address().getPort()); this.serverRef.set(server); }
@Override protected void startInternal() { DisposableServer server = this.reactorServer.handle(this.reactorHandler).bind().block(); setPort(server.address().getPort()); this.serverRef.set(server); }
@Override public Mono<Closeable> start(ConnectionAcceptor acceptor) { Objects.requireNonNull(acceptor, "acceptor must not be null"); return server .route( routes -> { routesBuilder.accept(routes); routes.ws(path, newHandler(acceptor)); }) .bind() .map(CloseableChannel::new); }
@Override public Mono<CloseableChannel> start(ConnectionAcceptor acceptor) { Objects.requireNonNull(acceptor, "acceptor must not be null"); return server .handle( (request, response) -> { transportHeaders.get().forEach(response::addHeader); return response.sendWebsocket(WebsocketRouteTransport.newHandler(acceptor)); }) .bind() .map(CloseableChannel::new); } }
@Override protected Mono<? extends DisposableServer> bind(TcpServer b) { return source.bind(b); } }
@Override protected Mono<? extends DisposableServer> bind(TcpServer b) { return source.bind(b); } }
/** * Bind the {@link HttpServer} and return a {@link Mono} of {@link DisposableServer}. If * {@link Mono} is cancelled, the underlying binding will be aborted. Once the {@link * DisposableServer} has been emitted and is not necessary anymore, disposing main server * loop must be done by the user via {@link DisposableServer#dispose()}. * * If update configuration phase fails, a {@link Mono#error(Throwable)} will be returned * * @return a {@link Mono} of {@link DisposableServer} */ public final Mono<? extends DisposableServer> bind() { return bind(tcpConfiguration()); }
/** * Bind the {@link HttpServer} and return a {@link Mono} of {@link DisposableServer}. If * {@link Mono} is cancelled, the underlying binding will be aborted. Once the {@link * DisposableServer} has been emitted and is not necessary anymore, disposing main server * loop must be done by the user via {@link DisposableServer#dispose()}. * * If update configuration phase fails, a {@link Mono#error(Throwable)} will be returned * * @return a {@link Mono} of {@link DisposableServer} */ public final Mono<? extends DisposableServer> bind() { return bind(tcpConfiguration()); }
/** * Start a Server in a blocking fashion, and wait for it to finish initializing. The * returned {@link DisposableServer} offers simple server API, including to {@link * DisposableServer#disposeNow()} shut it down in a blocking fashion. * * @param timeout max startup timeout * * @return a {@link DisposableServer} */ public final DisposableServer bindNow(Duration timeout) { Objects.requireNonNull(timeout, "timeout"); try { return Objects.requireNonNull(bind().block(timeout), "aborted"); } catch (IllegalStateException e) { if (e.getMessage().contains("blocking read")) { throw new IllegalStateException("HttpServer couldn't be started within " + timeout.toMillis() + "ms"); } throw e; } }
/** * Start a Server in a blocking fashion, and wait for it to finish initializing. The * returned {@link DisposableServer} offers simple server API, including to {@link * DisposableServer#disposeNow()} shut it down in a blocking fashion. * * @param timeout max startup timeout * * @return a {@link DisposableServer} */ public final DisposableServer bindNow(Duration timeout) { Objects.requireNonNull(timeout, "timeout"); try { return Objects.requireNonNull(bind().block(timeout), "aborted"); } catch (IllegalStateException e) { if (e.getMessage().contains("blocking read")) { throw new IllegalStateException("HttpServer couldn't be started within " + timeout.toMillis() + "ms"); } throw e; } }
@Override public Mono<CloseableChannel> start(ConnectionAcceptor acceptor) { Objects.requireNonNull(acceptor, "acceptor must not be null"); return server .handle( (request, response) -> { transportHeaders.get().forEach(response::addHeader); return response.sendWebsocket(WebsocketRouteTransport.newHandler(acceptor)); }) .bind() .map(CloseableChannel::new); } }
@Override public Mono<Closeable> start(ConnectionAcceptor acceptor) { Objects.requireNonNull(acceptor, "acceptor must not be null"); return server .route( routes -> { routesBuilder.accept(routes); routes.ws(path, newHandler(acceptor)); }) .bind() .map(CloseableChannel::new); }
private void init() { HttpServer.create() .host(bindAddress) .port(bindPort) .route(routes -> routes.post(metricsUrl, this::handle).get(metricsUrl, this::handle)) .bind() .subscribe(); }
@Override public Mono<Gateway> start( GatewayConfig config, Executor workerPool, Call call, Metrics metrics) { return Mono.defer( () -> { LOGGER.info("Starting gateway with {}", config); GatewayMetrics metrics1 = new GatewayMetrics(config.name(), metrics); HttpGatewayAcceptor acceptor = new HttpGatewayAcceptor(call.create(), metrics1); if (workerPool != null) { loopResources = new GatewayLoopResources((EventLoopGroup) workerPool); } return prepareHttpServer(loopResources, config.port(), null /*metrics*/) .handle(acceptor) .bind() .doOnSuccess(server -> this.server = server) .doOnSuccess( server -> LOGGER.info( "HTTP Gateway has been started successfully on {}", server.address())) .thenReturn(this); }); }
@Override public Mono<Gateway> start( GatewayConfig config, Executor workerPool, Call call, Metrics metrics) { return Mono.defer( () -> { LOGGER.info("Starting gateway with {}", config); GatewayMetrics metrics1 = new GatewayMetrics(config.name(), metrics); WebsocketGatewayAcceptor acceptor = new WebsocketGatewayAcceptor(call.create(), metrics1); if (workerPool != null) { loopResources = new GatewayLoopResources((EventLoopGroup) workerPool); } return prepareHttpServer(loopResources, config.port(), metrics1) .handle(acceptor) .bind() .doOnSuccess(server -> this.server = server) .doOnSuccess( server -> LOGGER.info( "Websocket Gateway has been started successfully on {}", server.address())) .thenReturn(this); }); }
@Test public void testHttpNoSslH2Fails() { StepVerifier.create( HttpServer.create() .protocol(HttpProtocol.H2) .handle((req, res) -> res.sendString(Mono.just("Hello"))) .wiretap(true) .bind() ).verifyErrorMessage("Configured H2 protocol without TLS. Use" + " a clear-text h2 protocol via HttpServer#protocol or configure TLS" + " via HttpServer#secure"); }
@Test public void testHttpSslH2CFails() throws Exception { SelfSignedCertificate cert = new SelfSignedCertificate(); SslContextBuilder serverOptions = SslContextBuilder.forServer(cert.certificate(), cert.privateKey()); StepVerifier.create( HttpServer.create() .protocol(HttpProtocol.H2C) .secure(ssl -> ssl.sslContext(serverOptions)) .handle((req, res) -> res.sendString(Mono.just("Hello"))) .wiretap(true) .bind() ).verifyErrorMessage("Configured H2 Clear-Text protocol with TLS. Use the non clear-text h2 protocol via HttpServer#protocol or disable TLS via HttpServer#tcpConfiguration(tcp -> tcp.noSSL())"); }