JAVA-24463 Cleanup spring-reactive-modules (#14989)

* JAVA-24463 Renaming spring-data-couchbase into spring-reactive-data-couchbase

* JAVA-24463 Moving spring boot actuator from spring reactive security to spring reactive 3

* JAVA-24463 Migrating URL matching and set header on response from spring-5 reactive to spring reactive-2

* JAVA-24463 Migrating reactive websocket and session reactive support to spring-reactive-3

---------

Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
timis1 2023-10-17 06:30:29 +03:00 committed by GitHub
parent 0eac8610bd
commit c30b23a140
84 changed files with 51 additions and 303 deletions

View File

@ -19,7 +19,6 @@
<modules> <modules>
<module>spring-reactive-data</module> <module>spring-reactive-data</module>
<module>spring-reactive-data-2</module> <module>spring-reactive-data-2</module>
<module>spring-5-reactive</module>
<module>spring-reactive-2</module> <module>spring-reactive-2</module>
<module>spring-reactive-3</module> <module>spring-reactive-3</module>
<module>spring-reactive-client</module> <module>spring-reactive-client</module>
@ -27,7 +26,7 @@
<module>spring-reactive-filters</module> <module>spring-reactive-filters</module>
<module>spring-reactive-oauth</module> <module>spring-reactive-oauth</module>
<module>spring-reactive-security</module> <module>spring-reactive-security</module>
<module>spring-data-couchbase</module> <module>spring-reactive-data-couchbase</module>
<module>spring-reactive</module> <module>spring-reactive</module>
<module>spring-reactive-exceptions</module> <module>spring-reactive-exceptions</module>
<module>spring-reactor</module> <module>spring-reactor</module>
@ -64,7 +63,4 @@
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<properties>
</properties>
</project> </project>

View File

@ -1,12 +0,0 @@
#folders#
.idea
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
# Packaged files #
*.jar
*.war
*.ear

View File

@ -1,14 +0,0 @@
## Spring 5 Reactive Project
This module contains articles about reactive Spring Boot
### The Course
The "REST With Spring" Classes: https://bit.ly/restwithspring
### Relevant Articles
- [Exploring the Spring 5 WebFlux URL Matching](https://www.baeldung.com/spring-5-mvc-url-matching)
- [Reactive WebSockets with Spring 5](https://www.baeldung.com/spring-5-reactive-websockets)
- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header)
- [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive)
- More articles: [[next -->]](../spring-5-reactive-2)

View File

@ -1,164 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-5-reactive</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-5-reactive</name>
<packaging>jar</packaging>
<description>spring 5 sample project about new features</description>
<parent>
<groupId>com.baeldung.spring.reactive</groupId>
<artifactId>spring-reactive-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-json_1.1_spec</artifactId>
<version>${geronimo-json_1.1_spec.version}</version>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jsonb</artifactId>
</dependency>
<!-- utils -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- runtime and test scoped -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring WebFlux WebSession -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/assets</directory>
<filtering>true</filtering>
</resource>
</resources>
<outputDirectory>${basedir}/target/classes/assets</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.reactive.Spring5ReactiveApplication</mainClass>
<layout>JAR</layout>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<johnzon.version>1.1.3</johnzon.version>
<jsonb-api.version>1.0</jsonb-api.version>
<geronimo-json_1.1_spec.version>1.0</geronimo-json_1.1_spec.version>
</properties>
</project>

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Baeldung: Static Content in Spring WebFlux</title>
</head>
<body>
Example Spring Web Flux and web resources configuration
</body>
</html>

View File

@ -1,56 +0,0 @@
package com.baeldung.websession.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.core.userdetails.MapReactiveUserDetailsService;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.server.SecurityWebFilterChain;
import org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository;
@Configuration
@EnableWebFluxSecurity
public class WebFluxSecurityConfig {
@Bean
public MapReactiveUserDetailsService userDetailsService() {
UserDetails admin = User
.withUsername("admin")
.password(encoder().encode("password"))
.roles("ADMIN")
.build();
UserDetails user = User
.withUsername("user")
.password(encoder().encode("password"))
.roles("USER")
.build();
return new MapReactiveUserDetailsService(admin, user);
}
@Bean
public SecurityWebFilterChain webSessionSpringSecurityFilterChain(ServerHttpSecurity http) {
http.authorizeExchange()
.anyExchange().authenticated()
.and()
.httpBasic()
.securityContextRepository(new WebSessionServerSecurityContextRepository())
.and()
.formLogin();
http.csrf().disable();
return http.build();
}
@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}
}

View File

@ -1,2 +0,0 @@
logging.level.root=INFO
server.tomcat.max-keep-alive-requests=1

View File

@ -7,4 +7,6 @@ This module contains articles about reactive Spring Boot.
- [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content) - [Static Content in Spring WebFlux](https://www.baeldung.com/spring-webflux-static-content)
- [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events) - [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events)
- [Backpressure Mechanism in Spring WebFlux](https://www.baeldung.com/spring-webflux-backpressure) - [Backpressure Mechanism in Spring WebFlux](https://www.baeldung.com/spring-webflux-backpressure)
- [Exploring the Spring 5 WebFlux URL Matching](https://www.baeldung.com/spring-5-mvc-url-matching)
- [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header)
- More articles: [[<-- prev]](../spring-5-reactive) [[next -->]](../spring-5-reactive-3) - More articles: [[<-- prev]](../spring-5-reactive) [[next -->]](../spring-5-reactive-3)

View File

@ -59,6 +59,10 @@
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -32,7 +32,7 @@ public class ExploreSpring5URLPatternUsingRouterFunctions {
.and(RouterFunctions.resources("/resources/**", new ClassPathResource("resources/"))); .and(RouterFunctions.resources("/resources/**", new ClassPathResource("resources/")));
} }
WebServer start() throws Exception { WebServer start() {
WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction()); WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction());
HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler) HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler)
.filter(new IndexRewriteFilter()) .filter(new IndexRewriteFilter())

View File

@ -5,4 +5,7 @@ This module contains articles about reactive Spring Boot.
- [Logging a Reactive Sequence](https://www.baeldung.com/spring-reactive-sequence-logging) - [Logging a Reactive Sequence](https://www.baeldung.com/spring-reactive-sequence-logging)
- [Reading Flux Into a Single InputStream Using Spring Reactive WebClient](https://www.baeldung.com/spring-reactive-read-flux-into-inputstream) - [Reading Flux Into a Single InputStream Using Spring Reactive WebClient](https://www.baeldung.com/spring-reactive-read-flux-into-inputstream)
- [Cancel an Ongoing Flux in Spring WebFlux](https://www.baeldung.com/spring-webflux-cancel-flux) - [Cancel an Ongoing Flux in Spring WebFlux](https://www.baeldung.com/spring-webflux-cancel-flux)
- [Spring Boot Actuator](https://www.baeldung.com/spring-boot-actuators)
- [Reactive WebSockets with Spring 5](https://www.baeldung.com/spring-5-reactive-websockets)
- [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive)
- More articles: [[<-- prev]](../spring-5-reactive-2) - More articles: [[<-- prev]](../spring-5-reactive-2)

View File

@ -47,6 +47,22 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>

View File

@ -2,8 +2,10 @@ package com.baeldung.reactive.actuator;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication @SpringBootApplication
@ComponentScan(basePackages = "com.baeldung.reactive.actuator")
public class Spring5ReactiveApplication { public class Spring5ReactiveApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -4,7 +4,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer; import org.springframework.web.reactive.config.WebFluxConfigurer;
@Configuration @Configuration

View File

@ -1 +1,13 @@
# application properties # application properties
management.endpoints.web.exposure.include=*
info.app.name=Spring Boot 2 actuator Application
management.endpoint.health.group.custom.include=diskSpace,ping
management.endpoint.health.group.custom.show-components=always
management.endpoint.health.group.custom.show-details=always
management.endpoint.health.group.custom.status.http-mapping.up=207
spring.main.allow-bean-definition-overriding=true
logging.level.root=INFO
server.tomcat.max-keep-alive-requests=1

View File

@ -5,10 +5,10 @@ import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.reactive.Spring5ReactiveApplication; import com.baeldung.functional.FunctionalWebApplication;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5ReactiveApplication.class) @SpringBootTest(classes = FunctionalWebApplication.class)
public class SpringContextTest { public class SpringContextTest {
@Test @Test

View File

@ -9,8 +9,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ -21,13 +19,13 @@ public class ActuatorInfoIntegrationTest {
private TestRestTemplate restTemplate; private TestRestTemplate restTemplate;
@Test @Test
public void whenGetInfo_thenReturns200() throws IOException { public void whenGetInfo_thenReturns200() {
final ResponseEntity<String> responseEntity = this.restTemplate.getForEntity("/actuator/info", String.class); final ResponseEntity<String> responseEntity = this.restTemplate.getForEntity("/actuator/info", String.class);
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
} }
@Test @Test
public void whenFeatures_thenReturns200() throws IOException { public void whenFeatures_thenReturns200() {
final ResponseEntity<String> responseEntity = this.restTemplate.getForEntity("/actuator/features", String.class); final ResponseEntity<String> responseEntity = this.restTemplate.getForEntity("/actuator/features", String.class);
assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
} }

View File

@ -3,7 +3,7 @@
xmlns="http://maven.apache.org/POM/4.0.0" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>spring-data-couchbase</artifactId> <artifactId>spring-reactive-data-couchbase</artifactId>
<name>spring-data-couchbase</name> <name>spring-data-couchbase</name>
<packaging>jar</packaging> <packaging>jar</packaging>

View File

@ -7,6 +7,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
### Relevant Articles ### Relevant Articles
- [Spring Boot Actuator](https://www.baeldung.com/spring-boot-actuators)
- [Guide to the AuthenticationManagerResolver in Spring Security](https://www.baeldung.com/spring-security-authenticationmanagerresolver) - [Guide to the AuthenticationManagerResolver in Spring Security](https://www.baeldung.com/spring-security-authenticationmanagerresolver)
- [Spring Webflux and CORS](https://www.baeldung.com/spring-webflux-cors) - [Spring Webflux and CORS](https://www.baeldung.com/spring-webflux-cors)

View File

@ -37,10 +37,6 @@
<groupId>javax.json.bind</groupId> <groupId>javax.json.bind</groupId>
<artifactId>javax.json.bind-api</artifactId> <artifactId>javax.json.bind-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>

View File

@ -1,23 +0,0 @@
package com.baeldung.reactive.actuator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.security.config.web.server.ServerHttpSecurity;
import org.springframework.security.web.server.SecurityWebFilterChain;
@Configuration
@EnableWebFluxSecurity
public class WebSecurityConfig {
@Bean
public SecurityWebFilterChain securitygWebFilterChain(
ServerHttpSecurity http) {
return http.authorizeExchange()
.pathMatchers("/actuator/**").permitAll()
.anyExchange().authenticated()
.and().build();
}
}

View File

@ -1,13 +1,14 @@
package com.baeldung; package com.baeldung;
import com.baeldung.reactive.actuator.Spring5ReactiveApplication;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.webflux.EmployeeWebSocketClient;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Spring5ReactiveApplication.class) @SpringBootTest(classes = EmployeeWebSocketClient.class)
public class SpringContextTest { public class SpringContextTest {
@Test @Test