Search in sources :

Example 16 with DisposableServer

use of reactor.netty.DisposableServer in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    DisposableServer server = HttpServer.create().host(// <1>
    "localhost").port(// <2>
    8080).bindNow();
    server.onDispose().block();
}
Also used : DisposableServer(reactor.netty.DisposableServer)

Example 17 with DisposableServer

use of reactor.netty.DisposableServer in project reactor-netty by reactor.

the class CustomForwardedHeaderHandlerApplication method main.

public static void main(String[] args) {
    DisposableServer server = HttpServer.create().forwarded((connectionInfo, request) -> {
        // <1>
        String hostHeader = request.headers().get("X-Forwarded-Host");
        if (hostHeader != null) {
            String[] hosts = hostHeader.split(",", 2);
            InetSocketAddress hostAddress = AddressUtils.createUnresolved(hosts[hosts.length - 1].trim(), connectionInfo.getHostAddress().getPort());
            connectionInfo = connectionInfo.withHostAddress(hostAddress);
        }
        return connectionInfo;
    }).route(routes -> routes.get("/clientip", (request, response) -> response.sendString(Mono.just(// <2>
    request.remoteAddress().getHostString())))).bindNow();
    server.onDispose().block();
}
Also used : HttpServer(reactor.netty.http.server.HttpServer) AddressUtils(reactor.netty.transport.AddressUtils) Mono(reactor.core.publisher.Mono) InetSocketAddress(java.net.InetSocketAddress) DisposableServer(reactor.netty.DisposableServer) DisposableServer(reactor.netty.DisposableServer) InetSocketAddress(java.net.InetSocketAddress)

Example 18 with DisposableServer

use of reactor.netty.DisposableServer in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    DisposableServer server = // <1>
    TcpServer.create().bindNow();
    server.onDispose().block();
}
Also used : DisposableServer(reactor.netty.DisposableServer)

Example 19 with DisposableServer

use of reactor.netty.DisposableServer in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    DisposableServer server = TcpServer.create().doOnConnection(conn -> conn.addHandler(new ReadTimeoutHandler(10, TimeUnit.SECONDS))).doOnChannelInit((observer, channel, remoteAddress) -> channel.pipeline().addFirst(// <2>
    new LoggingHandler("reactor.netty.examples"))).bindNow();
    server.onDispose().block();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) LoggingHandler(io.netty.handler.logging.LoggingHandler) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) TcpServer(reactor.netty.tcp.TcpServer) DisposableServer(reactor.netty.DisposableServer) LoggingHandler(io.netty.handler.logging.LoggingHandler) DisposableServer(reactor.netty.DisposableServer) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler)

Example 20 with DisposableServer

use of reactor.netty.DisposableServer in project reactor-netty by reactor.

the class Application method main.

public static void main(String[] args) {
    File cert = new File("certificate.crt");
    File key = new File("private.key");
    TcpSslContextSpec tcpSslContextSpec = TcpSslContextSpec.forServer(cert, key);
    DisposableServer server = TcpServer.create().secure(spec -> spec.sslContext(tcpSslContextSpec)).bindNow();
    server.onDispose().block();
}
Also used : TcpSslContextSpec(reactor.netty.tcp.TcpSslContextSpec) TcpServer(reactor.netty.tcp.TcpServer) DisposableServer(reactor.netty.DisposableServer) File(java.io.File) DisposableServer(reactor.netty.DisposableServer) File(java.io.File) TcpSslContextSpec(reactor.netty.tcp.TcpSslContextSpec)

Aggregations

DisposableServer (reactor.netty.DisposableServer)137 Mono (reactor.core.publisher.Mono)84 Test (org.junit.jupiter.api.Test)79 Duration (java.time.Duration)71 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)71 AtomicReference (java.util.concurrent.atomic.AtomicReference)68 Flux (reactor.core.publisher.Flux)68 Connection (reactor.netty.Connection)67 TimeUnit (java.util.concurrent.TimeUnit)65 LoopResources (reactor.netty.resources.LoopResources)60 List (java.util.List)58 CountDownLatch (java.util.concurrent.CountDownLatch)57 DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)56 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)55 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)54 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)54 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)53 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)53 Assumptions.assumeThat (org.assertj.core.api.Assumptions.assumeThat)53 StepVerifier (reactor.test.StepVerifier)53