Repository: sdeleuze/spring-reactive-playground
Branch: master
Commit: 3c07749fb226
Files: 29
Total size: 54.3 KB
Directory structure:
gitextract_on7m_6bd/
├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── src/
└── main/
├── java/
│ └── playground/
│ ├── Application.java
│ ├── CorsController.java
│ ├── EchoWebSocketHandler.java
│ ├── JacksonController.java
│ ├── Person.java
│ ├── ResourceController.java
│ ├── SseController.java
│ └── mongo/
│ ├── MongoConfiguration.java
│ ├── PersonReactiveController.java
│ ├── PersonReactiveCrudRepository.java
│ ├── PersonRxJava1Controller.java
│ └── PersonRxJava1CrudRepository.java
└── resources/
├── application.properties
└── static/
├── common.js
├── cors.html
├── index.html
├── jackson.html
├── mongo.html
├── sse.html
└── websocket.html
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea/
*.iml
/classes/
/build/
/bin/
.gradle/
.settings
.classpath
.project
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
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
http://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.
================================================
FILE: README.md
================================================
Spring Reactive Playground is a showcase for experimenting on applications based on
[Spring Framework 5.0 Reactive support][], [Spring Data Reactive][] and [Reactive NoSQL drivers][].
## Getting started
Prerequisite:
- [Install Java 8](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
- [Install MongoDB](https://www.mongodb.com/download-center) (optional)
For testing MongoDB support, run `mongod` and enable `mongo` profile in `application.properties`.
Run `Application#main()` in your IDE or `./gradlew bootRun` on command line, then open
`http://localhost:8080/` in your browser and use the various test pages.
## License
Spring Reactive Playground is released under version 2.0 of the [Apache License][].
[Apache License]: http://www.apache.org/licenses/LICENSE-2.0
[Spring Framework 5.0 Reactive support]: https://spring.io/blog/2016/07/28/reactive-programming-with-spring-5-0-m1
[Spring Data Reactive]: https://spring.io/blog/2016/11/28/going-reactive-with-spring-data
[Reactive NoSQL drivers]: https://mongodb.github.io/mongo-java-driver-reactivestreams/
================================================
FILE: build.gradle
================================================
buildscript {
ext {
springBootVersion = '2.0.0.BUILD-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
jar {
baseName = 'spring-reactive-playground'
version = '0.1.0-SNAPSHOT'
}
repositories {
mavenCentral()
maven { url 'https://oss.jfrog.org/libs-snapshot' } // RxNetty 0.5.x snapshots
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencyManagement {
imports {
mavenBom "org.springframework.boot.experimental:spring-boot-dependencies-web-reactive:0.1.0.BUILD-SNAPSHOT"
}
}
dependencies {
compile "io.reactivex:rxjava:1.2.1"
compile "io.reactivex:rxjava-reactive-streams:1.2.1"
compile "org.springframework.data:spring-data-commons:2.0.0.BUILD-SNAPSHOT"
compile "org.springframework.data:spring-data-mongodb:2.0.0.BUILD-SNAPSHOT"
compile "org.mongodb:mongodb-driver-reactivestreams:1.2.0"
// With Tomcat
//compile "org.springframework.boot.experimental:spring-boot-starter-web-reactive"
// With Reactor Netty
compile('org.springframework.boot.experimental:spring-boot-starter-web-reactive') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile "io.projectreactor.ipc:reactor-netty"
// With RxNetty
/*
compile('org.springframework.boot.experimental:spring-boot-starter-web-reactive') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile "io.reactivex:rxnetty-common"
compile "io.reactivex:rxnetty-http"
*/
// With Undertow
/*
compile('org.springframework.boot.experimental:spring-boot-starter-web-reactive') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile "io.undertow:undertow-core"
*/
// With Jetty
/*
compile('org.springframework.boot.experimental:spring-boot-starter-web-reactive') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile("org.eclipse.jetty:jetty-server")
compile("org.eclipse.jetty:jetty-servlet")
compile("org.eclipse.jetty:jetty-util")
compile("org.eclipse.jetty:jetty-security")
compile("org.eclipse.jetty:jetty-io")
compile("org.eclipse.jetty:jetty-http")
*/
testCompile('org.springframework.boot:spring-boot-starter-test')
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Wed Jul 20 17:57:05 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
================================================
FILE: gradle.properties
================================================
version=1.0.0.BUILD-SNAPSHOT
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: src/main/java/playground/Application.java
================================================
/*
* Copyright 2002-2015 the original author or authors.
*
* 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
*
* http://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 playground;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.reactive.config.EnableWebReactive;
import org.springframework.web.reactive.config.WebReactiveConfigurer;
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.server.WebSocketService;
import org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService;
import org.springframework.web.reactive.socket.server.support.WebSocketHandlerAdapter;
import org.springframework.web.reactive.socket.server.upgrade.ReactorNettyRequestUpgradeStrategy;
/**
* @author Sebastien Deleuze
*/
@SpringBootApplication
@EnableWebReactive
@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
public class Application implements WebReactiveConfigurer {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/cors/config");
}
@Bean
public HandlerMapping handlerMapping() {
Map<String, WebSocketHandler> map = new HashMap<>();
map.put("/websocket/echo", new EchoWebSocketHandler());
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
mapping.setUrlMap(map);
return mapping;
}
@Bean
public WebSocketHandlerAdapter handlerAdapter() {
return new WebSocketHandlerAdapter(webSocketService());
}
@Bean
public WebSocketService webSocketService() {
return new HandshakeWebSocketService(new ReactorNettyRequestUpgradeStrategy());
}
}
================================================
FILE: src/main/java/playground/CorsController.java
================================================
/*
* Copyright 2002-2016 the original author or authors.
*
* 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
*
* http://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 playground;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Sebastien Deleuze
*/
@RestController
public class CorsController {
@GetMapping("/cors/no")
public Person noCors() {
return new Person("foo", "Bar", "Baz");
}
@GetMapping("/cors/config")
public Person corsConfig() {
return new Person("foo", "Bar", "Baz");
}
@CrossOrigin
@GetMapping("/cors/annotation")
public Person corsaAnotation() {
return new Person("foo", "Bar", "Baz");
}
}
================================================
FILE: src/main/java/playground/EchoWebSocketHandler.java
================================================
/*
* Copyright 2002-2016 the original author or authors.
*
* 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
*
* http://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 playground;
import java.time.Duration;
import reactor.core.publisher.Mono;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.WebSocketMessage;
import org.springframework.web.reactive.socket.WebSocketSession;
/**
* WebSocketHandler that echoes the input with a delay of 2 seconds.
*/
public class EchoWebSocketHandler implements WebSocketHandler {
@Override
public Mono<Void> handle(WebSocketSession session) {
// Use retain() for Reactor Netty
return session.send(session.receive().doOnNext(WebSocketMessage::retain).delay(Duration.ofSeconds(2)));
}
}
================================================
FILE: src/main/java/playground/JacksonController.java
================================================
/*
* Copyright 2002-2016 the original author or authors.
*
* 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
*
* http://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 playground;
import com.fasterxml.jackson.annotation.JsonView;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import rx.Observable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Sebastien Deleuze
*/
@RestController
public class JacksonController {
private final JacksonViewBean jacksonViewBean =
new JacksonViewBean("with", "with", "without");
@GetMapping(path = "/jackson/view")
@JsonView(MyJacksonView1.class)
JacksonViewBean view() {
return jacksonViewBean;
}
@GetMapping(path = "/jackson/view-with-mono")
@JsonView(MyJacksonView1.class)
Mono<JacksonViewBean> viewWithMono() {
return Mono.just(jacksonViewBean);
}
@GetMapping(path = "/jackson/view-with-flux")
@JsonView(MyJacksonView1.class)
Flux<JacksonViewBean> viewWithFlux() {
return Flux.just(jacksonViewBean, jacksonViewBean);
}
@GetMapping(path = "/jackson/view-with-observable")
@JsonView(MyJacksonView1.class)
Observable<JacksonViewBean> viewWithObservable() {
return Observable.just(jacksonViewBean, jacksonViewBean);
}
@GetMapping(path = "/jackson/full")
JacksonViewBean full() {
return jacksonViewBean;
}
private interface MyJacksonView1 {}
private interface MyJacksonView2 {}
private static class JacksonViewBean {
public JacksonViewBean(String withView1, String withView2, String withoutView) {
this.withView1 = withView1;
this.withView2 = withView2;
this.withoutView = withoutView;
}
@JsonView(MyJacksonView1.class)
private String withView1;
@JsonView(MyJacksonView2.class)
private String withView2;
private String withoutView;
public String getWithView1() {
return withView1;
}
public void setWithView1(String withView1) {
this.withView1 = withView1;
}
public String getWithView2() {
return withView2;
}
public void setWithView2(String withView2) {
this.withView2 = withView2;
}
public String getWithoutView() {
return withoutView;
}
public void setWithoutView(String withoutView) {
this.withoutView = withoutView;
}
}
}
================================================
FILE: src/main/java/playground/Person.java
================================================
/*
* Copyright 2002-2015 the original author or authors.
*
* 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
*
* http://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 playground;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Sebastien Deleuze
*/
@Document
public class Person {
private String id;
private String firstname;
private String lastname;
public Person() {
}
public Person(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
public Person(String id, String firstname, String lastname) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
}
@Id
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Person person = (Person) o;
if (id != null ? !id.equals(person.id) : person.id != null) {
return false;
}
if (firstname != null ? !firstname.equals(person.firstname) :
person.firstname != null) {
return false;
}
return lastname != null ? lastname.equals(person.lastname) :
person.lastname == null;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (firstname != null ? firstname.hashCode() : 0);
result = 31 * result + (lastname != null ? lastname.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Person{" +
"id='" + id + '\'' +
", firstname='" + firstname + '\'' +
", lastname='" + lastname + '\'' +
'}';
}
}
================================================
FILE: src/main/java/playground/ResourceController.java
================================================
/*
* Copyright 2002-2016 the original author or authors.
*
* 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
*
* http://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 playground;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ResourceController {
@GetMapping(path = "/", produces = MediaType.TEXT_HTML_VALUE)
Resource index() {
return new ClassPathResource("static/index.html");
}
@GetMapping(path = "/file")
Resource resource(@RequestParam(value = "name", required = false) String name) {
return new ClassPathResource("static/" + name);
}
}
================================================
FILE: src/main/java/playground/SseController.java
================================================
/*
* Copyright 2002-2016 the original author or authors.
*
* 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
*
* http://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 playground;
import java.time.Duration;
import reactor.core.publisher.Flux;
import reactor.core.publisher.ReplayProcessor;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SseController {
private ReplayProcessor<ServerSentEvent<String>> replayProcessor = ReplayProcessor.<ServerSentEvent<String>>create();
@GetMapping("/sse/string")
Flux<String> string() {
return Flux
.interval(Duration.ofSeconds(1))
.map(l -> "foo " + l);
}
@GetMapping("/sse/person")
Flux<Person> person() {
return Flux
.interval(Duration.ofSeconds(1))
.map(l -> new Person(Long.toString(l), "foo", "bar"));
}
@GetMapping("/sse/event")
Flux<ServerSentEvent<String>> event() {
return Flux
.interval(Duration.ofSeconds(1))
.map(l -> ServerSentEvent
.builder("foo\nbar")
.comment("bar\nbaz")
.id(Long.toString(l))
.build());
}
@PostMapping("/sse/receive/{val}")
public void receive(@PathVariable("val") String s) {
replayProcessor.onNext(ServerSentEvent.builder(s).build());
}
@GetMapping("/sse/send")
public Flux<ServerSentEvent<String>> send() {
return replayProcessor.log("playground");
}
}
================================================
FILE: src/main/java/playground/mongo/MongoConfiguration.java
================================================
/*
* Copyright 2002-2015 the original author or authors.
*
* 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
*
* http://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 playground.mongo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration;
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;
import playground.Person;
/**
* @author Sebastien Deleuze
* @author Mark Paluch
*/
@Profile("mongo")
@Configuration
@EnableReactiveMongoRepositories
public class MongoConfiguration extends AbstractReactiveMongoConfiguration {
@Value("${mongo.database}")
private String database;
@Bean
ObjectMapper objectMapper() {
return Jackson2ObjectMapperBuilder.json().build();
}
@Override
public MongoClient mongoClient() {
return MongoClients.create();
}
@Override
protected String getDatabaseName() {
return database;
}
@Bean
CommandLineRunner initData(PersonReactiveCrudRepository personRepository) {
return (p) -> {
personRepository.deleteAll().block();
personRepository.save(new Person("1", "Eric", "Foo")).block();
personRepository.save(new Person("2", "Raymond", "Bar")).block();
personRepository.save(new Person("3", "Paul", "Baz")).block();
};
}
}
================================================
FILE: src/main/java/playground/mongo/PersonReactiveController.java
================================================
/*
* Copyright 2002-2015 the original author or authors.
*
* 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
*
* http://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 playground.mongo;
import org.reactivestreams.Publisher;
import playground.Person;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Sebastien Deleuze
* @author Mark Paluch
*/
@Profile("mongo")
@RestController
public class PersonReactiveController {
private final PersonReactiveCrudRepository repository;
public PersonReactiveController(PersonReactiveCrudRepository repository) {
this.repository = repository;
}
@PostMapping("/mongo")
Mono<Void> create(@RequestBody Publisher<Person> personStream) {
return this.repository.save(personStream).then();
}
@GetMapping("/mongo")
Flux<Person> list() {
return this.repository.findAll();
}
@GetMapping("/mongo/{id}")
Mono<Person> findById(@PathVariable String id) {
return this.repository.findOne(id);
}
}
================================================
FILE: src/main/java/playground/mongo/PersonReactiveCrudRepository.java
================================================
/*
* Copyright 2016 the original author or authors.
*
* 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
*
* http://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 playground.mongo;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import playground.Person;
/**
* @author Mark Paluch
*/
public interface PersonReactiveCrudRepository extends ReactiveCrudRepository<Person, String> {
}
================================================
FILE: src/main/java/playground/mongo/PersonRxJava1Controller.java
================================================
/*
* Copyright 2002-2015 the original author or authors.
*
* 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
*
* http://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 playground.mongo;
import playground.Person;
import rx.Observable;
import rx.Single;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Sebastien Deleuze
* @author Mark Paluch
*/
@Profile("mongo")
@RestController
public class PersonRxJava1Controller {
private final PersonRxJava1CrudRepository repository;
public PersonRxJava1Controller(PersonRxJava1CrudRepository repository) {
this.repository = repository;
}
@PostMapping("/rxjava/mongo")
Observable<Person> create(@RequestBody Observable<Person> personStream) {
return this.repository.save(personStream);
}
@GetMapping("/rxjava/mongo")
Observable<Person> list() {
return this.repository.findAll();
}
@GetMapping("/rxjava/mongo/{id}")
Single<Person> findById(@PathVariable String id) {
return this.repository.findOne(id).toSingle();
}
}
================================================
FILE: src/main/java/playground/mongo/PersonRxJava1CrudRepository.java
================================================
/*
* Copyright 2016 the original author or authors.
*
* 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
*
* http://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 playground.mongo;
import org.springframework.data.repository.reactive.RxJava1CrudRepository;
import playground.Person;
/**
* @author Mark Paluch
*/
public interface PersonRxJava1CrudRepository extends RxJava1CrudRepository<Person, String> {
}
================================================
FILE: src/main/resources/application.properties
================================================
# spring.profiles.active=mongo
mongo.database=test
================================================
FILE: src/main/resources/static/common.js
================================================
function addEvent(evnt, elem, func) {
if (elem.addEventListener) // W3C DOM
elem.addEventListener(evnt,func,false);
else if (elem.attachEvent) { // IE DOM
elem.attachEvent("on"+evnt, func);
}
else { // No much to do
elem[evnt] = func;
}
}
function print(message) {
var elem = document.createElement('span');
elem.innerHTML = message + '<br />';
document.getElementById('output').appendChild(elem);
}
================================================
FILE: src/main/resources/static/cors.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Cross Origin</title>
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0">
<script type="text/javascript" src="/file?name=common.js"></script>
</head>
<body>
<p>
This page must be run from other domain than http://localhost:8080 to be effective.<br />
You can run 2 instances of this app, one on http://localhost:8080 for REST webservices<br />
and one on http://localhost:8181 for this page.
</p>
<p>
<button id="no-cors">No CORS</button>
<button id="cors-config">CORS Config</button>
<button id="cors-annotation">@CrossOrigin annotation</button>
</p>
<p id="output"></p>
<p>
Return <a href="/">to the index</a>
</p>
<script type="text/javascript">
addEvent("click", document.getElementById('no-cors'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/cors/no', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
addEvent("click", document.getElementById('cors-config'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/cors/config', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
addEvent("click", document.getElementById('cors-annotation'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/cors/annotation', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
</script>
</body>
================================================
FILE: src/main/resources/static/index.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Spring Reactive Playground</title>
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0">
</head>
<body>
<p>
Welcome to Spring Reactive Playground!<br />
What do you want to test?
<ul>
<li><a href="/file?name=cors.html">Reactive CORS support</a></li>
<li><a href="/file?name=jackson.html">Reactive JSON REST Webservices with Jackson</a></li>
<li><a href="/file?name=sse.html">Reactive Server Sent Events</a></li>
<li><a href="/file?name=websocket.html">Reactive Websocket</a></li>
<li><a href="/file?name=mongo.html">Reactive Spring Data + Mongo</a></li>
</ul>
</p>
</body>
================================================
FILE: src/main/resources/static/jackson.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Jackson</title>
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0">
<script type="text/javascript" src="/file?name=common.js"></script>
</head>
<body>
<p>
<button id="jsonview">JsonView</button>
<button id="jsonview-with-mono">JsonView with Mono</button>
<button id="jsonview-with-flux">JsonView with Flux</button>
<button id="jsonview-with-observable">JsonView with Observable</button>
<button id="full">No JsonView</button>
</p>
<p id="output"></p>
<p>
Return <a href="/">to the index</a>
</p>
<script type="text/javascript">
addEvent("click", document.getElementById('jsonview'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/jackson/view', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
addEvent("click", document.getElementById('jsonview-with-mono'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/jackson/view-with-mono', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
addEvent("click", document.getElementById('jsonview-with-flux'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/jackson/view-with-flux', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
addEvent("click", document.getElementById('jsonview-with-observable'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/jackson/view-with-observable', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
addEvent("click", document.getElementById('full'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/jackson/full', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
</script>
</body>
================================================
FILE: src/main/resources/static/mongo.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mongo</title>
<meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0">
<script type="text/javascript" src="/file?name=common.js"></script>
</head>
<body>
<p>
<button id="list-all">List all the persons</button>
<button id="get-one">Get one person</button>
</p>
<p id="output"></p>
<p>
Return <a href="/">to the index</a>
</p>
<script type="text/javascript">
addEvent("click", document.getElementById('list-all'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/mongo/', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
addEvent("click", document.getElementById('get-one'), function() {
var req = new XMLHttpRequest();
req.open('GET', 'http://' + document.domain + ':8080/mongo/1', false);
req.send(null);
if(req.status == 200)
print('Response received: ' + req.responseText);
});
</script>
</body>
================================================
FILE: src/main/resources/static/sse.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SSE example</title>
<script type="text/javascript" src="/file?name=common.js"></script>
</head>
<p>
<p>
<button id="send-data">Send data</button><br />
SSE with processor: <ul id="processor-events"></ul>
</p>
<p>
<button id="subscribe-string-events">Subscribe</button><br />
SSE with String: <ul id="string-events"></ul>
</p>
<p>
<button id="subscribe-person-events">Subscribe</button><br />
SSE with Person: <ul id="person-events"></ul>
</p>
<p>
<button id="subscribe-raw-events">Subscribe</button><br />
SSE with raw events: <ul id="raw-events"></ul>
</p>
</p>
<p>
Return <a href="/">to the index</a>
</p>
<script type="application/javascript">
addEvent("click", document.getElementById('subscribe-string-events'), function() {
var stringEvents = document.getElementById("string-events");
var stringEventSource = new EventSource("/sse/string");
stringEventSource.onmessage = function(e) {
var newElement = document.createElement("li");
newElement.innerHTML = "Message: " + e.data;
stringEvents.appendChild(newElement);
}
});
addEvent("click", document.getElementById('subscribe-person-events'), function() {
var personEvents = document.getElementById("person-events");
var personEventSource = new EventSource("/sse/person");
personEventSource.onmessage = function(e) {
var newElement = document.createElement("li");
var person = JSON.parse(e.data);
newElement.innerHTML = "Person: id=" + person.id + ", firstname=" + person.firstname + ", lastname=" + person.lastname;
personEvents.appendChild(newElement);
}
});
addEvent("click", document.getElementById('subscribe-raw-events'), function() {
var rawEvents = document.getElementById("raw-events");
var rawEventSource = new EventSource("/sse/event");
rawEventSource.onmessage = function(e) {
var newElement = document.createElement("li");
newElement.innerHTML = "Event: id=" + e.lastEventId + ", data=" + e.data;
rawEvents.appendChild(newElement);
}
});
addEvent("click", document.getElementById('send-data'), function() {
var req = new XMLHttpRequest();
req.open('POST', '/sse/receive/foo', true);
req.send(null);
});
var processorEvents = document.getElementById("processor-events");
var processorEventSource = new EventSource("/sse/send");
processorEventSource.onmessage = function(e) {
var newElement = document.createElement("li");
newElement.innerHTML = "Event: id=" + e.lastEventId + ", data=" + e.data;
processorEvents.appendChild(newElement);
}
</script>
</body>
</html>
================================================
FILE: src/main/resources/static/websocket.html
================================================
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WebSocket example</title>
<script type="text/javascript" src="/file?name=common.js"></script>
</head>
<p>Echo the input with a delay of 2 seconds</p>
<p>
Input<br />
<textarea id="input" name="input" cols="40"></textarea>
</p>
<p>
Output<br />
<div id="output"></div>
</p>
<p>
Return <a href="/">to the index</a>
</p>
<script type="application/javascript">
var socket = new WebSocket("ws://" + location.host + "/websocket/echo");
addEvent("keypress", document.getElementById('input'), function(event) {
socket.send(event.key);
});
var output = document.getElementById("output");
socket.onmessage = function(e) {
output.innerHTML = output.innerHTML + e.data;
}
</script>
</body>
</html>
gitextract_on7m_6bd/
├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── src/
└── main/
├── java/
│ └── playground/
│ ├── Application.java
│ ├── CorsController.java
│ ├── EchoWebSocketHandler.java
│ ├── JacksonController.java
│ ├── Person.java
│ ├── ResourceController.java
│ ├── SseController.java
│ └── mongo/
│ ├── MongoConfiguration.java
│ ├── PersonReactiveController.java
│ ├── PersonReactiveCrudRepository.java
│ ├── PersonRxJava1Controller.java
│ └── PersonRxJava1CrudRepository.java
└── resources/
├── application.properties
└── static/
├── common.js
├── cors.html
├── index.html
├── jackson.html
├── mongo.html
├── sse.html
└── websocket.html
SYMBOL INDEX (69 symbols across 13 files)
FILE: src/main/java/playground/Application.java
class Application (line 42) | @SpringBootApplication
method main (line 47) | public static void main(String[] args) throws Exception {
method addCorsMappings (line 51) | @Override
method handlerMapping (line 56) | @Bean
method handlerAdapter (line 67) | @Bean
method webSocketService (line 72) | @Bean
FILE: src/main/java/playground/CorsController.java
class CorsController (line 26) | @RestController
method noCors (line 29) | @GetMapping("/cors/no")
method corsConfig (line 34) | @GetMapping("/cors/config")
method corsaAnotation (line 39) | @CrossOrigin
FILE: src/main/java/playground/EchoWebSocketHandler.java
class EchoWebSocketHandler (line 30) | public class EchoWebSocketHandler implements WebSocketHandler {
method handle (line 32) | @Override
FILE: src/main/java/playground/JacksonController.java
class JacksonController (line 30) | @RestController
method view (line 36) | @GetMapping(path = "/jackson/view")
method viewWithMono (line 42) | @GetMapping(path = "/jackson/view-with-mono")
method viewWithFlux (line 48) | @GetMapping(path = "/jackson/view-with-flux")
method viewWithObservable (line 54) | @GetMapping(path = "/jackson/view-with-observable")
method full (line 60) | @GetMapping(path = "/jackson/full")
type MyJacksonView1 (line 66) | private interface MyJacksonView1 {}
type MyJacksonView2 (line 68) | private interface MyJacksonView2 {}
class JacksonViewBean (line 70) | private static class JacksonViewBean {
method JacksonViewBean (line 72) | public JacksonViewBean(String withView1, String withView2, String wi...
method getWithView1 (line 86) | public String getWithView1() {
method setWithView1 (line 90) | public void setWithView1(String withView1) {
method getWithView2 (line 94) | public String getWithView2() {
method setWithView2 (line 98) | public void setWithView2(String withView2) {
method getWithoutView (line 102) | public String getWithoutView() {
method setWithoutView (line 106) | public void setWithoutView(String withoutView) {
FILE: src/main/java/playground/Person.java
class Person (line 25) | @Document
method Person (line 35) | public Person() {
method Person (line 38) | public Person(String firstname, String lastname) {
method Person (line 43) | public Person(String id, String firstname, String lastname) {
method getId (line 50) | @Id
method setId (line 55) | public void setId(String id) {
method getFirstname (line 59) | public String getFirstname() {
method setFirstname (line 63) | public void setFirstname(String firstname) {
method getLastname (line 67) | public String getLastname() {
method setLastname (line 71) | public void setLastname(String lastname) {
method equals (line 75) | @Override
method hashCode (line 98) | @Override
method toString (line 106) | @Override
FILE: src/main/java/playground/ResourceController.java
class ResourceController (line 26) | @RestController
method index (line 29) | @GetMapping(path = "/", produces = MediaType.TEXT_HTML_VALUE)
method resource (line 34) | @GetMapping(path = "/file")
FILE: src/main/java/playground/SseController.java
class SseController (line 30) | @RestController
method string (line 35) | @GetMapping("/sse/string")
method person (line 42) | @GetMapping("/sse/person")
method event (line 49) | @GetMapping("/sse/event")
method receive (line 60) | @PostMapping("/sse/receive/{val}")
method send (line 65) | @GetMapping("/sse/send")
FILE: src/main/java/playground/mongo/MongoConfiguration.java
class MongoConfiguration (line 37) | @Profile("mongo")
method objectMapper (line 45) | @Bean
method mongoClient (line 50) | @Override
method getDatabaseName (line 55) | @Override
method initData (line 60) | @Bean
FILE: src/main/java/playground/mongo/PersonReactiveController.java
class PersonReactiveController (line 35) | @Profile("mongo")
method PersonReactiveController (line 41) | public PersonReactiveController(PersonReactiveCrudRepository repositor...
method create (line 45) | @PostMapping("/mongo")
method list (line 50) | @GetMapping("/mongo")
method findById (line 55) | @GetMapping("/mongo/{id}")
FILE: src/main/java/playground/mongo/PersonReactiveCrudRepository.java
type PersonReactiveCrudRepository (line 24) | public interface PersonReactiveCrudRepository extends ReactiveCrudReposi...
FILE: src/main/java/playground/mongo/PersonRxJava1Controller.java
class PersonRxJava1Controller (line 34) | @Profile("mongo")
method PersonRxJava1Controller (line 40) | public PersonRxJava1Controller(PersonRxJava1CrudRepository repository) {
method create (line 44) | @PostMapping("/rxjava/mongo")
method list (line 49) | @GetMapping("/rxjava/mongo")
method findById (line 54) | @GetMapping("/rxjava/mongo/{id}")
FILE: src/main/java/playground/mongo/PersonRxJava1CrudRepository.java
type PersonRxJava1CrudRepository (line 25) | public interface PersonRxJava1CrudRepository extends RxJava1CrudReposito...
FILE: src/main/resources/static/common.js
function addEvent (line 1) | function addEvent(evnt, elem, func) {
function print (line 12) | function print(message) {
Condensed preview — 29 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (60K chars).
[
{
"path": ".gitignore",
"chars": 263,
"preview": "*.class\n\n# Mobile Tools for Java (J2ME)\n.mtj.tmp/\n\n# Package Files #\n*.war\n*.ear\n\n# virtual machine crash logs, see http"
},
{
"path": "LICENSE",
"chars": 11358,
"preview": " Apache License\n Version 2.0, January 2004\n "
},
{
"path": "README.md",
"chars": 1107,
"preview": "Spring Reactive Playground is a showcase for experimenting on applications based on\n[Spring Framework 5.0 Reactive suppo"
},
{
"path": "build.gradle",
"chars": 2494,
"preview": "buildscript {\n\text {\n\t\tspringBootVersion = '2.0.0.BUILD-SNAPSHOT'\n\t}\n\trepositories {\n\t\tmavenCentral()\n\t\tmaven { url \"htt"
},
{
"path": "gradle/wrapper/gradle-wrapper.properties",
"chars": 234,
"preview": "#Wed Jul 20 17:57:05 CEST 2016\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER"
},
{
"path": "gradle.properties",
"chars": 30,
"preview": "version=1.0.0.BUILD-SNAPSHOT\n\n"
},
{
"path": "gradlew",
"chars": 5046,
"preview": "#!/usr/bin/env bash\n\n##############################################################################\n##\n## Gradle start "
},
{
"path": "gradlew.bat",
"chars": 2314,
"preview": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem "
},
{
"path": "src/main/java/playground/Application.java",
"chars": 2833,
"preview": "/*\n * Copyright 2002-2015 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/CorsController.java",
"chars": 1241,
"preview": "/*\n * Copyright 2002-2016 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/EchoWebSocketHandler.java",
"chars": 1258,
"preview": "/*\n * Copyright 2002-2016 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/JacksonController.java",
"chars": 2762,
"preview": "/*\n * Copyright 2002-2016 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/Person.java",
"chars": 2458,
"preview": "/*\n * Copyright 2002-2015 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/ResourceController.java",
"chars": 1327,
"preview": "/*\n * Copyright 2002-2016 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/SseController.java",
"chars": 2055,
"preview": "/*\n * Copyright 2002-2016 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/mongo/MongoConfiguration.java",
"chars": 2340,
"preview": "/*\n * Copyright 2002-2015 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/mongo/PersonReactiveController.java",
"chars": 1803,
"preview": "/*\n * Copyright 2002-2015 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/mongo/PersonReactiveCrudRepository.java",
"chars": 875,
"preview": "/*\n * Copyright 2016 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\""
},
{
"path": "src/main/java/playground/mongo/PersonRxJava1Controller.java",
"chars": 1771,
"preview": "/*\n * Copyright 2002-2015 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"Lic"
},
{
"path": "src/main/java/playground/mongo/PersonRxJava1CrudRepository.java",
"chars": 873,
"preview": "/*\n * Copyright 2016 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\""
},
{
"path": "src/main/resources/application.properties",
"chars": 52,
"preview": "# spring.profiles.active=mongo\n\nmongo.database=test\n"
},
{
"path": "src/main/resources/static/common.js",
"chars": 457,
"preview": "function addEvent(evnt, elem, func) {\n if (elem.addEventListener) // W3C DOM\n elem.addEventListener(evnt,func"
},
{
"path": "src/main/resources/static/cors.html",
"chars": 1941,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <title>Cross Origin</title>\n <meta http-equiv="
},
{
"path": "src/main/resources/static/index.html",
"chars": 795,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <title>Spring Reactive Playground</title>\n <me"
},
{
"path": "src/main/resources/static/jackson.html",
"chars": 2562,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <title>Jackson</title>\n <meta http-equiv=\"Cach"
},
{
"path": "src/main/resources/static/mongo.html",
"chars": 1239,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <title>Mongo</title>\n <meta http-equiv=\"Cache-"
},
{
"path": "src/main/resources/static/sse.html",
"chars": 3159,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <title>SSE example</title>\n <script type=\"text"
},
{
"path": "src/main/resources/static/websocket.html",
"chars": 918,
"preview": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <title>WebSocket example</title>\n <script type"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the sdeleuze/spring-reactive-playground GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 29 files (54.3 KB), approximately 13.7k tokens, and a symbol index with 69 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.