@Override protected void initServer() { this.reactorHandler = createHttpHandlerAdapter(); this.reactorServer = reactor.netty.http.server.HttpServer.create() .tcpConfiguration(server -> server.host(getHost())) .port(getPort()); }
@Override protected void initServer() { this.reactorHandler = createHttpHandlerAdapter(); this.reactorServer = reactor.netty.http.server.HttpServer.create() .tcpConfiguration(server -> server.host(getHost())) .port(getPort()); }
@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)); }
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); }
/** * Creates a new instance binding to localhost * * @param port the port to bind to * @return a new instance */ public static WebsocketServerTransport create(int port) { HttpServer httpServer = HttpServer.create().port(port); return create(httpServer); }
/** * 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(); }
@DisplayName("creates server") @Test void constructor() { new WebsocketRouteTransport(HttpServer.create(), routes -> {}, "/test-path"); }
@DisplayName("starts server") @Test void start() { WebsocketRouteTransport serverTransport = new WebsocketRouteTransport(HttpServer.create(), routes -> {}, "/test-path"); serverTransport .start(duplexConnection -> Mono.empty()) .as(StepVerifier::create) .expectNextCount(1) .verifyComplete(); }
@DisplayName("constructor throw NullPointer with null path") @Test void constructorNullPath() { assertThatNullPointerException() .isThrownBy(() -> new WebsocketRouteTransport(HttpServer.create(), routes -> {}, null)) .withMessage("path must not be null"); }
@DisplayName("constructor throw NullPointer with null routesBuilder") @Test void constructorNullRoutesBuilder() { assertThatNullPointerException() .isThrownBy(() -> new WebsocketRouteTransport(HttpServer.create(), null, "/test-path")) .withMessage("routesBuilder must not be null"); }
@DisplayName("start throw NullPointerException with null acceptor") @Test void startNullAcceptor() { assertThatNullPointerException() .isThrownBy( () -> new WebsocketRouteTransport(HttpServer.create(), routes -> {}, "/test-path") .start(null)) .withMessage("acceptor must not be null"); } }
@Profile("default") @Bean public HttpServer 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); }
@Profile("default") @Bean public HttpServer 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); }
@Profile("default") @Bean public HttpServer 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); }
@Profile("default") @Bean public HttpServer 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); }
@Profile("default") @Bean public HttpServer 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); }
@Profile("default") @Bean public HttpServer 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); }
@Test public void httpPortWithAddress() { DisposableServer blockingFacade = HttpServer.create() .port(8080) .host("localhost") .handle((req, resp) -> resp.sendNotFound()) .wiretap(true) .bindNow(); blockingFacade.disposeNow(); assertThat(blockingFacade.address().getPort()) .isEqualTo(8080); }
@Before public void setUp() { server = HttpServer.create() .port(7000) .host("localhost") .handle((req, res) -> res.sendString(Mono.just("test"))) .wiretap(true) .bindNow(); }