Skip to content

Commit cee5dcf

Browse files
author
Eugen Paraschiv
committed
adding new module
1 parent 112f33a commit cee5dcf

59 files changed

Lines changed: 2639 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<module>persistence-modules/solr</module>
142142
<module>spark-java</module>
143143
<!-- <module>spring-5</module>-->
144+
<module>spring-5-reactive</module>
144145
<module>spring-5-mvc</module>
145146
<module>spring-activiti</module>
146147
<module>spring-akka</module>

‎spring-5-reactive/.gitignore‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#folders#
2+
.idea
3+
/target
4+
/neoDb*
5+
/data
6+
/src/main/webapp/WEB-INF/classes
7+
*/META-INF/*
8+
9+
# Packaged files #
10+
*.jar
11+
*.war
12+
*.ear

‎spring-5-reactive/README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Spring REST Example Project
2+
3+
### The Course
4+
The "REST With Spring" Classes: http://bit.ly/restwithspring
5+
6+
### Relevant Articles
7+
8+
- [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests)
9+
- [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web)
10+
- [Exploring the Spring 5 MVC URL Matching Improvements](http://www.baeldung.com/spring-5-mvc-url-matching)
11+
- [Spring 5 WebClient](http://www.baeldung.com/spring-5-webclient)
12+
- [Spring 5 Functional Bean Registration](http://www.baeldung.com/spring-5-functional-beans)
13+
- [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](http://www.baeldung.com/spring-5-junit-config)
14+
- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive)
15+
- [Spring 5 Testing with @EnabledIf Annotation](https://github.com/eugenp/tutorials/tree/master/spring-5)

‎spring-5-reactive/pom.xml‎

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.baeldung</groupId>
6+
<artifactId>spring-5-reactive</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>spring-5</name>
11+
<description>spring 5 sample project about new features</description>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>2.0.0.M7</version>
17+
<relativePath /> <!-- lookup parent from repository -->
18+
</parent>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-data-jpa</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-security</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-validation</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-webflux</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.projectreactor</groupId>
43+
<artifactId>reactor-spring</artifactId>
44+
<version>${reactor-spring.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>javax.json.bind</groupId>
48+
<artifactId>javax.json.bind-api</artifactId>
49+
<version>${jsonb-api.version}</version>
50+
</dependency>
51+
<!-- Dependencies for Yasson -->
52+
<!-- <dependency> -->
53+
<!-- <groupId>org.eclipse</groupId> -->
54+
<!-- <artifactId>yasson</artifactId> -->
55+
<!-- <version>1.0</version> -->
56+
<!-- </dependency> -->
57+
<!-- <dependency> -->
58+
<!-- <groupId>org.glassfish</groupId> -->
59+
<!-- <artifactId>javax.json</artifactId> -->
60+
<!-- <version>1.1.2</version> -->
61+
<!-- </dependency> -->
62+
<!-- Dependencies for Johnzon -->
63+
<dependency>
64+
<groupId>org.apache.geronimo.specs</groupId>
65+
<artifactId>geronimo-json_1.1_spec</artifactId>
66+
<version>${geronimo-json_1.1_spec.version}</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.johnzon</groupId>
70+
<artifactId>johnzon-jsonb</artifactId>
71+
<version>${johnzon.version}</version>
72+
</dependency>
73+
<!-- utils -->
74+
<dependency>
75+
<groupId>org.apache.commons</groupId>
76+
<artifactId>commons-lang3</artifactId>
77+
</dependency>
78+
79+
<!-- runtime and test scoped -->
80+
81+
<dependency>
82+
<groupId>org.springframework.boot</groupId>
83+
<artifactId>spring-boot-devtools</artifactId>
84+
<scope>runtime</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>com.h2database</groupId>
88+
<artifactId>h2</artifactId>
89+
<scope>runtime</scope>
90+
</dependency>
91+
92+
<dependency>
93+
<groupId>org.springframework</groupId>
94+
<artifactId>spring-test</artifactId>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.springframework.boot</groupId>
98+
<artifactId>spring-boot-starter-test</artifactId>
99+
<scope>test</scope>
100+
</dependency>
101+
<dependency>
102+
<groupId>org.springframework.security</groupId>
103+
<artifactId>spring-security-test</artifactId>
104+
<scope>test</scope>
105+
</dependency>
106+
107+
<dependency>
108+
<groupId>org.apache.commons</groupId>
109+
<artifactId>commons-collections4</artifactId>
110+
<version>4.1</version>
111+
<scope>test</scope>
112+
</dependency>
113+
114+
<dependency>
115+
<groupId>org.junit.jupiter</groupId>
116+
<artifactId>junit-jupiter-api</artifactId>
117+
<version>${junit.jupiter.version}</version>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.junit.jupiter</groupId>
121+
<artifactId>junit-jupiter-engine</artifactId>
122+
<version>${junit.jupiter.version}</version>
123+
<scope>test</scope>
124+
</dependency>
125+
<dependency>
126+
<groupId>org.junit.platform</groupId>
127+
<artifactId>junit-platform-surefire-provider</artifactId>
128+
<version>${junit.platform.version}</version>
129+
<scope>test</scope>
130+
</dependency>
131+
<dependency>
132+
<groupId>org.junit.platform</groupId>
133+
<artifactId>junit-platform-runner</artifactId>
134+
<version>${junit.platform.version}</version>
135+
<scope>test</scope>
136+
</dependency>
137+
138+
</dependencies>
139+
140+
<build>
141+
<plugins>
142+
<plugin>
143+
<groupId>org.springframework.boot</groupId>
144+
<artifactId>spring-boot-maven-plugin</artifactId>
145+
<configuration>
146+
<mainClass>com.baeldung.Spring5Application</mainClass>
147+
<layout>JAR</layout>
148+
</configuration>
149+
</plugin>
150+
151+
<plugin>
152+
<groupId>org.apache.maven.plugins</groupId>
153+
<artifactId>maven-surefire-plugin</artifactId>
154+
<configuration>
155+
<forkCount>3</forkCount>
156+
<reuseForks>true</reuseForks>
157+
<parallel>methods</parallel>
158+
<useUnlimitedThreads>true</useUnlimitedThreads>
159+
<excludes>
160+
<exclude>**/*IntegrationTest.java</exclude>
161+
<exclude>**/*LiveTest.java</exclude>
162+
</excludes>
163+
</configuration>
164+
</plugin>
165+
</plugins>
166+
</build>
167+
168+
<repositories>
169+
<repository>
170+
<id>spring-milestones</id>
171+
<name>Spring Milestones</name>
172+
<url>https://repo.spring.io/milestone</url>
173+
<snapshots>
174+
<enabled>false</enabled>
175+
</snapshots>
176+
</repository>
177+
</repositories>
178+
<pluginRepositories>
179+
<pluginRepository>
180+
<id>spring-milestones</id>
181+
<name>Spring Milestones</name>
182+
<url>https://repo.spring.io/milestone</url>
183+
<snapshots>
184+
<enabled>false</enabled>
185+
</snapshots>
186+
</pluginRepository>
187+
</pluginRepositories>
188+
189+
<properties>
190+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
191+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
192+
<java.version>1.8</java.version>
193+
<junit.platform.version>1.0.0</junit.platform.version>
194+
<junit.jupiter.version>5.0.0</junit.jupiter.version>
195+
<maven-surefire-plugin.version>2.20</maven-surefire-plugin.version>
196+
<spring.version>5.0.1.RELEASE</spring.version>
197+
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
198+
<johnzon.version>1.1.3</johnzon.version>
199+
<jsonb-api.version>1.0</jsonb-api.version>
200+
<geronimo-json_1.1_spec.version>1.0</geronimo-json_1.1_spec.version>
201+
</properties>
202+
203+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ComponentScan;
6+
7+
@SpringBootApplication
8+
@ComponentScan(basePackages = { "com.baeldung.web" })
9+
public class Spring5Application {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(Spring5Application.class, args);
13+
}
14+
15+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.ComponentScan;
7+
import org.springframework.http.server.reactive.HttpHandler;
8+
import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
9+
import org.springframework.web.reactive.config.EnableWebFlux;
10+
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
11+
import reactor.ipc.netty.NettyContext;
12+
import reactor.ipc.netty.http.server.HttpServer;
13+
14+
@ComponentScan(basePackages = {"com.baeldung.security"})
15+
@EnableWebFlux
16+
public class SpringSecurity5Application {
17+
18+
public static void main(String[] args) {
19+
try (AnnotationConfigApplicationContext context =
20+
new AnnotationConfigApplicationContext(SpringSecurity5Application.class)) {
21+
context.getBean(NettyContext.class).onClose().block();
22+
}
23+
}
24+
25+
@Bean
26+
public NettyContext nettyContext(ApplicationContext context) {
27+
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context)
28+
.build();
29+
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
30+
HttpServer httpServer = HttpServer.create("localhost", 8080);
31+
return httpServer.newHandler(adapter).block();
32+
}
33+
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.functional;
2+
3+
class Actor {
4+
private String firstname;
5+
private String lastname;
6+
7+
public Actor() {
8+
}
9+
10+
public Actor(String firstname, String lastname) {
11+
this.firstname = firstname;
12+
this.lastname = lastname;
13+
}
14+
15+
public String getFirstname() {
16+
return firstname;
17+
}
18+
19+
public String getLastname() {
20+
return lastname;
21+
}
22+
23+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.baeldung.functional;
2+
3+
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
4+
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
5+
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
6+
import static org.springframework.web.reactive.function.server.RouterFunctions.toHttpHandler;
7+
import static org.springframework.web.reactive.function.server.ServerResponse.ok;
8+
9+
import org.apache.catalina.Context;
10+
import org.apache.catalina.startup.Tomcat;
11+
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
12+
import org.springframework.boot.web.server.WebServer;
13+
import org.springframework.core.io.ClassPathResource;
14+
import org.springframework.http.server.reactive.HttpHandler;
15+
import org.springframework.http.server.reactive.ServletHttpHandlerAdapter;
16+
import org.springframework.web.reactive.function.server.RouterFunction;
17+
import org.springframework.web.reactive.function.server.RouterFunctions;
18+
import org.springframework.web.reactive.function.server.ServerResponse;
19+
import org.springframework.web.server.WebHandler;
20+
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
21+
22+
public class ExploreSpring5URLPatternUsingRouterFunctions {
23+
24+
private RouterFunction<ServerResponse> routingFunction() {
25+
26+
return route(GET("/p?ths"), serverRequest -> ok().body(fromObject("/p?ths"))).andRoute(GET("/test/{*id}"), serverRequest -> ok().body(fromObject(serverRequest.pathVariable("id"))))
27+
.andRoute(GET("/*card"), serverRequest -> ok().body(fromObject("/*card path was accessed")))
28+
.andRoute(GET("/{var1}_{var2}"), serverRequest -> ok().body(fromObject(serverRequest.pathVariable("var1") + " , " + serverRequest.pathVariable("var2"))))
29+
.andRoute(GET("/{baeldung:[a-z]+}"), serverRequest -> ok().body(fromObject("/{baeldung:[a-z]+} was accessed and baeldung=" + serverRequest.pathVariable("baeldung"))))
30+
.and(RouterFunctions.resources("/files/{*filepaths}", new ClassPathResource("files/")));
31+
}
32+
33+
WebServer start() throws Exception {
34+
WebHandler webHandler = (WebHandler) toHttpHandler(routingFunction());
35+
HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(webHandler)
36+
.filter(new IndexRewriteFilter())
37+
.build();
38+
39+
Tomcat tomcat = new Tomcat();
40+
tomcat.setHostname("localhost");
41+
tomcat.setPort(9090);
42+
Context rootContext = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
43+
ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler);
44+
Tomcat.addServlet(rootContext, "httpHandlerServlet", servlet);
45+
rootContext.addServletMappingDecoded("/", "httpHandlerServlet");
46+
47+
TomcatWebServer server = new TomcatWebServer(tomcat);
48+
server.start();
49+
return server;
50+
51+
}
52+
53+
public static void main(String[] args) {
54+
try {
55+
new FunctionalWebApplication().start();
56+
} catch (Exception e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
61+
}

0 commit comments

Comments
 (0)