@Override protected void initServer() throws Exception { SelfSignedCertificate cert = new SelfSignedCertificate(); SslContextBuilder builder = SslContextBuilder.forServer(cert.certificate(), cert.privateKey()); this.reactorHandler = createHttpHandlerAdapter(); this.reactorServer = reactor.netty.http.server.HttpServer.create() .host(getHost()) .port(getPort()) .secure(spec -> spec.sslContext(builder).defaultConfiguration(DefaultConfigurationType.TCP)); }
@Override protected void initServer() { this.reactorHandler = createHttpHandlerAdapter(); this.reactorServer = reactor.netty.http.server.HttpServer.create() .tcpConfiguration(server -> server.host(getHost())) .port(getPort()); }
public static DisposableServer nettyServer(ApplicationContext context) { HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build(); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); HttpServer httpServer = HttpServer.create().host("localhost").port(8080); return httpServer.handle(adapter).bindNow(); }
/** * 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. * * @return a {@link Connection} */ public final DisposableServer bindNow() { return bindNow(Duration.ofSeconds(45)); }
@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 gettingOptionsDuplicates() { HttpServer server = HttpServer.create() .port(123) .host(("foo")) .compress(true); assertThat(server.tcpConfiguration().configure()) .isNotSameAs(HttpServer.DEFAULT_TCP_SERVER) .isNotSameAs(server.tcpConfiguration().configure()); }
/** * Creates a new instance * * @param bindAddress the address to bind to * @param port the port to bind to * @return a new instance * @throws NullPointerException if {@code bindAddress} is {@code null} */ public static WebsocketServerTransport create(String bindAddress, int port) { Objects.requireNonNull(bindAddress, "bindAddress must not be null"); HttpServer httpServer = HttpServer.create().host(bindAddress).port(port); return create(httpServer); }
@DisplayName("creates server with HttpClient") @Test void createHttpClient() { assertThat(WebsocketServerTransport.create(HttpServer.create())).isNotNull(); }
@Test public void testSslConfigurationProtocolHttp11_2() { DisposableServer disposableServer = server.protocol(HttpProtocol.H2) .secure(spec -> spec.sslContext(builder)) .protocol(HttpProtocol.HTTP11) .bindNow(); assertTrue(protocols.isEmpty()); assertTrue(OpenSsl.isAvailable() ? sslContext instanceof OpenSslContext : sslContext instanceof JdkSslContext); disposableServer.disposeNow(); }
@Test public void testIssue309() { doTestIssue309("/somethingtooolooong", HttpServer.create() .port(0) .httpRequestDecoder(c -> c.maxInitialLineLength(20))); doTestIssue309("/something", HttpServer.create() .port(0) .httpRequestDecoder(c -> c.maxInitialLineLength(20))); }
private HttpServer createHttpServer() { HttpServer server = HttpServer.create(); if (this.resourceFactory != null) { LoopResources resources = this.resourceFactory.getLoopResources(); Assert.notNull(resources, "No LoopResources: is ReactorResourceFactory not initialized yet?"); server = server.tcpConfiguration((tcpServer) -> tcpServer.runOn(resources) .addressSupplier(this::getListenAddress)); } else { server = server.tcpConfiguration( (tcpServer) -> tcpServer.addressSupplier(this::getListenAddress)); } if (getSsl() != null && getSsl().isEnabled()) { SslServerCustomizer sslServerCustomizer = new SslServerCustomizer(getSsl(), getHttp2(), getSslStoreProvider()); server = sslServerCustomizer.apply(server); } if (getCompression() != null && getCompression().getEnabled()) { CompressionCustomizer compressionCustomizer = new CompressionCustomizer( getCompression()); server = compressionCustomizer.apply(server); } server = server.protocol(listProtocols()).forwarded(this.useForwardHeaders); return applyCustomizers(server); }
/** * 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()); }
@Override protected Mono<? extends DisposableServer> bind(TcpServer b) { return source.bind(b); } }
@Profile("default") @Bean public DisposableServer nettyHttpServer(ApplicationContext context) { HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build(); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); HttpServer httpServer = HttpServer.create().host("localhost").port(this.port); return httpServer.handle(adapter).bindNow(); }