From c2f9ca03ab91457340ae95b618b84136de038b4f Mon Sep 17 00:00:00 2001 From: "Kun.Long" Date: Tue, 29 Aug 2023 21:29:35 +0800 Subject: [PATCH 01/13] [sample] add a 'http snoop server' sample which receives any request and tells the client the details of the request in a formatted string #{761} --- .../examples/http/snoop/HttpSnoopClient.java | 64 +++++++ .../examples/http/snoop/HttpSnoopServer.java | 166 ++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java create mode 100644 reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java new file mode 100644 index 0000000000..ed4c3a51c6 --- /dev/null +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 VMware, Inc. or its affiliates, All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package reactor.netty.examples.http.snoop; + +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpHeaderValues; +import reactor.core.publisher.Mono; +import reactor.netty.ByteBufFlux; +import reactor.netty.http.client.HttpClient; + +/** + * @author Kun.Long + * a http client demo that sends two requests to the http snoop server and then wait for the completion of the two requests + * @see HttpSnoopServer + **/ +public class HttpSnoopClient { + + private final HttpClient client = HttpClient.create().wiretap(false); + + public static void main(String[] args) { + HttpSnoopClient httpSnoopClient = new HttpSnoopClient(); + httpSnoopClient.client.warmup().block(); + System.out.println("client is ready"); + + // we fire two requests to the server asynchronously + Mono respOfGet = httpSnoopClient.get(); + Mono respOfPost = httpSnoopClient.postSomeJsonData(); + System.out.println("requests have fired"); + + // then let the main thread wait for the completion of the two requests + Mono.when(respOfGet, respOfPost).block(); + System.out.println("main thread exits"); + } + + public Mono get() { + return client.headers(hds -> hds.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.TEXT_PLAIN)) + .get().uri("http://localhost:8080/hello?q1=a&q2=b").responseContent().aggregate() + .asString() + .doOnNext(resp -> System.out.println("resp of get(): \n" + resp)); + } + + public Mono postSomeJsonData() { + return client.headers(hds -> hds.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON)) + .post().uri("http://localhost:8080/hello2") + .send(ByteBufFlux.fromString(Mono.just("{\"foo\": 1,\"bar\": 2}"))) + .responseContent().aggregate() + .asString() + .doOnNext(resp -> System.out.println("resp of postSomeJsonData(): \n" + resp)); + } + +} diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java new file mode 100644 index 0000000000..ea434681fd --- /dev/null +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2023 VMware, Inc. or its affiliates, All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package reactor.netty.examples.http.snoop; + +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.QueryStringDecoder; +import reactor.core.publisher.Mono; +import reactor.netty.DisposableServer; +import reactor.netty.NettyOutbound; +import reactor.netty.http.server.HttpServer; +import reactor.netty.http.server.HttpServerRequest; +import reactor.netty.http.server.HttpServerResponse; + +import java.util.Arrays; +import java.util.List; + +/** + * An HTTP server that receives any request and tells the client the details of the request in a formatted string. + * @author Kun.Long + **/ +public class HttpSnoopServer { + + public static void main(String[] args) { + HttpSnoopServer server = new HttpSnoopServer(8080); + server.startup(); + } + + /** + * the port of the server + **/ + private final int port; + + /** + * the server instance + **/ + private DisposableServer server; + + public HttpSnoopServer(int port) { + this.port = port; + } + + /** + * startup the server + **/ + public void startup() { + // 1.create and config the server instance + HttpServer server = HttpServer + .create() + .port(port) + .wiretap(false); + + // 2.config the route rule, this server will receive any request that has any path and any method, + // and then send back the details of the received HTTP request + server = server.route(routes -> routes.route( + req -> true, + this::parseRequestAndSendResponse + )); + + // 3. start the server, using eager mode + server.warmup().block(); + this.server = server.bindNow(); + + // 4. block the main thread to keep the server running + this.server.onDispose().block(); + } + + private NettyOutbound parseRequestAndSendResponse(HttpServerRequest request, HttpServerResponse response) { + StringBuilder buf = new StringBuilder(); + buf.append("request received, the details are: \n\n"); + + // append the request method, uri and protocol version + buf.append("your host: ").append(request.hostAddress()).append("\n"); + buf.append("http method: ").append(request.method().name()).append("\n"); + buf.append("http version: ").append(request.version().text()).append("\n"); + buf.append("request path: ").append(request.path()).append("\n\n"); + + // append the request headers + buf.append("headers: \n"); + request.requestHeaders().forEach(entry -> { + buf.append(entry.getKey()); + buf.append(" : "); + buf.append(entry.getValue()); + buf.append("\n"); + }); + buf.append("\n"); + + // append the query parameters + buf.append("query parameters: \n"); + new QueryStringDecoder(request.uri()).parameters().forEach((key, value) -> { + buf.append(key); + buf.append(" : "); + buf.append(value); + buf.append("\n"); + }); + buf.append("\n"); + + // append the request content if there is any + buf.append("content: \n"); + String contentType = request.requestHeaders().get(HttpHeaderNames.CONTENT_TYPE); + Mono responseContent; + if (this.isATextualContentType(contentType)) { + responseContent = request.receive().aggregate().asString() + .onErrorReturn("") + .switchIfEmpty(Mono.just("")) + .flatMap(content -> { + buf.append(content); + buf.append("\n"); + return Mono.just(buf.toString()); + }); + } else { + buf.append("there is no content or the content is not textual, so we don't print it here\n"); + responseContent = Mono.just(buf.toString()); + } + + // 6. send the response + response.status(HttpResponseStatus.OK); + response.header(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.TEXT_PLAIN); + + return response.sendString(responseContent); + } + + /** + * check whether the content type is textual + **/ + private boolean isATextualContentType(String contentType) { + if (contentType == null) { + return false; + } + + for (String textBaseContentType : TEXTUAL_CONTENT_TYPE) { + if (contentType.startsWith(textBaseContentType)) { + return true; + } + } + return false; + } + + private static final List TEXTUAL_CONTENT_TYPE = Arrays.asList( + "text/plain", + "text/html", + "text/xml", + "text/css", + "text/javascript", + "application/json", + "application/xml", + "application/javascript", + "application/x-javascript", + "application/xhtml+xml", + "application/x-www-form-urlencoded" + ); +} From 0b2f1236698b7ac949927f047ead7ee1528fe5f3 Mon Sep 17 00:00:00 2001 From: "Kun.Long" Date: Thu, 31 Aug 2023 21:49:39 +0800 Subject: [PATCH 02/13] remove the warmup operation #{761} --- .../reactor/netty/examples/http/snoop/HttpSnoopClient.java | 2 -- .../reactor/netty/examples/http/snoop/HttpSnoopServer.java | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java index ed4c3a51c6..af05e5c6e5 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java @@ -32,8 +32,6 @@ public class HttpSnoopClient { public static void main(String[] args) { HttpSnoopClient httpSnoopClient = new HttpSnoopClient(); - httpSnoopClient.client.warmup().block(); - System.out.println("client is ready"); // we fire two requests to the server asynchronously Mono respOfGet = httpSnoopClient.get(); diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java index ea434681fd..95f34ba282 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java @@ -71,8 +71,7 @@ public void startup() { this::parseRequestAndSendResponse )); - // 3. start the server, using eager mode - server.warmup().block(); + // 3. start the server this.server = server.bindNow(); // 4. block the main thread to keep the server running From e24fe0d9f1a64328cb7a4a014b59b884cf8c8043 Mon Sep 17 00:00:00 2001 From: "Kun.Long" Date: Thu, 31 Aug 2023 22:25:20 +0800 Subject: [PATCH 03/13] let the HttpSnoopServer follows the HelloWorldServer's pattern #{761} --- .../examples/http/snoop/HttpSnoopClient.java | 51 +++++++------- .../examples/http/snoop/HttpSnoopServer.java | 66 +++++++++---------- 2 files changed, 61 insertions(+), 56 deletions(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java index af05e5c6e5..506a029b6c 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java @@ -17,8 +17,10 @@ import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import reactor.core.publisher.Mono; import reactor.netty.ByteBufFlux; +import reactor.netty.http.Http11SslContextSpec; import reactor.netty.http.client.HttpClient; /** @@ -28,35 +30,40 @@ **/ public class HttpSnoopClient { - private final HttpClient client = HttpClient.create().wiretap(false); + static final boolean SECURE = System.getProperty("secure") != null; + static final int PORT = Integer.parseInt(System.getProperty("port", SECURE ? "8443" : "8080")); + static final boolean WIRETAP = System.getProperty("wiretap") != null; + static final boolean COMPRESS = System.getProperty("compress") != null; - public static void main(String[] args) { - HttpSnoopClient httpSnoopClient = new HttpSnoopClient(); + public static void main(String[] args) throws Exception{ + HttpClient client = HttpClient.create() + .port(PORT) + .wiretap(WIRETAP) + .compress(COMPRESS); + if (SECURE) { + Http11SslContextSpec http11SslContextSpec = + Http11SslContextSpec.forClient() + .configure(builder -> builder.trustManager(InsecureTrustManagerFactory.INSTANCE)); + client = client.secure(spec -> spec.sslContext(http11SslContextSpec)); + } // we fire two requests to the server asynchronously - Mono respOfGet = httpSnoopClient.get(); - Mono respOfPost = httpSnoopClient.postSomeJsonData(); + Mono respOfGet = + client.headers(hds -> hds.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.TEXT_PLAIN)) + .get().uri("/hello?q1=a&q2=b").responseContent().aggregate() + .asString() + .doOnNext(resp -> System.out.println("resp of get(): \n" + resp)); + Mono respOfPost = + client.headers(hds -> hds.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON)) + .post().uri("/hello2") + .send(ByteBufFlux.fromString(Mono.just("{\"foo\": 1,\"bar\": 2}"))) + .responseContent().aggregate() + .asString() + .doOnNext(resp -> System.out.println("resp of postSomeJsonData(): \n" + resp)); System.out.println("requests have fired"); // then let the main thread wait for the completion of the two requests Mono.when(respOfGet, respOfPost).block(); System.out.println("main thread exits"); } - - public Mono get() { - return client.headers(hds -> hds.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.TEXT_PLAIN)) - .get().uri("http://localhost:8080/hello?q1=a&q2=b").responseContent().aggregate() - .asString() - .doOnNext(resp -> System.out.println("resp of get(): \n" + resp)); - } - - public Mono postSomeJsonData() { - return client.headers(hds -> hds.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON)) - .post().uri("http://localhost:8080/hello2") - .send(ByteBufFlux.fromString(Mono.just("{\"foo\": 1,\"bar\": 2}"))) - .responseContent().aggregate() - .asString() - .doOnNext(resp -> System.out.println("resp of postSomeJsonData(): \n" + resp)); - } - } diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java index 95f34ba282..af5d144b0b 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java @@ -19,9 +19,12 @@ import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.QueryStringDecoder; +import io.netty.handler.ssl.util.SelfSignedCertificate; import reactor.core.publisher.Mono; -import reactor.netty.DisposableServer; import reactor.netty.NettyOutbound; +import reactor.netty.http.Http11SslContextSpec; +import reactor.netty.http.Http2SslContextSpec; +import reactor.netty.http.HttpProtocol; import reactor.netty.http.server.HttpServer; import reactor.netty.http.server.HttpServerRequest; import reactor.netty.http.server.HttpServerResponse; @@ -35,50 +38,45 @@ **/ public class HttpSnoopServer { - public static void main(String[] args) { - HttpSnoopServer server = new HttpSnoopServer(8080); - server.startup(); - } - - /** - * the port of the server - **/ - private final int port; - - /** - * the server instance - **/ - private DisposableServer server; - - public HttpSnoopServer(int port) { - this.port = port; - } + static final boolean SECURE = System.getProperty("secure") != null; + static final int PORT = Integer.parseInt(System.getProperty("port", SECURE ? "8443" : "8080")); + static final boolean WIRETAP = System.getProperty("wiretap") != null; + static final boolean COMPRESS = System.getProperty("compress") != null; + static final boolean HTTP2 = System.getProperty("http2") != null; - /** - * startup the server - **/ - public void startup() { + public static void main(String[] args) throws Exception { // 1.create and config the server instance HttpServer server = HttpServer .create() - .port(port) - .wiretap(false); + .port(PORT) + .wiretap(WIRETAP) + .compress(COMPRESS); + + if (SECURE) { + SelfSignedCertificate ssc = new SelfSignedCertificate(); + if (HTTP2) { + server = server.secure(spec -> spec.sslContext(Http2SslContextSpec.forServer(ssc.certificate(), ssc.privateKey()))); + } + else { + server = server.secure(spec -> spec.sslContext(Http11SslContextSpec.forServer(ssc.certificate(), ssc.privateKey()))); + } + } + if (HTTP2) { + server = server.protocol(HttpProtocol.H2); + } // 2.config the route rule, this server will receive any request that has any path and any method, // and then send back the details of the received HTTP request server = server.route(routes -> routes.route( req -> true, - this::parseRequestAndSendResponse + HttpSnoopServer::parseRequestAndSendResponse )); - // 3. start the server - this.server = server.bindNow(); - - // 4. block the main thread to keep the server running - this.server.onDispose().block(); + // 3. start the server and block the main thread to keep the server running + server.bindNow().onDispose().block(); } - private NettyOutbound parseRequestAndSendResponse(HttpServerRequest request, HttpServerResponse response) { + private static NettyOutbound parseRequestAndSendResponse(HttpServerRequest request, HttpServerResponse response) { StringBuilder buf = new StringBuilder(); buf.append("request received, the details are: \n\n"); @@ -112,7 +110,7 @@ private NettyOutbound parseRequestAndSendResponse(HttpServerRequest request, Htt buf.append("content: \n"); String contentType = request.requestHeaders().get(HttpHeaderNames.CONTENT_TYPE); Mono responseContent; - if (this.isATextualContentType(contentType)) { + if (isATextualContentType(contentType)) { responseContent = request.receive().aggregate().asString() .onErrorReturn("") .switchIfEmpty(Mono.just("")) @@ -136,7 +134,7 @@ private NettyOutbound parseRequestAndSendResponse(HttpServerRequest request, Htt /** * check whether the content type is textual **/ - private boolean isATextualContentType(String contentType) { + private static boolean isATextualContentType(String contentType) { if (contentType == null) { return false; } From 77a36ad90db9e917a3f4baa02e384bb4903b843a Mon Sep 17 00:00:00 2001 From: "Kun.Long" Date: Thu, 31 Aug 2023 22:27:23 +0800 Subject: [PATCH 04/13] error handling for read request body #{761} --- .../netty/examples/http/snoop/HttpSnoopServer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java index af5d144b0b..3565678b7a 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java @@ -112,12 +112,15 @@ private static NettyOutbound parseRequestAndSendResponse(HttpServerRequest reque Mono responseContent; if (isATextualContentType(contentType)) { responseContent = request.receive().aggregate().asString() - .onErrorReturn("") + .onErrorResume(e -> { + System.out.println("error occurs when receiving the content: " + e.getMessage()); + return Mono.empty(); + }) .switchIfEmpty(Mono.just("")) - .flatMap(content -> { + .map(content -> { buf.append(content); buf.append("\n"); - return Mono.just(buf.toString()); + return buf.toString(); }); } else { buf.append("there is no content or the content is not textual, so we don't print it here\n"); From c6cede2f8fa3cfc753385b565fbe904a80d0c8d1 Mon Sep 17 00:00:00 2001 From: RealLongKun Date: Fri, 1 Sep 2023 16:14:33 +0800 Subject: [PATCH 05/13] Update reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java Co-authored-by: Violeta Georgieva --- .../reactor/netty/examples/http/snoop/HttpSnoopClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java index 506a029b6c..26622e4450 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java @@ -24,8 +24,9 @@ import reactor.netty.http.client.HttpClient; /** + * An HTTP client demo that sends two requests to the http snoop server and then waits for the completion of the two requests + * * @author Kun.Long - * a http client demo that sends two requests to the http snoop server and then wait for the completion of the two requests * @see HttpSnoopServer **/ public class HttpSnoopClient { From a4c274caf29f128b8159bfee69a75a5ef7cd7117 Mon Sep 17 00:00:00 2001 From: RealLongKun Date: Fri, 1 Sep 2023 16:14:52 +0800 Subject: [PATCH 06/13] Update reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java Co-authored-by: Violeta Georgieva --- .../reactor/netty/examples/http/snoop/HttpSnoopClient.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java index 26622e4450..0251fda4d5 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java @@ -51,7 +51,10 @@ public static void main(String[] args) throws Exception{ // we fire two requests to the server asynchronously Mono respOfGet = client.headers(hds -> hds.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.TEXT_PLAIN)) - .get().uri("/hello?q1=a&q2=b").responseContent().aggregate() + .get() + .uri("/hello?q1=a&q2=b") + .responseContent() + .aggregate() .asString() .doOnNext(resp -> System.out.println("resp of get(): \n" + resp)); Mono respOfPost = From f74f08f9daf38c473dfa90b4eacf1505ce313d10 Mon Sep 17 00:00:00 2001 From: RealLongKun Date: Fri, 1 Sep 2023 16:17:28 +0800 Subject: [PATCH 07/13] Update reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java Co-authored-by: Violeta Georgieva --- .../netty/examples/http/snoop/HttpSnoopClient.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java index 0251fda4d5..2884a244fa 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java @@ -59,11 +59,13 @@ public static void main(String[] args) throws Exception{ .doOnNext(resp -> System.out.println("resp of get(): \n" + resp)); Mono respOfPost = client.headers(hds -> hds.set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON)) - .post().uri("/hello2") - .send(ByteBufFlux.fromString(Mono.just("{\"foo\": 1,\"bar\": 2}"))) - .responseContent().aggregate() + .post() + .uri("/hello2") + .send(ByteBufMono.fromString(Mono.just("{\"foo\": 1,\"bar\": 2}"))) + .responseContent() + .aggregate() .asString() - .doOnNext(resp -> System.out.println("resp of postSomeJsonData(): \n" + resp)); + .doOnNext(resp -> System.out.println("resp of post(): \n" + resp)); System.out.println("requests have fired"); // then let the main thread wait for the completion of the two requests From fe5aef4edba8867e281ea72a785bdba98f81237c Mon Sep 17 00:00:00 2001 From: RealLongKun Date: Fri, 1 Sep 2023 16:18:02 +0800 Subject: [PATCH 08/13] Update reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java Co-authored-by: Violeta Georgieva --- .../netty/examples/http/snoop/HttpSnoopServer.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java index 3565678b7a..770cc7e910 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java @@ -46,11 +46,10 @@ public class HttpSnoopServer { public static void main(String[] args) throws Exception { // 1.create and config the server instance - HttpServer server = HttpServer - .create() - .port(PORT) - .wiretap(WIRETAP) - .compress(COMPRESS); + HttpServer server = HttpServer.create() + .port(PORT) + .wiretap(WIRETAP) + .compress(COMPRESS); if (SECURE) { SelfSignedCertificate ssc = new SelfSignedCertificate(); From 2b3f185d7711860682254ec7642fe01eb873d1dc Mon Sep 17 00:00:00 2001 From: RealLongKun Date: Fri, 1 Sep 2023 16:18:17 +0800 Subject: [PATCH 09/13] Update reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java Co-authored-by: Violeta Georgieva --- .../java/reactor/netty/examples/http/snoop/HttpSnoopServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java index 770cc7e910..a205e87bd2 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java @@ -34,6 +34,7 @@ /** * An HTTP server that receives any request and tells the client the details of the request in a formatted string. + * * @author Kun.Long **/ public class HttpSnoopServer { From 54d5d3b645c856e19ae6788f2db3c059834aedf5 Mon Sep 17 00:00:00 2001 From: "Kun.Long" Date: Fri, 1 Sep 2023 17:15:38 +0800 Subject: [PATCH 10/13] fix the import #{761} --- .../java/reactor/netty/examples/http/snoop/HttpSnoopClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java index 2884a244fa..f234f1fc6a 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java @@ -19,7 +19,7 @@ import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; import reactor.core.publisher.Mono; -import reactor.netty.ByteBufFlux; +import reactor.netty.ByteBufMono; import reactor.netty.http.Http11SslContextSpec; import reactor.netty.http.client.HttpClient; From 1e9fae745b08259d2980e58d88d2db78c382bf89 Mon Sep 17 00:00:00 2001 From: RealLongKun Date: Fri, 1 Sep 2023 17:16:52 +0800 Subject: [PATCH 11/13] Update reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java Co-authored-by: Pierre De Rop --- .../java/reactor/netty/examples/http/snoop/HttpSnoopClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java index f234f1fc6a..bfb35e812f 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopClient.java @@ -36,7 +36,7 @@ public class HttpSnoopClient { static final boolean WIRETAP = System.getProperty("wiretap") != null; static final boolean COMPRESS = System.getProperty("compress") != null; - public static void main(String[] args) throws Exception{ + public static void main(String[] args) throws Exception { HttpClient client = HttpClient.create() .port(PORT) .wiretap(WIRETAP) From e8ac29363de05e56318a48ffe91edddf9bf6f510 Mon Sep 17 00:00:00 2001 From: RealLongKun Date: Fri, 1 Sep 2023 17:18:31 +0800 Subject: [PATCH 12/13] Update reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java Co-authored-by: Pierre De Rop --- .../reactor/netty/examples/http/snoop/HttpSnoopServer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java index a205e87bd2..fd221a7919 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java @@ -122,7 +122,8 @@ private static NettyOutbound parseRequestAndSendResponse(HttpServerRequest reque buf.append("\n"); return buf.toString(); }); - } else { + } + else { buf.append("there is no content or the content is not textual, so we don't print it here\n"); responseContent = Mono.just(buf.toString()); } From 5fead72030d7399051d7b30d8090ec9cf4582a1f Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Fri, 1 Sep 2023 13:15:06 +0300 Subject: [PATCH 13/13] Make checkstyle happy --- .../reactor/netty/examples/http/snoop/HttpSnoopServer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java index fd221a7919..6b309acc64 100644 --- a/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/http/snoop/HttpSnoopServer.java @@ -34,7 +34,7 @@ /** * An HTTP server that receives any request and tells the client the details of the request in a formatted string. - * + * * @author Kun.Long **/ public class HttpSnoopServer { @@ -122,7 +122,7 @@ private static NettyOutbound parseRequestAndSendResponse(HttpServerRequest reque buf.append("\n"); return buf.toString(); }); - } + } else { buf.append("there is no content or the content is not textual, so we don't print it here\n"); responseContent = Mono.just(buf.toString());