Search in sources :

Example 1 with DisposableServer

use of reactor.netty.DisposableServer in project spring-framework by spring-projects.

the class ReactorHttpsServer method startInternal.

@Override
protected void startInternal() {
    DisposableServer server = this.reactorServer.handle(this.reactorHandler).bind().block();
    setPort(((InetSocketAddress) server.address()).getPort());
    this.serverRef.set(server);
}
Also used : DisposableServer(reactor.netty.DisposableServer)

Example 2 with DisposableServer

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

the class ITTracingHttpClientDecoratorTest method currentSpanVisibleToUserHandler.

@Test
@SuppressWarnings("try")
public void currentSpanVisibleToUserHandler() {
    AtomicReference<HttpHeaders> headers = new AtomicReference<>();
    DisposableServer disposableServer = null;
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    try (Scope scope = currentTraceContext.newScope(parent)) {
        disposableServer = HttpServer.create().port(0).handle((req, res) -> {
            headers.set(req.requestHeaders());
            return res.sendString(Mono.just("test"));
        }).bindNow();
        client.port(disposableServer.port()).request(HttpMethod.GET).uri("/").send((req, out) -> {
            req.header("test-id", currentTraceContext.get().traceIdString());
            return out;
        }).responseContent().aggregate().block(Duration.ofSeconds(30));
        assertThat(headers.get()).isNotNull();
        assertThat(headers.get().get("x-b3-traceId")).isEqualTo(headers.get().get("test-id"));
    } finally {
        if (disposableServer != null) {
            disposableServer.disposeNow();
        }
    }
    testSpanHandler.takeRemoteSpan(CLIENT);
}
Also used : EventExecutor(io.netty.util.concurrent.EventExecutor) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) Nullable(reactor.util.annotation.Nullable) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(java.time.Duration) BiConsumer(java.util.function.BiConsumer) AfterClass(org.junit.AfterClass) ChannelGroup(io.netty.channel.group.ChannelGroup) CLIENT(brave.Span.Kind.CLIENT) ITHttpAsyncClient(brave.test.http.ITHttpAsyncClient) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) TraceContext(brave.propagation.TraceContext) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) DefaultEventExecutor(io.netty.util.concurrent.DefaultEventExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) HttpServer(reactor.netty.http.server.HttpServer) Assertions.fail(org.assertj.core.api.Assertions.fail) Scope(brave.propagation.CurrentTraceContext.Scope) SamplingFlags(brave.propagation.SamplingFlags) DisposableServer(reactor.netty.DisposableServer) HttpClient(reactor.netty.http.client.HttpClient) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) Scope(brave.propagation.CurrentTraceContext.Scope) DisposableServer(reactor.netty.DisposableServer) TraceContext(brave.propagation.TraceContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 3 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().metrics(true, // <1>
    CustomHttpServerMetricsRecorder::new).route(r -> r.get("/stream/{n}", (req, res) -> res.sendString(Mono.just(req.param("n")))).get("/bytes/{n}", (req, res) -> res.sendString(Mono.just(req.param("n"))))).bindNow();
    server.onDispose().block();
}
Also used : HttpServer(reactor.netty.http.server.HttpServer) SocketAddress(java.net.SocketAddress) HttpServerMetricsRecorder(reactor.netty.http.server.HttpServerMetricsRecorder) Duration(java.time.Duration) Mono(reactor.core.publisher.Mono) DisposableServer(reactor.netty.DisposableServer) DisposableServer(reactor.netty.DisposableServer)

Example 4 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().httpFormDecoder(// <1>
    builder -> builder.maxInMemorySize(0)).route(routes -> routes.post("/multipart", (request, response) -> response.sendString(// <2>
    request.receiveForm(builder -> builder.maxInMemorySize(256)).flatMap(data -> Mono.just('[' + data.getName() + ']'))))).bindNow();
    server.onDispose().block();
}
Also used : HttpServer(reactor.netty.http.server.HttpServer) Mono(reactor.core.publisher.Mono) DisposableServer(reactor.netty.DisposableServer) DisposableServer(reactor.netty.DisposableServer)

Example 5 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().route(routes -> routes.get("/{param}", (request, response) -> {
        if (request.requestHeaders().contains("Some-Header")) {
            return response.sendString(Mono.just(request.param("param")));
        }
        return response.sendNotFound();
    })).bindNow();
    server.onDispose().block();
}
Also used : HttpServer(reactor.netty.http.server.HttpServer) Mono(reactor.core.publisher.Mono) DisposableServer(reactor.netty.DisposableServer) DisposableServer(reactor.netty.DisposableServer)

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