From d26f3ac49a176a193768830bcd2797739c42255a Mon Sep 17 00:00:00 2001 From: isaolmez Date: Wed, 27 Mar 2019 21:35:54 +0300 Subject: [PATCH 1/4] BAEL-2715: Moved reactor netty samples to an existing module --- spring-5-webflux/pom.xml | 25 +++----- .../CustomNettyWebServerFactory.java | 36 +++++++++++ .../serverconfig/GreetingController.java | 23 +++++++ .../spring/serverconfig/GreetingService.java | 12 ++++ .../NettyWebServerFactoryPortCustomizer.java | 30 +++++++++ .../NettyWebServerFactorySslCustomizer.java | 26 ++++++++ .../serverconfig/ServerConfigApplication.java | 12 ++++ .../src/main/resources/logback.xml | 31 ++++++++++ .../src/main/resources/sample.jks | Bin 0 -> 2264 bytes ... => ResponseStatusControllerLiveTest.java} | 2 +- .../GreetingControllerIntegrationTest.java | 41 +++++++++++++ .../spring/serverconfig/GreetingLiveTest.java | 57 ++++++++++++++++++ .../GreetingSkipAutoConfigLiveTest.java | 8 +++ .../src/test/resources/logback-test.xml | 13 ++++ 14 files changed, 299 insertions(+), 17 deletions(-) create mode 100644 spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/CustomNettyWebServerFactory.java create mode 100644 spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/GreetingController.java create mode 100644 spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/GreetingService.java create mode 100644 spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/NettyWebServerFactoryPortCustomizer.java create mode 100644 spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/NettyWebServerFactorySslCustomizer.java create mode 100644 spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/ServerConfigApplication.java create mode 100644 spring-5-webflux/src/main/resources/logback.xml create mode 100644 spring-5-webflux/src/main/resources/sample.jks rename spring-5-webflux/src/test/java/com/baeldung/spring/responsestatus/{ResponseStatusControllerTests.java => ResponseStatusControllerLiveTest.java} (97%) create mode 100644 spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingControllerIntegrationTest.java create mode 100644 spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingLiveTest.java create mode 100644 spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingSkipAutoConfigLiveTest.java create mode 100644 spring-5-webflux/src/test/resources/logback-test.xml diff --git a/spring-5-webflux/pom.xml b/spring-5-webflux/pom.xml index d7fb7b7930..3306fd1729 100644 --- a/spring-5-webflux/pom.xml +++ b/spring-5-webflux/pom.xml @@ -1,23 +1,20 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung spring-5-webflux 1.0-SNAPSHOT - spring-5-webflux - http://www.baeldung.com - - UTF-8 - 1.8 - 1.8 - 2.0.2.RELEASE - + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + @@ -58,12 +55,8 @@ - maven-compiler-plugin - 3.8.0 - - - maven-surefire-plugin - 2.22.1 + org.springframework.boot + spring-boot-maven-plugin diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/CustomNettyWebServerFactory.java b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/CustomNettyWebServerFactory.java new file mode 100644 index 0000000000..f9de3b4006 --- /dev/null +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/CustomNettyWebServerFactory.java @@ -0,0 +1,36 @@ +package com.baeldung.spring.serverconfig; + +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import reactor.netty.http.server.HttpServer; + +@Configuration +@Profile("skipAutoConfig") +public class CustomNettyWebServerFactory { + + @Bean + public NettyReactiveWebServerFactory nettyReactiveWebServerFactory() { + NettyReactiveWebServerFactory webServerFactory = new NettyReactiveWebServerFactory(); + webServerFactory.addServerCustomizers(new EventLoopNettyCustomizer()); + return webServerFactory; + } + + private static class EventLoopNettyCustomizer implements NettyServerCustomizer { + + @Override + public HttpServer apply(HttpServer httpServer) { + EventLoopGroup parentGroup = new NioEventLoopGroup(); + EventLoopGroup childGroup = new NioEventLoopGroup(); + return httpServer + .tcpConfiguration(tcpServer -> tcpServer.bootstrap( + serverBootstrap -> serverBootstrap.group(parentGroup, childGroup).channel(NioServerSocketChannel.class) + )); + } + } +} diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/GreetingController.java b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/GreetingController.java new file mode 100644 index 0000000000..990ea5cf83 --- /dev/null +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/GreetingController.java @@ -0,0 +1,23 @@ +package com.baeldung.spring.serverconfig; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Mono; + +@RestController +@RequestMapping("/greet") +public class GreetingController { + + private final GreetingService greetingService; + + public GreetingController(GreetingService greetingService) { + this.greetingService = greetingService; + } + + @GetMapping("/{name}") + private Mono greet(@PathVariable String name) { + return greetingService.greet(name); + } +} diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/GreetingService.java b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/GreetingService.java new file mode 100644 index 0000000000..a6243b2bd0 --- /dev/null +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/GreetingService.java @@ -0,0 +1,12 @@ +package com.baeldung.spring.serverconfig; + +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +@Service +public class GreetingService { + + public Mono greet(String name) { + return Mono.just("Greeting " + name); + } +} diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/NettyWebServerFactoryPortCustomizer.java b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/NettyWebServerFactoryPortCustomizer.java new file mode 100644 index 0000000000..fdde130286 --- /dev/null +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/NettyWebServerFactoryPortCustomizer.java @@ -0,0 +1,30 @@ +package com.baeldung.spring.serverconfig; + +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; +import reactor.netty.http.server.HttpServer; + +@Component +public class NettyWebServerFactoryPortCustomizer implements WebServerFactoryCustomizer { + + @Override + public void customize(NettyReactiveWebServerFactory serverFactory) { + serverFactory.addServerCustomizers(new PortCustomizer(8443)); + } + + private static class PortCustomizer implements NettyServerCustomizer { + + private final int port; + + private PortCustomizer(int port) { + this.port = port; + } + + @Override + public HttpServer apply(HttpServer httpServer) { + return httpServer.port(port); + } + } +} diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/NettyWebServerFactorySslCustomizer.java b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/NettyWebServerFactorySslCustomizer.java new file mode 100644 index 0000000000..cf4e5ac8ea --- /dev/null +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/NettyWebServerFactorySslCustomizer.java @@ -0,0 +1,26 @@ +package com.baeldung.spring.serverconfig; + +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.embedded.netty.SslServerCustomizer; +import org.springframework.boot.web.server.Http2; +import org.springframework.boot.web.server.Ssl; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; + +@Component +public class NettyWebServerFactorySslCustomizer implements WebServerFactoryCustomizer { + + @Override + public void customize(NettyReactiveWebServerFactory serverFactory) { + Ssl ssl = new Ssl(); + ssl.setEnabled(true); + ssl.setKeyStore("classpath:sample.jks"); + ssl.setKeyAlias("alias"); + ssl.setKeyPassword("password"); + ssl.setKeyStorePassword("secret"); + Http2 http2 = new Http2(); + http2.setEnabled(false); + serverFactory.addServerCustomizers(new SslServerCustomizer(ssl, http2, null)); + serverFactory.setPort(8443); + } +} diff --git a/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/ServerConfigApplication.java b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/ServerConfigApplication.java new file mode 100644 index 0000000000..b4f6006be3 --- /dev/null +++ b/spring-5-webflux/src/main/java/com/baeldung/spring/serverconfig/ServerConfigApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.spring.serverconfig; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ServerConfigApplication { + + public static void main(String[] args) { + SpringApplication.run(ServerConfigApplication.class, args); + } +} diff --git a/spring-5-webflux/src/main/resources/logback.xml b/spring-5-webflux/src/main/resources/logback.xml new file mode 100644 index 0000000000..48b68c6bf1 --- /dev/null +++ b/spring-5-webflux/src/main/resources/logback.xml @@ -0,0 +1,31 @@ + + + + + + %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable + + + + + + netty-access.log + + %msg%n + + + + + + + + + + + + + + + + diff --git a/spring-5-webflux/src/main/resources/sample.jks b/spring-5-webflux/src/main/resources/sample.jks new file mode 100644 index 0000000000000000000000000000000000000000..6aa9a28053a591e41453e665e5024e8a8cb78b3d GIT binary patch literal 2264 zcmchYX*3iJ7sqE|hQS!q5Mv)4GM2$i#uAFqC`%7x7baWA*i&dRX>3`uq(XS?3XSYp z%38`&ib7E$8j~$cF^}gt?|I+noW8#w?uYxk=iGD8|K9Vzd#pVc0002(2k@T|2@MMI zqxqr2AhQO*TVi`j@((S;e;g;l$#dAA{>vf0kX$R(Qn4oKgGEYjZ5zti2dw?Z6A zh%LuFCNI?9o+Z1duJL-++e#cjO`zlK?u9s030=k_*wD1#-$FbIDRDnA^vo@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UJ8nM`$7S*mfKR z#9-JzPRZ?{M!@L+0N^V)IyeeP2T|^UK|m0QD+Ibs!wEoml^N!YO#vW~j~jraX(0A3 z6Kux?IRLez`O^X;{!4g%BhcRn>^H*qKZ3*|{_YGuz)KCJcu;)DSES5D2tDE`C02YR0R%Vy1T7k|RQ;3g<0icA$AuP0pOvc~jGl zz+NeKv_FT_;GWK&8XlDUv&hv9kxg?@c!bu?83i=YQ$S!K09Y)Glg3Hz?@|)ZCBlVz zP8i}#XZkMoje3I=h&I!!s_m?Qi@1MR`yv7X*yEs47qOs^t^?&=;*IQ!q&)gq_Sx5* z?fhU8Q*PSe*w7y)FH#P!9R^Xw!lTT+zI39L<&8cViaj$A(Z2Cg7!{V?uuyi#vlNCg z40i}2ivw&y&1-&Nh&WMG`&aIt>)(#tKTJ}^@696Kw1-{IzSOTnFF+0@k$o3%ZHS;Q#;t literal 0 HcmV?d00001 diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/responsestatus/ResponseStatusControllerTests.java b/spring-5-webflux/src/test/java/com/baeldung/spring/responsestatus/ResponseStatusControllerLiveTest.java similarity index 97% rename from spring-5-webflux/src/test/java/com/baeldung/spring/responsestatus/ResponseStatusControllerTests.java rename to spring-5-webflux/src/test/java/com/baeldung/spring/responsestatus/ResponseStatusControllerLiveTest.java index 5112c8ceb2..4c6708e423 100644 --- a/spring-5-webflux/src/test/java/com/baeldung/spring/responsestatus/ResponseStatusControllerTests.java +++ b/spring-5-webflux/src/test/java/com/baeldung/spring/responsestatus/ResponseStatusControllerLiveTest.java @@ -9,7 +9,7 @@ import org.springframework.test.web.reactive.server.WebTestClient; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class ResponseStatusControllerTests { +public class ResponseStatusControllerLiveTest { @Autowired private WebTestClient testClient; diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingControllerIntegrationTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingControllerIntegrationTest.java new file mode 100644 index 0000000000..ce156beb3f --- /dev/null +++ b/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingControllerIntegrationTest.java @@ -0,0 +1,41 @@ +package com.baeldung.spring.serverconfig; + +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.reactive.server.WebTestClient; +import reactor.core.publisher.Mono; + +@RunWith(SpringRunner.class) +@WebFluxTest +public class GreetingControllerIntegrationTest { + + @Autowired + private WebTestClient webClient; + + @MockBean + private GreetingService greetingService; + + private final String name = "Baeldung"; + + @Before + public void setUp() { + when(greetingService.greet(name)).thenReturn(Mono.just("Greeting Baeldung")); + } + + @Test + public void shouldGreet() { + webClient.get().uri("/greet/{name}", name) + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("Greeting Baeldung"); + } +} diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingLiveTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingLiveTest.java new file mode 100644 index 0000000000..2400272c6e --- /dev/null +++ b/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingLiveTest.java @@ -0,0 +1,57 @@ +package com.baeldung.spring.serverconfig; + +import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; +import io.netty.handler.ssl.util.InsecureTrustManagerFactory; +import javax.net.ssl.SSLException; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; +import reactor.netty.http.client.HttpClient; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) +@DirtiesContext +public class GreetingLiveTest { + + private static final String BASE_URL = "https://localhost:8443"; + + private WebTestClient webTestClient; + + @Before + public void setup() throws SSLException { + webTestClient = WebTestClient.bindToServer(getConnector()) + .baseUrl(BASE_URL) + .build(); + } + + @Test + public void shouldGreet() { + final String name = "Baeldung"; + + ResponseSpec response = webTestClient.get() + .uri("/greet/{name}", name) + .exchange(); + + response.expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("Greeting Baeldung"); + } + + private ReactorClientHttpConnector getConnector() throws SSLException { + SslContext sslContext = SslContextBuilder + .forClient() + .trustManager(InsecureTrustManagerFactory.INSTANCE) + .build(); + HttpClient httpClient = HttpClient.create().secure(t -> t.sslContext(sslContext)); + return new ReactorClientHttpConnector(httpClient); + } +} diff --git a/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingSkipAutoConfigLiveTest.java b/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingSkipAutoConfigLiveTest.java new file mode 100644 index 0000000000..45918dfd70 --- /dev/null +++ b/spring-5-webflux/src/test/java/com/baeldung/spring/serverconfig/GreetingSkipAutoConfigLiveTest.java @@ -0,0 +1,8 @@ +package com.baeldung.spring.serverconfig; + +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles("skipAutoConfig") +public class GreetingSkipAutoConfigLiveTest extends GreetingLiveTest { + +} diff --git a/spring-5-webflux/src/test/resources/logback-test.xml b/spring-5-webflux/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..12cedf5952 --- /dev/null +++ b/spring-5-webflux/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ + + + + + + %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable + + + + + + + From c2db7e83575dd8a4196979451f8e1f731bbd0f2f Mon Sep 17 00:00:00 2001 From: isaolmez Date: Wed, 27 Mar 2019 21:38:08 +0300 Subject: [PATCH 2/4] BAEL-2715: Removed spring-5-reactive-netty module --- pom.xml | 2 +- spring-5-reactive-netty/.gitignore | 11 ---- spring-5-reactive-netty/README.md | 3 - spring-5-reactive-netty/pom.xml | 51 ---------------- .../CustomNettyWebServerFactory.java | 36 ----------- .../serverconfig/GreetingController.java | 23 ------- .../serverconfig/GreetingService.java | 12 ---- .../NettyWebServerFactoryPortCustomizer.java | 30 ---------- .../NettyWebServerFactorySslCustomizer.java | 26 -------- .../serverconfig/ServerConfigApplication.java | 12 ---- .../src/main/resources/logback.xml | 31 ---------- .../src/main/resources/sample.jks | Bin 2264 -> 0 bytes .../GreetingControllerIntegrationTest.java | 41 ------------- .../serverconfig/GreetingLiveTest.java | 56 ------------------ .../GreetingSkipAutoConfigLiveTest.java | 8 --- .../src/test/resources/logback-test.xml | 13 ---- 16 files changed, 1 insertion(+), 354 deletions(-) delete mode 100644 spring-5-reactive-netty/.gitignore delete mode 100644 spring-5-reactive-netty/README.md delete mode 100644 spring-5-reactive-netty/pom.xml delete mode 100644 spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/CustomNettyWebServerFactory.java delete mode 100644 spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/GreetingController.java delete mode 100644 spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/GreetingService.java delete mode 100644 spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/NettyWebServerFactoryPortCustomizer.java delete mode 100644 spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/NettyWebServerFactorySslCustomizer.java delete mode 100644 spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/ServerConfigApplication.java delete mode 100644 spring-5-reactive-netty/src/main/resources/logback.xml delete mode 100644 spring-5-reactive-netty/src/main/resources/sample.jks delete mode 100644 spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingControllerIntegrationTest.java delete mode 100644 spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingLiveTest.java delete mode 100644 spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingSkipAutoConfigLiveTest.java delete mode 100644 spring-5-reactive-netty/src/test/resources/logback-test.xml diff --git a/pom.xml b/pom.xml index 7af92fbd11..7cb57a9077 100644 --- a/pom.xml +++ b/pom.xml @@ -577,12 +577,12 @@ spring-4 spring-5 + spring-5-webflux spring-5-mvc spring-5-reactive spring-5-reactive-client spring-5-reactive-oauth spring-5-reactive-security - spring-5-reactive-netty spring-5-security spring-5-security-oauth diff --git a/spring-5-reactive-netty/.gitignore b/spring-5-reactive-netty/.gitignore deleted file mode 100644 index 70ed41e73a..0000000000 --- a/spring-5-reactive-netty/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Folders # -**/.idea -**/target - -# Files # -*.log - -# Packaged files # -*.jar -*.war -*.ear \ No newline at end of file diff --git a/spring-5-reactive-netty/README.md b/spring-5-reactive-netty/README.md deleted file mode 100644 index 09f7cc0e24..0000000000 --- a/spring-5-reactive-netty/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Spring 5 Reactive Project With Netty Server - -Includes configuration options for Netty server. diff --git a/spring-5-reactive-netty/pom.xml b/spring-5-reactive-netty/pom.xml deleted file mode 100644 index 48fc0b201f..0000000000 --- a/spring-5-reactive-netty/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - 4.0.0 - com.baeldung - spring-5-reactive-netty - 0.0.1-SNAPSHOT - spring-5-reactive-netty - jar - Spring 5 sample project about reactive web with Netty server - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-webflux - - - - org.projectlombok - lombok - - - - org.springframework.boot - spring-boot-devtools - runtime - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/CustomNettyWebServerFactory.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/CustomNettyWebServerFactory.java deleted file mode 100644 index 8a1cdbba97..0000000000 --- a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/CustomNettyWebServerFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.serverconfig; - -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; -import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import reactor.netty.http.server.HttpServer; - -@Configuration -@Profile("skipAutoConfig") -public class CustomNettyWebServerFactory { - - @Bean - public NettyReactiveWebServerFactory nettyReactiveWebServerFactory() { - NettyReactiveWebServerFactory webServerFactory = new NettyReactiveWebServerFactory(); - webServerFactory.addServerCustomizers(new EventLoopNettyCustomizer()); - return webServerFactory; - } - - private static class EventLoopNettyCustomizer implements NettyServerCustomizer { - - @Override - public HttpServer apply(HttpServer httpServer) { - EventLoopGroup parentGroup = new NioEventLoopGroup(); - EventLoopGroup childGroup = new NioEventLoopGroup(); - return httpServer - .tcpConfiguration(tcpServer -> tcpServer.bootstrap( - serverBootstrap -> serverBootstrap.group(parentGroup, childGroup).channel(NioServerSocketChannel.class) - )); - } - } -} diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/GreetingController.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/GreetingController.java deleted file mode 100644 index 9cb5b27ac5..0000000000 --- a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/GreetingController.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.serverconfig; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import reactor.core.publisher.Mono; - -@RestController -@RequestMapping("/greet") -public class GreetingController { - - private final GreetingService greetingService; - - public GreetingController(GreetingService greetingService) { - this.greetingService = greetingService; - } - - @GetMapping("/{name}") - private Mono greet(@PathVariable String name) { - return greetingService.greet(name); - } -} diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/GreetingService.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/GreetingService.java deleted file mode 100644 index 5440f526aa..0000000000 --- a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/GreetingService.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.serverconfig; - -import org.springframework.stereotype.Service; -import reactor.core.publisher.Mono; - -@Service -public class GreetingService { - - public Mono greet(String name) { - return Mono.just("Greeting " + name); - } -} diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/NettyWebServerFactoryPortCustomizer.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/NettyWebServerFactoryPortCustomizer.java deleted file mode 100644 index 152e1285aa..0000000000 --- a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/NettyWebServerFactoryPortCustomizer.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.serverconfig; - -import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; -import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; -import org.springframework.stereotype.Component; -import reactor.netty.http.server.HttpServer; - -@Component -public class NettyWebServerFactoryPortCustomizer implements WebServerFactoryCustomizer { - - @Override - public void customize(NettyReactiveWebServerFactory serverFactory) { - serverFactory.addServerCustomizers(new PortCustomizer(8443)); - } - - private static class PortCustomizer implements NettyServerCustomizer { - - private final int port; - - private PortCustomizer(int port) { - this.port = port; - } - - @Override - public HttpServer apply(HttpServer httpServer) { - return httpServer.port(port); - } - } -} diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/NettyWebServerFactorySslCustomizer.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/NettyWebServerFactorySslCustomizer.java deleted file mode 100644 index d0ad0dcac5..0000000000 --- a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/NettyWebServerFactorySslCustomizer.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.serverconfig; - -import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; -import org.springframework.boot.web.embedded.netty.SslServerCustomizer; -import org.springframework.boot.web.server.Http2; -import org.springframework.boot.web.server.Ssl; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; -import org.springframework.stereotype.Component; - -@Component -public class NettyWebServerFactorySslCustomizer implements WebServerFactoryCustomizer { - - @Override - public void customize(NettyReactiveWebServerFactory serverFactory) { - Ssl ssl = new Ssl(); - ssl.setEnabled(true); - ssl.setKeyStore("classpath:sample.jks"); - ssl.setKeyAlias("alias"); - ssl.setKeyPassword("password"); - ssl.setKeyStorePassword("secret"); - Http2 http2 = new Http2(); - http2.setEnabled(false); - serverFactory.addServerCustomizers(new SslServerCustomizer(ssl, http2, null)); - serverFactory.setPort(8443); - } -} diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/ServerConfigApplication.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/ServerConfigApplication.java deleted file mode 100644 index 9d420cc7da..0000000000 --- a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/ServerConfigApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.serverconfig; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class ServerConfigApplication { - - public static void main(String[] args) { - SpringApplication.run(ServerConfigApplication.class, args); - } -} diff --git a/spring-5-reactive-netty/src/main/resources/logback.xml b/spring-5-reactive-netty/src/main/resources/logback.xml deleted file mode 100644 index 48b68c6bf1..0000000000 --- a/spring-5-reactive-netty/src/main/resources/logback.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable - - - - - - netty-access.log - - %msg%n - - - - - - - - - - - - - - - - diff --git a/spring-5-reactive-netty/src/main/resources/sample.jks b/spring-5-reactive-netty/src/main/resources/sample.jks deleted file mode 100644 index 6aa9a28053a591e41453e665e5024e8a8cb78b3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2264 zcmchYX*3iJ7sqE|hQS!q5Mv)4GM2$i#uAFqC`%7x7baWA*i&dRX>3`uq(XS?3XSYp z%38`&ib7E$8j~$cF^}gt?|I+noW8#w?uYxk=iGD8|K9Vzd#pVc0002(2k@T|2@MMI zqxqr2AhQO*TVi`j@((S;e;g;l$#dAA{>vf0kX$R(Qn4oKgGEYjZ5zti2dw?Z6A zh%LuFCNI?9o+Z1duJL-++e#cjO`zlK?u9s030=k_*wD1#-$FbIDRDnA^vo@fm( zzjt(3VJrGOr0iHXSTM|rYN#>RZ@Dp`PwB2zrDQffLvuoR2~V3ReYa0&vU^dXd8isV zsAf*@!8s%xBvHLseXn6f?1kefe(8uAmAbaF$x{Ykzb6c6jdUwY1$y4tFzsj7 zIghr!T#ODfu@Po!a29@kXQ8kY#(LE<0o7?7PQ|eMeY@Equ?R-6*f@Na3o&stDQ=6( zQzDSQhCnS(9Bu9W_~giknP0vECqUsr4_9y_}nEU`cy z4}dApnAip92wMwgzciAFpc3i}+-#Zlq+iF7d1y}d4Qsp8=%l1N8NIs161I`HmkcpQ zY4*CUCFJJf(2!M{`&qQ}3($KeTQ=)mMrBs`DOb;%Of0tC)9he_p~w&CO#DfCgx(%s z{@|D(brX_Gb}ZDLmGej*JgEl0Et>q~kgTXuJg-PwvRjNx8sBbIShxD=xOySzw{;^X zAvrh5HTg>Xq@<{#^!Kg}B?qz@b<{ebD)yaSf&RChBIJQo-?Ahzw@qopSe^e&>^IuU zydM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egrationTest.java b/spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingControllerIntegrationTest.java deleted file mode 100644 index 3c2c08321a..0000000000 --- a/spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingControllerIntegrationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.serverconfig; - -import static org.mockito.Mockito.when; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.reactive.server.WebTestClient; -import reactor.core.publisher.Mono; - -@RunWith(SpringRunner.class) -@WebFluxTest -public class GreetingControllerIntegrationTest { - - @Autowired - private WebTestClient webClient; - - @MockBean - private GreetingService greetingService; - - private final String name = "Baeldung"; - - @Before - public void setUp() { - when(greetingService.greet(name)).thenReturn(Mono.just("Greeting Baeldung")); - } - - @Test - public void shouldGreet() { - webClient.get().uri("/greet/{name}", name) - .exchange() - .expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("Greeting Baeldung"); - } -} diff --git a/spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingLiveTest.java b/spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingLiveTest.java deleted file mode 100644 index 7c4a37c890..0000000000 --- a/spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingLiveTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.serverconfig; - -import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.SslContextBuilder; -import io.netty.handler.ssl.util.InsecureTrustManagerFactory; -import javax.net.ssl.SSLException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.client.reactive.ReactorClientHttpConnector; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.reactive.server.WebTestClient; -import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; -import reactor.netty.http.client.HttpClient; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) -public class GreetingLiveTest { - - private static final String BASE_URL = "https://localhost:8443"; - - private WebTestClient webTestClient; - - @Before - public void setup() throws SSLException { - webTestClient = WebTestClient.bindToServer(getConnector()) - .baseUrl(BASE_URL) - .build(); - } - - @Test - public void shouldGreet() { - final String name = "Baeldung"; - - ResponseSpec response = webTestClient.get() - .uri("/greet/{name}", name) - .exchange(); - - response.expectStatus() - .isOk() - .expectBody(String.class) - .isEqualTo("Greeting Baeldung"); - } - - private ReactorClientHttpConnector getConnector() throws SSLException { - SslContext sslContext = SslContextBuilder - .forClient() - .trustManager(InsecureTrustManagerFactory.INSTANCE) - .build(); - HttpClient httpClient = HttpClient.create().secure(t -> t.sslContext(sslContext)); - return new ReactorClientHttpConnector(httpClient); - } -} diff --git a/spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingSkipAutoConfigLiveTest.java b/spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingSkipAutoConfigLiveTest.java deleted file mode 100644 index 646742b3d7..0000000000 --- a/spring-5-reactive-netty/src/test/java/com/baeldung/serverconfig/GreetingSkipAutoConfigLiveTest.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.serverconfig; - -import org.springframework.test.context.ActiveProfiles; - -@ActiveProfiles("skipAutoConfig") -public class GreetingSkipAutoConfigLiveTest extends GreetingLiveTest { - -} diff --git a/spring-5-reactive-netty/src/test/resources/logback-test.xml b/spring-5-reactive-netty/src/test/resources/logback-test.xml deleted file mode 100644 index 12cedf5952..0000000000 --- a/spring-5-reactive-netty/src/test/resources/logback-test.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable - - - - - - - From 73a58cc3b1f450df6fb8a263d9e38794d0b03dde Mon Sep 17 00:00:00 2001 From: isaolmez Date: Wed, 27 Mar 2019 21:41:07 +0300 Subject: [PATCH 3/4] BAEL-2715: Removed spring-5-reactive-netty module --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7cb57a9077..615fc7b46e 100644 --- a/pom.xml +++ b/pom.xml @@ -577,7 +577,7 @@ spring-4 spring-5 - spring-5-webflux + spring-5-webflux spring-5-mvc spring-5-reactive spring-5-reactive-client From cf37a11ddfa0c87bd4dcae56aee62b48d900a11c Mon Sep 17 00:00:00 2001 From: isaolmez Date: Wed, 27 Mar 2019 21:46:44 +0300 Subject: [PATCH 4/4] BAEL-2715: Removed spring-5-reactive-netty module --- spring-5-webflux/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 spring-5-webflux/.gitignore diff --git a/spring-5-webflux/.gitignore b/spring-5-webflux/.gitignore new file mode 100644 index 0000000000..aa4871eeea --- /dev/null +++ b/spring-5-webflux/.gitignore @@ -0,0 +1,2 @@ +# Files # +*.log \ No newline at end of file