@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 public Optional<ServerTransport> buildServer(URI uri) { Objects.requireNonNull(uri, "uri must not be null"); if (!SCHEME.equals(uri.getScheme())) { return Optional.empty(); } return Optional.of( TcpServerTransport.create(TcpServer.create().host(uri.getHost()).port(uri.getPort()))); } }
/** * 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 TcpServerTransport create(String bindAddress, int port) { Objects.requireNonNull(bindAddress, "bindAddress must not be null"); TcpServer server = TcpServer.create().host(bindAddress).port(port); return create(server); }
/** * The host to which this server should bind. * * @param host The host to bind to. * * @return a new {@link HttpServer} */ public final HttpServer host(String host) { return tcpConfiguration(tcpServer -> tcpServer.host(host)); }
/** * The host to which this server should bind. * * @param host The host to bind to. * * @return a new {@link HttpServer} */ public final HttpServer host(String host) { return tcpConfiguration(tcpServer -> tcpServer.host(host)); }
@Override public Optional<ServerTransport> buildServer(URI uri) { Objects.requireNonNull(uri, "uri must not be null"); if (!SCHEME.equals(uri.getScheme())) { return Optional.empty(); } return Optional.of( TcpServerTransport.create(TcpServer.create().host(uri.getHost()).port(uri.getPort()))); } }
/** * 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 TcpServerTransport create(String bindAddress, int port) { Objects.requireNonNull(bindAddress, "bindAddress must not be null"); TcpServer server = TcpServer.create().host(bindAddress).port(port); return create(server); }
@Test public void gettingOptionsDuplicates() { TcpServer server = TcpServer.create().host("foo").port(123); Assertions.assertThat(server.configure()) .isNotSameAs(TcpServerBind.INSTANCE.serverBootstrap) .isNotSameAs(server.configure()); }
TcpServer.create().host("localhost") .handle((in, out) -> out.sendGroups(in.receive() .asString()
@Test @Ignore public void startContentServer() { Random random = new Random(0); byte[] content = new byte[1024 * 10]; random.nextBytes(content); HttpServer server = HttpServer.create() .port(CONTENT_SERVER_PORT) .tcpConfiguration(tcpServer -> tcpServer.host("0.0.0.0") .option(ChannelOption.SO_LINGER, -1)); server.route(routes -> routes.get("/**", (req, res) -> res.header("Content-length", String.valueOf(content.length)) .header("Content-type", "application/octet-stream") .header("Connection", "Close") .sendByteArray(Flux.just(content)))) .wiretap(true) .bindNow(); }
final TcpServer server = TcpServer.create() .host("localhost") .secure(sslContextSpec -> sslContextSpec.sslContext(serverOptions));
@Test public void prematureCancel() { DirectProcessor<Void> signal = DirectProcessor.create(); DisposableServer x = TcpServer.create() .host("localhost") .port(0) .handle((in, out) -> { signal.onComplete(); return out.withConnection(c -> c.addHandlerFirst(new HttpResponseEncoder())) .sendObject(Mono.delay(Duration.ofSeconds(2)) .map(t -> new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.PROCESSING))) .neverComplete(); }) .wiretap(true) .bindNow(Duration.ofSeconds(30)); StepVerifier.create( createHttpClientForContextWithAddress(x) .get() .uri("/") .responseContent() .timeout(signal)) .verifyError(TimeoutException.class); }
DisposableServer x = TcpServer.create() .host("localhost") .port(0) .handle((in, out) ->