use of reactor.netty.DisposableServer in project reactor-netty by reactor.
the class HttpServerTests method errorResponseAndReturn.
@Test
void errorResponseAndReturn() {
disposableServer = createServer().handle((req, resp) -> Mono.error(new Exception("returnError"))).bindNow();
Integer code = createClient(disposableServer.port()).get().uri("/return").responseSingle((res, buf) -> Mono.just(res.status().code())).block();
assertThat(code).isEqualTo(500);
}
use of reactor.netty.DisposableServer in project reactor-netty by reactor.
the class HttpServerTests method testIssue940.
@Test
void testIssue940() {
AtomicInteger counter = new AtomicInteger();
Flux<String> response = Flux.interval(Duration.ofMillis(200)).map(l -> "" + counter.getAndIncrement()).doFinally(sig -> {
if (SignalType.ON_ERROR.equals(sig)) {
counter.getAndDecrement();
}
});
disposableServer = createServer().handle((req, res) -> res.sendString(response)).bindNow();
HttpClient client = createClient(disposableServer.port());
doTestIssue940(client, "0", "1");
doTestIssue940(client, "2", "3");
}
use of reactor.netty.DisposableServer in project reactor-netty by reactor.
the class HttpServerTests method testNormalConnectionCloseForWebSocketServer.
@Test
void testNormalConnectionCloseForWebSocketServer() throws Exception {
AtomicReference<WebSocketCloseStatus> statusServer = new AtomicReference<>();
AtomicReference<WebSocketCloseStatus> statusClient = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(2);
disposableServer = createServer().handle((req, resp) -> resp.sendWebsocket((in, out) -> in.receiveCloseStatus().doOnNext(o -> {
statusServer.set(o);
latch.countDown();
}).then())).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> out.sendClose(4404, "test").then(in.receiveCloseStatus().doOnNext(o -> {
statusClient.set(o);
latch.countDown();
}))).blockLast();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(statusClient.get()).isNotNull().isEqualTo(new WebSocketCloseStatus(4404, "test"));
assertThat(statusServer.get()).isNotNull().isEqualTo(new WebSocketCloseStatus(4404, "test"));
}
use of reactor.netty.DisposableServer in project reactor-netty by reactor.
the class HttpServerTests method testSniSupport.
@Test
void testSniSupport() throws Exception {
SelfSignedCertificate defaultCert = new SelfSignedCertificate("default");
Http11SslContextSpec defaultSslContextBuilder = Http11SslContextSpec.forServer(defaultCert.certificate(), defaultCert.privateKey());
SelfSignedCertificate testCert = new SelfSignedCertificate("test.com");
Http11SslContextSpec testSslContextBuilder = Http11SslContextSpec.forServer(testCert.certificate(), testCert.privateKey());
Http11SslContextSpec clientSslContextBuilder = Http11SslContextSpec.forClient().configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE));
AtomicReference<String> hostname = new AtomicReference<>();
disposableServer = createServer().secure(spec -> spec.sslContext(defaultSslContextBuilder).addSniMapping("*.test.com", domainSpec -> domainSpec.sslContext(testSslContextBuilder))).doOnChannelInit((obs, channel, remoteAddress) -> channel.pipeline().addAfter(NettyPipeline.SslHandler, "test", new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
if (evt instanceof SniCompletionEvent) {
hostname.set(((SniCompletionEvent) evt).hostname());
}
ctx.fireUserEventTriggered(evt);
}
})).handle((req, res) -> res.sendString(Mono.just("testSniSupport"))).bindNow();
createClient(disposableServer::address).secure(spec -> spec.sslContext(clientSslContextBuilder).serverNames(new SNIHostName("test.com"))).get().uri("/").responseContent().aggregate().block(Duration.ofSeconds(30));
assertThat(hostname.get()).isNotNull();
assertThat(hostname.get()).isEqualTo("test.com");
}
use of reactor.netty.DisposableServer in project reactor-netty by reactor.
the class TcpServerTests method assertSendFile.
private void assertSendFile(Function<NettyOutbound, NettyOutbound> fn) throws Exception {
DisposableServer context = TcpServer.create().handle((in, out) -> in.receive().asString().flatMap(word -> "GOGOGO".equals(word) ? fn.apply(out).then() : out.sendString(Mono.just("NOPE")))).wiretap(true).bindNow();
assertThat(context).isNotNull();
AtomicReference<String> m1 = new AtomicReference<>();
AtomicReference<String> m2 = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(2);
Connection client1 = TcpClient.create().port(context.port()).handle((in, out) -> {
in.receive().asString().log("-----------------CLIENT1").subscribe(s -> {
m1.set(s);
latch.countDown();
});
return out.sendString(Mono.just("gogogo")).neverComplete();
}).wiretap(true).connectNow();
Connection client2 = TcpClient.create().port(context.port()).option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(64, 1024, 65536)).handle((in, out) -> {
in.receive().asString(StandardCharsets.UTF_8).take(2).reduceWith(String::new, String::concat).log("-----------------CLIENT2").subscribe(s -> {
m2.set(s);
latch.countDown();
});
return out.sendString(Mono.just("GOGOGO")).neverComplete();
}).wiretap(true).connectNow();
assertThat(client2).isNotNull();
assertThat(latch.await(30, TimeUnit.SECONDS)).as("latch await").isTrue();
client1.disposeNow();
client2.disposeNow();
context.disposeNow();
assertThat(m1.get()).isNotNull().isEqualTo("NOPE");
assertThat(m2.get()).isNotNull().startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here ->").contains("<- 1024 mark here").endsWith("End of File");
}
Aggregations