├── README.md ├── https-integration ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── tuturself │ │ │ └── httpsintegration │ │ │ ├── Employee.java │ │ │ ├── EmployeeRepository.java │ │ │ ├── HttpsIntegrationApplication.java │ │ │ ├── TomcatEmbed.java │ │ │ └── WebService.java │ └── resources │ │ ├── application.yml │ │ └── keystore.p12 │ └── test │ └── java │ └── com │ └── tuturself │ └── httpsintegration │ └── HttpsIntegrationApplicationTests.java ├── spring-boot-cassandra-datastax ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── tuturself │ │ └── datastax │ │ ├── StudentManager.java │ │ ├── SwaggerConfig.java │ │ ├── api │ │ └── StudentApi.java │ │ ├── model │ │ └── Student.java │ │ └── repository │ │ ├── CassandraConnector.java │ │ └── StudentService.java │ └── resources │ └── application.yml ├── spring-boot-consul ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── tuturself │ │ ├── SpringBoot2Consul.java │ │ ├── config │ │ └── SwaggerConfig.java │ │ ├── model │ │ └── ConsulConfiguration.java │ │ └── webservice │ │ └── RestApi.java │ └── resources │ └── bootstrap.yml ├── spring-boot-file-upload ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── tuturself │ │ ├── SpringBoot2FileUpload.java │ │ ├── config │ │ └── SwaggerConfig.java │ │ └── webservice │ │ └── FileUploadRestApi.java │ └── resources │ └── bootstrap.yml ├── spring-boot-jdbc ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── tuturself │ │ │ └── demo │ │ │ ├── API.java │ │ │ ├── DemoApplication.java │ │ │ ├── mapper │ │ │ ├── CityMapper.java │ │ │ └── CountryMapper.java │ │ │ ├── model │ │ │ ├── City.java │ │ │ └── Country.java │ │ │ └── service │ │ │ ├── QueryProvider.java │ │ │ └── Repository.java │ └── resources │ │ ├── Queries.properties │ │ ├── application.properties │ │ └── db.sql │ └── test │ └── java │ └── com │ └── tuturself │ └── demo │ └── DemoApplicationTests.java ├── spring-boot-jersey ├── pom.xml └── src │ └── main │ ├── java │ └── spring │ │ └── boot │ │ └── jersey │ │ └── sample │ │ ├── JerseyConfig.java │ │ ├── SpringBootJerseyApplication.java │ │ ├── data │ │ ├── Person.java │ │ └── PersonService.java │ │ └── rest │ │ └── PersonSearchEndPoint.java │ └── resources │ └── banner.txt ├── spring-boot-logback ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── tuturself │ │ └── spring │ │ └── boot │ │ ├── StudentSearchApplication.java │ │ ├── api │ │ └── StudentAPI.java │ │ └── model │ │ └── Student.java │ └── resources │ └── application.yml ├── spring-boot-route ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── tuturself │ │ │ └── example │ │ │ └── springbootroute │ │ │ ├── Employee.java │ │ │ ├── EmployeeRepository.java │ │ │ └── SpringBootRouteApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── tuturself │ └── example │ └── springbootroute │ └── SpringBootRouteApplicationTests.java ├── spring-boot-swagger ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── tuturself │ │ └── spring │ │ └── boot │ │ ├── StudentSearchApplication.java │ │ ├── SwaggerConfig.java │ │ ├── api │ │ └── StudentAPI.java │ │ ├── model │ │ └── Student.java │ │ └── service │ │ └── StudentService.java │ └── resources │ └── application.yml ├── spring-boot-web ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── tuturself │ │ └── springboot │ │ └── web │ │ ├── SpringBootWebApplication.java │ │ ├── configuration │ │ └── AppConfig.java │ │ ├── controller │ │ └── PersonAPI.java │ │ ├── interceptor │ │ └── RequestInterceptor.java │ │ ├── model │ │ └── Person.java │ │ └── service │ │ └── PersonService.java │ └── test │ └── java │ └── com │ └── tuturself │ └── springboot │ └── web │ └── AppTest.java ├── spring-boot-websocket ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── tuturself │ │ │ └── springbootwebsocket │ │ │ ├── SpringBootWebsocketApplication.java │ │ │ ├── TomcatEmbeded.java │ │ │ ├── WebSocketConfig.java │ │ │ └── WebSocketEndpoint.java │ └── resources │ │ ├── application.yml │ │ └── keystore.p12 │ └── test │ └── java │ └── com │ └── tuturself │ └── springbootwebsocket │ ├── SpringBootWebsocketApplicationTests.java │ └── Test1.java ├── spring.boot.filter ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── tuturself │ │ └── spring │ │ └── boot │ │ └── filter │ │ ├── HeaderMapRequestWrapper.java │ │ ├── SpringFilterApplication.java │ │ ├── WebApi.java │ │ └── WebFilter.java │ └── resources │ └── application.yml ├── spring.boot.integration.db ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── tuturself │ │ │ └── spring │ │ │ └── boot │ │ │ ├── StudentSearchApplication.java │ │ │ ├── api │ │ │ └── StudentAPI.java │ │ │ ├── model │ │ │ └── Student.java │ │ │ └── service │ │ │ └── StudentRepository.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── tuturself │ └── spring │ └── boot │ └── integration │ └── db │ └── AppTest.java ├── spring.boot ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── tuturself │ │ └── spring │ │ └── boot │ │ ├── StudentSearchApplication.java │ │ ├── api │ │ └── StudentAPI.java │ │ ├── model │ │ └── Student.java │ │ └── service │ │ └── StudentService.java │ └── test │ └── java │ └── com │ └── tuturself │ └── spring │ └── boot │ └── AppTest.java ├── springboot.cassandra ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── tuturself │ │ └── spring │ │ └── boot │ │ └── cassandra │ │ ├── StudentSearchApplication.java │ │ ├── api │ │ └── StudentSearchAPI.java │ │ ├── entity │ │ └── Student.java │ │ ├── manager │ │ ├── CassandraConfiguration.java │ │ └── ManagerConfiguration.java │ │ └── repo │ │ └── StudentRepository.java │ └── resources │ └── application.yml └── test /README.md: -------------------------------------------------------------------------------- 1 | # Tutu'rself: 2 | 3 | Please visit our website for to learn about Java/ J2EE Technologies 4 | https://www.tuturself.com 5 | 6 | Learning something new can be a strenuous task. However having the right information readily available would be a great way to start. Keeping it at hands bay for future reference would be even greater. Tutur'self has taken up this mission of bringing this information to you in the easiest and the fastest possible way. 7 | 8 | In this era of internet, availability of information is not a constraint to start learning something like a new technology or a concept. The difficult part though is to navigate through the ocean of information that the internet is and find what actually is that will help you achieve your goal. We at Tutur'self aim to make this task easier by effectively categorizing information in any way that will help users find it easily. This information or content is for the users and by the users. 9 | -------------------------------------------------------------------------------- /https-integration/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninja-panda/spring-boot-example/00b41debaddaa0ece2ae606c7c9d0f39c2a2f40e/https-integration/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /https-integration/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /https-integration/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /https-integration/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /https-integration/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.tuturself 7 | https-integration 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | https-integration 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-webflux 35 | 36 | 37 | 38 | org.projectlombok 39 | lombok 40 | true 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | io.projectreactor 49 | reactor-test 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /https-integration/src/main/java/com/tuturself/httpsintegration/Employee.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.httpsintegration; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.UUID; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | class Employee { 13 | 14 | private UUID employeeId; 15 | private String name; 16 | } 17 | -------------------------------------------------------------------------------- /https-integration/src/main/java/com/tuturself/httpsintegration/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.httpsintegration; 2 | 3 | import org.springframework.stereotype.Repository; 4 | import reactor.core.publisher.Flux; 5 | import reactor.core.publisher.Mono; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.UUID; 10 | 11 | @Repository 12 | class EmployeeRepository { 13 | 14 | List employees = new ArrayList<>(); 15 | 16 | public EmployeeRepository() { 17 | employees.add(new Employee(UUID.randomUUID(), "Robert Barnes")); 18 | employees.add(new Employee(UUID.randomUUID(), "Robin Bennett")); 19 | employees.add(new Employee(UUID.randomUUID(), "Harvey Berg")); 20 | employees.add(new Employee(UUID.randomUUID(), "Joanne Dalton")); 21 | employees.add(new Employee(UUID.randomUUID(), "Keifer Davey")); 22 | employees.add(new Employee(UUID.randomUUID(), "Grace Dobson")); 23 | } 24 | 25 | public Flux findAll() { 26 | return Flux.fromStream(employees.stream()); 27 | } 28 | 29 | public Mono findById(String id) { 30 | UUID empId = UUID.fromString(id); 31 | return Mono.justOrEmpty(employees.stream(). 32 | filter(e -> e.getEmployeeId().equals(empId)).findFirst()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /https-integration/src/main/java/com/tuturself/httpsintegration/HttpsIntegrationApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.httpsintegration; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HttpsIntegrationApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HttpsIntegrationApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /https-integration/src/main/java/com/tuturself/httpsintegration/TomcatEmbed.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.httpsintegration; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.catalina.Context; 5 | import org.apache.catalina.connector.Connector; 6 | import org.apache.tomcat.util.descriptor.web.SecurityCollection; 7 | import org.apache.tomcat.util.descriptor.web.SecurityConstraint; 8 | import org.apache.tomcat.websocket.server.WsSci; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; 11 | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.web.SpringServletContainerInitializer; 15 | 16 | @Slf4j 17 | @Configuration 18 | public class TomcatEmbed extends SpringServletContainerInitializer { 19 | 20 | @Value("${server.port}") 21 | private Integer httpsPort; 22 | 23 | @Value("${server.http-port}") 24 | private Integer httpPort; 25 | 26 | @Bean 27 | public TomcatServletWebServerFactory servletContainer() { 28 | TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() { 29 | protected void postProcessContext(Context context) { 30 | SecurityConstraint securityConstraint = new SecurityConstraint(); 31 | securityConstraint.setUserConstraint("CONFIDENTIAL"); 32 | SecurityCollection collection = new SecurityCollection(); 33 | collection.addPattern("/*"); 34 | securityConstraint.addCollection(collection); 35 | context.addConstraint(securityConstraint); 36 | } 37 | }; 38 | tomcat.addAdditionalTomcatConnectors(initiateHttpConnector()); 39 | return tomcat; 40 | } 41 | 42 | private Connector initiateHttpConnector() { 43 | Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); 44 | connector.setScheme("http"); 45 | connector.setPort(httpPort); 46 | connector.setSecure(false); 47 | connector.setRedirectPort(httpsPort); 48 | return connector; 49 | } 50 | 51 | /** 52 | * The following code is required only if you WebSocket endpoint 53 | * in your application. We added it for some later example. You 54 | * can omit this part if you don't have any WebSocket endpoint. 55 | */ 56 | @Bean 57 | public TomcatContextCustomizer tomcatContextCustomizer() { 58 | log.info("TOMCAT CONTEXT CUSTOMIZER INITIALIZED"); 59 | return new TomcatContextCustomizer() { 60 | @Override 61 | public void customize(Context context) { 62 | context.addServletContainerInitializer(new WsSci(), null); 63 | } 64 | }; 65 | } 66 | } 67 | 68 | -------------------------------------------------------------------------------- /https-integration/src/main/java/com/tuturself/httpsintegration/WebService.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.httpsintegration; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import reactor.core.publisher.Flux; 9 | import reactor.core.publisher.Mono; 10 | 11 | @RestController 12 | public class WebService { 13 | 14 | @Autowired 15 | private EmployeeRepository repository; 16 | 17 | @GetMapping("/employees") 18 | public Flux getAllEmployees() { 19 | return repository.findAll(); 20 | } 21 | 22 | @GetMapping("/employees/{id}") 23 | public Mono> getAllEmployees(@PathVariable("id") String employeeId) { 24 | return repository.findById(employeeId) 25 | .map(employee -> ResponseEntity.ok(employee)) 26 | .defaultIfEmpty(ResponseEntity.notFound().build()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /https-integration/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: spring-test-service 4 | 5 | # SSL Configuration STARTS Here 6 | server: 7 | port: 8443 8 | http-port: 8099 9 | ssl: 10 | key-store: classpath:keystore.p12 11 | key-store-password: test@123 12 | keyStoreType: PKCS12 13 | keyAlias: https-integration 14 | # SSL Configuration ENDS Here 15 | 16 | logging: 17 | level: 18 | org.springframework: INFO 19 | com.qualys: INFO 20 | pattern: 21 | console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" 22 | file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" 23 | file: /tmp/logs/https-integration-application.log -------------------------------------------------------------------------------- /https-integration/src/main/resources/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninja-panda/spring-boot-example/00b41debaddaa0ece2ae606c7c9d0f39c2a2f40e/https-integration/src/main/resources/keystore.p12 -------------------------------------------------------------------------------- /https-integration/src/test/java/com/tuturself/httpsintegration/HttpsIntegrationApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.httpsintegration; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class HttpsIntegrationApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-cassandra-datastax/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.tuturself 5 | spring-boot-cassandra-datastax 6 | 0.0.1-SNAPSHOT 7 | spring-boot-cassandra-datastax 8 | 9 | 10 | org.springframework.boot 11 | spring-boot-starter-parent 12 | 1.5.1.RELEASE 13 | 14 | 15 | 16 | 1.8 17 | UTF-8 18 | 1.5.1.RELEASE 19 | 3.2.0 20 | 4.12 21 | 2.8.1 22 | 2.5.0 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | ${spring-boot.version} 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-actuator 36 | ${spring-boot.version} 37 | 38 | 39 | 40 | 41 | com.datastax.cassandra 42 | cassandra-driver-core 43 | ${cassandra.driver.version} 44 | 45 | 46 | 47 | com.datastax.cassandra 48 | cassandra-driver-extras 49 | ${cassandra.driver.version} 50 | 51 | 52 | 53 | com.datastax.cassandra 54 | cassandra-driver-mapping 55 | ${cassandra.driver.version} 56 | 57 | 58 | 59 | io.netty 60 | netty-all 61 | 4.0.36.Final 62 | 63 | 64 | 65 | com.fasterxml.jackson.core 66 | jackson-databind 67 | ${jackson.version} 68 | 69 | 70 | 71 | com.fasterxml.jackson.core 72 | jackson-annotations 73 | ${jackson.version} 74 | 75 | 76 | 77 | 78 | io.springfox 79 | springfox-swagger2 80 | ${swagger.version} 81 | 82 | 83 | 84 | io.springfox 85 | springfox-swagger-ui 86 | ${swagger.version} 87 | 88 | 89 | 90 | 91 | 92 | 93 | org.springframework.boot 94 | spring-boot-maven-plugin 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /spring-boot-cassandra-datastax/src/main/java/com/tuturself/datastax/StudentManager.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.datastax; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class StudentManager { 10 | 11 | private final static Logger logger = LoggerFactory.getLogger(StudentManager.class); 12 | 13 | public static void main(String[] args) throws Exception { 14 | logger.debug("StudentManager is STARTing..."); 15 | SpringApplication.run(StudentManager.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-cassandra-datastax/src/main/java/com/tuturself/datastax/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.datastax; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.PathSelectors; 6 | import springfox.documentation.builders.RequestHandlerSelectors; 7 | import springfox.documentation.service.ApiInfo; 8 | import springfox.documentation.spi.DocumentationType; 9 | import springfox.documentation.spring.web.plugins.Docket; 10 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 11 | 12 | @Configuration 13 | @EnableSwagger2 14 | public class SwaggerConfig { 15 | 16 | @Bean 17 | public Docket api() { 18 | return new Docket(DocumentationType.SWAGGER_2) 19 | .select() 20 | .apis(RequestHandlerSelectors.basePackage("com.tuturself.datastax.api")) 21 | .paths(PathSelectors.any()) 22 | .build().apiInfo(apiInfo()); 23 | } 24 | 25 | private ApiInfo apiInfo() { 26 | ApiInfo apiInfo = new ApiInfo( 27 | "StudentManager", 28 | "An application to perform CURD operation in Cassandra Student repository", 29 | "StudentManager v1", 30 | "Terms of service", 31 | "tuturself@gmail.com", 32 | "License of API", 33 | "License URL"); 34 | return apiInfo; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-cassandra-datastax/src/main/java/com/tuturself/datastax/api/StudentApi.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.datastax.api; 2 | 3 | import com.datastax.driver.mapping.Result; 4 | import com.tuturself.datastax.model.Student; 5 | import com.tuturself.datastax.repository.StudentService; 6 | import io.swagger.annotations.*; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.HttpStatus; 11 | import org.springframework.http.ResponseEntity; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import java.util.UUID; 15 | 16 | @RestController 17 | @RequestMapping("/students") 18 | @Api(value = "API to perform CRUD operation in a Student database maintained in apache cassandra", 19 | description = "This API provides the capability to perform CRUD operation in a Student " + 20 | "database maintained in apache cassandra", produces = "application/json") 21 | public class StudentApi { 22 | 23 | private static final Logger logger = LoggerFactory.getLogger(StudentApi.class); 24 | 25 | @Autowired 26 | private StudentService studentService; 27 | 28 | private static final String NO_RECORD = "Student not found for Student Id : "; 29 | 30 | @ApiOperation(value = "Search Student by studentId", produces = "application/json") 31 | @RequestMapping(value = "/{studentId}", method = RequestMethod.GET) 32 | public ResponseEntity searchStudentById(@ApiParam(name = "studentId", 33 | value = "The Id of the Student to be viewed", 34 | required = true) @PathVariable UUID studentId) { 35 | logger.debug("Searching for student with studentId :: {}", studentId); 36 | Result studentResult = null; 37 | ResponseEntity response = null; 38 | try { 39 | studentResult = studentService.getStudentById(studentId); 40 | if (studentResult == null) { 41 | response = new ResponseEntity(NO_RECORD + studentId, HttpStatus.OK); 42 | } else { 43 | response = new ResponseEntity(studentResult.one(), HttpStatus.OK); 44 | } 45 | } catch (Exception ex) { 46 | logger.error(ex.getMessage(), ex); 47 | return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 48 | } 49 | return response; 50 | } 51 | 52 | 53 | @ApiOperation(value = "Create a new Student", consumes = "application/json") 54 | @ApiImplicitParams({ 55 | @ApiImplicitParam(name = "departmentId", value = "Department Id", 56 | required = true, dataType = "Integer", paramType = "header"), 57 | @ApiImplicitParam(name = "name", value = "Name of Student", 58 | required = true, dataType = "String", paramType = "query"), 59 | @ApiImplicitParam(name = "address", value = "Address of Student", 60 | required = true, dataType = "String", paramType = "query") }) 61 | @RequestMapping(method = RequestMethod.POST) 62 | public ResponseEntity createStudent( 63 | @RequestHeader(name = "departmentId") Integer departmentId, 64 | @RequestParam String name,@RequestParam String address) { 65 | logger.debug("Creating Student with name :: {}", name); 66 | ResponseEntity response = null; 67 | try { 68 | UUID studentId = studentService.createStudent(departmentId,name,address); 69 | response = new ResponseEntity("Student created successfully with Id :" + 70 | studentId, HttpStatus.OK); 71 | } catch (Exception ex) { 72 | logger.error(ex.getMessage(), ex); 73 | return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 74 | } 75 | return response; 76 | } 77 | 78 | @ApiOperation(value = "Delete a Student Object from Database", consumes = "application/json") 79 | @ApiImplicitParams({ 80 | @ApiImplicitParam(name = "studentId", value = "StudentID to delete", 81 | required = true, dataType = "UUID", paramType = "header")}) 82 | @RequestMapping(method = RequestMethod.DELETE) 83 | public ResponseEntity delete( 84 | @RequestHeader(name = "studentId") UUID studentId) { 85 | logger.debug("Deleting Student with studentId :: {}", studentId); 86 | ResponseEntity response = null; 87 | try { 88 | studentService.delete(studentId); 89 | response = new ResponseEntity("Student deleted successfully with Id :" + 90 | studentId, HttpStatus.OK); 91 | } catch (Exception ex) { 92 | logger.error(ex.getMessage(), ex); 93 | return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 94 | } 95 | return response; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /spring-boot-cassandra-datastax/src/main/java/com/tuturself/datastax/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.datastax.model; 2 | 3 | import com.datastax.driver.mapping.annotations.ClusteringColumn; 4 | import com.datastax.driver.mapping.annotations.Column; 5 | import com.datastax.driver.mapping.annotations.PartitionKey; 6 | import com.datastax.driver.mapping.annotations.Table; 7 | import com.google.common.base.Objects; 8 | 9 | import java.util.UUID; 10 | 11 | @Table(keyspace = "tuturself", name = "student") 12 | public class Student { 13 | 14 | /* 15 | * This is an annotated entity, but that correspond to a table that has a 16 | * clustering column. Note that if there is more than one clustering column, 17 | * the order must be specified (@ClusteringColumn(0), @ClusteringColumn(1), 18 | * ...). The same stands for the @PartitionKey. 19 | */ 20 | @PartitionKey 21 | @Column(name = "student_id") 22 | private UUID studentId; 23 | 24 | @ClusteringColumn 25 | @Column(name = "department_id") 26 | private Integer departmentId; 27 | 28 | private String name; 29 | private String address; 30 | 31 | public UUID getStudentId() { 32 | return studentId; 33 | } 34 | 35 | public void setStudentId(UUID studentId) { 36 | this.studentId = studentId; 37 | } 38 | 39 | public Integer getDepartmentId() { 40 | return departmentId; 41 | } 42 | 43 | public void setDepartmentId(Integer departmentId) { 44 | this.departmentId = departmentId; 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | public String getAddress() { 56 | return address; 57 | } 58 | 59 | public void setAddress(String address) { 60 | this.address = address; 61 | } 62 | 63 | @Override 64 | public boolean equals(Object other) { 65 | if (other == null || other.getClass() != this.getClass()) 66 | return false; 67 | 68 | Student that = (Student) other; 69 | return Objects.equal(studentId, that.studentId) && Objects.equal(departmentId, that.departmentId) 70 | && Objects.equal(name, that.name) && Objects.equal(address, that.address); 71 | } 72 | 73 | @Override 74 | public int hashCode() { 75 | return Objects.hashCode(studentId, departmentId, name, address); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /spring-boot-cassandra-datastax/src/main/java/com/tuturself/datastax/repository/CassandraConnector.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.datastax.repository; 2 | 3 | import com.datastax.driver.core.*; 4 | import com.google.common.collect.Lists; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Value; 8 | import org.springframework.stereotype.Repository; 9 | 10 | import javax.annotation.PostConstruct; 11 | import java.net.InetSocketAddress; 12 | import java.util.List; 13 | import java.util.Optional; 14 | 15 | @Repository 16 | public class CassandraConnector { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(CassandraConnector.class); 19 | 20 | @Value("${cassandra.host}") 21 | private String hostList; 22 | 23 | @Value("${cassandra.cluster.name}") 24 | private String clusterName; 25 | 26 | @Value("${cassandra.cluster.username}") 27 | private String userName; 28 | 29 | @Value("${cassandra.cluster.password}") 30 | private String password; 31 | 32 | private static Cluster cluster; 33 | private static Session session; 34 | private static ConsistencyLevel consistencyLevel; 35 | 36 | @PostConstruct 37 | public void connectToCluster() throws Exception { 38 | try { 39 | PoolingOptions poolingOptions = new PoolingOptions(); 40 | poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, 10); 41 | poolingOptions.setPoolTimeoutMillis(5000); 42 | poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, 10); 43 | PlainTextAuthProvider authProvider = new PlainTextAuthProvider(userName, password); 44 | 45 | cluster = Cluster.builder().addContactPointsWithPorts(getHostIntetSocketAddressList(hostList)) 46 | .withClusterName(clusterName).withAuthProvider(authProvider).withPoolingOptions(poolingOptions) 47 | .build(); 48 | 49 | consistencyLevel = getSession().getCluster().getMetadata().getAllHosts().size() > 1 ? ConsistencyLevel.ALL 50 | : ConsistencyLevel.ONE; 51 | } catch (Exception ex) { 52 | throw ex; 53 | } 54 | } 55 | 56 | private List getHostIntetSocketAddressList(String hostList) { 57 | List cassandraHosts = Lists.newArrayList(); 58 | for (String host : hostList.split(",")) { 59 | InetSocketAddress socketAddress = new InetSocketAddress(host.split(":")[0], 60 | Integer.valueOf(host.split(":")[1])); 61 | cassandraHosts.add(socketAddress); 62 | } 63 | return cassandraHosts; 64 | } 65 | 66 | public ConsistencyLevel getConsistencyLevel() { 67 | Optional consistencyLevelOptional = Optional.of(consistencyLevel); 68 | if (consistencyLevelOptional.isPresent()) { 69 | return consistencyLevel; 70 | } 71 | return null; 72 | } 73 | 74 | public Session getSession() { 75 | if (cluster == null) { 76 | throw new RuntimeException("Cassandra Cluster in NULL"); 77 | } 78 | if (session == null) { 79 | session = cluster.connect(); 80 | } 81 | return session; 82 | } 83 | 84 | public void close() { 85 | if (session != null) { 86 | logger.debug("Closing Session...."); 87 | try { 88 | session.close(); 89 | } catch (Exception e) { 90 | logger.error("Error while closing the Session ..."); 91 | } 92 | } 93 | if (cluster != null) { 94 | logger.debug("Closing Cluster...."); 95 | try { 96 | cluster.close(); 97 | } catch (Exception e) { 98 | logger.error("Error while closing the Cluster ..."); 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /spring-boot-cassandra-datastax/src/main/java/com/tuturself/datastax/repository/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.datastax.repository; 2 | 3 | import com.datastax.driver.core.ResultSet; 4 | import com.datastax.driver.core.Session; 5 | import com.datastax.driver.core.Statement; 6 | import com.datastax.driver.core.querybuilder.QueryBuilder; 7 | import com.datastax.driver.mapping.Mapper; 8 | import com.datastax.driver.mapping.MappingManager; 9 | import com.datastax.driver.mapping.Result; 10 | import com.tuturself.datastax.model.Student; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.beans.factory.annotation.Value; 13 | import org.springframework.stereotype.Service; 14 | 15 | import javax.annotation.PostConstruct; 16 | 17 | import java.util.UUID; 18 | 19 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; 20 | 21 | 22 | @Service 23 | public class StudentService { 24 | 25 | @Autowired 26 | private CassandraConnector cassandraConnector; 27 | 28 | @Value("${cassandra.keyspace.name}") 29 | private String keyspaceName; 30 | 31 | private Session session; 32 | private MappingManager manager; 33 | private Mapper mapper; 34 | 35 | @PostConstruct 36 | public void init() { 37 | try { 38 | session = cassandraConnector.getSession(); 39 | manager = new MappingManager(session); 40 | mapper = manager.mapper(Student.class); 41 | } catch (Exception e) { 42 | throw new RuntimeException("Failed to initiate StudentService", e); 43 | } 44 | } 45 | 46 | public Result getStudentById(UUID studentId) throws Exception { 47 | Result result = null; 48 | Statement statement = QueryBuilder 49 | .select() 50 | .from(keyspaceName, "student") 51 | .where(eq("student_id", studentId)).setFetchSize(10); 52 | statement.setConsistencyLevel(cassandraConnector.getConsistencyLevel()); 53 | try { 54 | ResultSet resultSet = session.execute(statement); 55 | result = mapper.map(resultSet); 56 | 57 | } catch (Exception e) { 58 | throw new Exception("Failed to search Student for studentId :" + studentId.toString(), e); 59 | } 60 | return result; 61 | } 62 | 63 | public UUID createStudent(Integer deptId, String name, String address) throws Exception { 64 | Student student = new Student(); 65 | student.setStudentId(UUID.randomUUID()); 66 | student.setDepartmentId(deptId); 67 | student.setName(name); 68 | student.setAddress(address); 69 | mapper.save(student); 70 | return student.getStudentId(); 71 | } 72 | 73 | public void delete(UUID studentId) throws Exception { 74 | Student student = getStudentById(studentId).one(); 75 | mapper.delete(student); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /spring-boot-cassandra-datastax/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | application: 2 | name: spring-boot-cassandra-datastax 3 | server: 4 | port: 8089 5 | context-path: /student-api 6 | # Following are Cassandra Configuration 7 | cassandra: 8 | host: 127.0.0.1:9042 9 | cluster: 10 | name: test 11 | username: cassandra 12 | password: cassandra 13 | keyspace: 14 | name: tuturself -------------------------------------------------------------------------------- /spring-boot-consul/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.tuturself 8 | spring-boot-consul 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 2.0.0.RELEASE 15 | 16 | 17 | 18 | 19 | 1.16.20 20 | 2.0.0.M5 21 | 5.0.4.RELEASE 22 | 2.8.0 23 | UTF-8 24 | UTF-8 25 | 1.8 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-web 34 | 35 | 36 | org.springframework 37 | spring-context 38 | ${spring-framework-version} 39 | 40 | 41 | org.springframework.cloud 42 | spring-cloud-starter-consul-all 43 | ${spring-cloud-consul-version} 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-consul-discovery 48 | ${spring-cloud-consul-version} 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-test 53 | test 54 | 55 | 56 | 57 | 58 | 59 | io.springfox 60 | springfox-swagger2 61 | ${swagger.version} 62 | 63 | 64 | io.springfox 65 | springfox-swagger-ui 66 | ${swagger.version} 67 | 68 | 69 | 70 | 71 | 72 | org.projectlombok 73 | lombok 74 | ${lombok.version} 75 | provided 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.apache.maven.plugins 84 | maven-compiler-plugin 85 | 3.5.1 86 | 87 | ${java.version} 88 | ${java.version} 89 | ${java.version} 90 | 91 | 92 | 93 | org.springframework.boot 94 | spring-boot-maven-plugin 95 | 96 | true 97 | 98 | 99 | 100 | 101 | 102 | src/main/resources 103 | true 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | spring-milestones 112 | Spring Milestones 113 | http://repo.spring.io/milestone 114 | 115 | false 116 | 117 | 118 | 119 | 120 | 121 | 122 | org.springframework.cloud 123 | spring-cloud-dependencies 124 | Finchley.M7 125 | pom 126 | import 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /spring-boot-consul/src/main/java/com/tuturself/SpringBoot2Consul.java: -------------------------------------------------------------------------------- 1 | package com.tuturself; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | 8 | /** 9 | * Created by Arpan Das on 3/22/2018. 10 | */ 11 | @EnableAutoConfiguration 12 | @EnableDiscoveryClient 13 | @SpringBootApplication 14 | public class SpringBoot2Consul { 15 | 16 | public static void main(String[] args) { 17 | System.out.println("SpringBoot2Consul Application is Starting..."); 18 | try { 19 | SpringApplication.run(SpringBoot2Consul.class, args); 20 | } catch (Exception e) { 21 | System.out.println("Error occurred while starting SpringBoot2Consul"); 22 | } 23 | System.out.println("SpringBoot2Consul Application Started.."); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-consul/src/main/java/com/tuturself/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.config; 2 | 3 | import org.springframework.boot.autoconfigure.domain.EntityScan; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.ComponentScan; 6 | import org.springframework.context.annotation.Configuration; 7 | import springfox.documentation.builders.ApiInfoBuilder; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.service.Contact; 12 | import springfox.documentation.spi.DocumentationType; 13 | import springfox.documentation.spring.web.plugins.Docket; 14 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 15 | 16 | /** 17 | * @author Arpan Das 18 | */ 19 | @Configuration 20 | @EnableSwagger2 21 | @ComponentScan("com.tuturself.*") 22 | @EntityScan("com.tuturself.model") 23 | public class SwaggerConfig { 24 | 25 | @Bean 26 | public Docket api() { 27 | return new Docket(DocumentationType.SWAGGER_2) 28 | .select() 29 | .apis(RequestHandlerSelectors.basePackage("com.tuturself.webservice")) 30 | .paths(PathSelectors.any()) 31 | .build().apiInfo(metaData()) 32 | .useDefaultResponseMessages(false); 33 | } 34 | 35 | private ApiInfo metaData() { 36 | return new ApiInfoBuilder() 37 | .title("Spring Boot 2.0 Consul Integration with Swagger 2.8.0") 38 | .description("Spring Boot 2.0 Spring Cloud Consul Integration") 39 | .version("version 1.0") 40 | .contact(new Contact("Tutu'rself", "https://www.tuturself.com", "arpan.kgp@gmail.com")) 41 | .build(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /spring-boot-consul/src/main/java/com/tuturself/model/ConsulConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.model; 2 | 3 | import lombok.Data; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Data 8 | @Configuration 9 | public class ConsulConfiguration { 10 | 11 | @Value("${cassandra.host}") 12 | private String cassandraHost; 13 | 14 | @Value("${cassandra.user}") 15 | private String userName; 16 | 17 | @Value("${cassandra.password}") 18 | private String password; 19 | 20 | @Value("${cassandra.pooling.maxThread}") 21 | private int maxThread; 22 | 23 | @Value("${cassandra.pooling.timeout}") 24 | private int timeout; 25 | 26 | @Value("${cassandra.keyspace.name}") 27 | private String keyspace; 28 | 29 | @Value("${cassandra.keyspace.readConsistency}") 30 | private String readConsistency; 31 | 32 | @Value("${cassandra.keyspace.writeConsistency}") 33 | private String writeConsistency; 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-consul/src/main/java/com/tuturself/webservice/RestApi.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.webservice; 2 | 3 | import com.tuturself.model.ConsulConfiguration; 4 | import io.swagger.annotations.*; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @RestController 14 | @RequestMapping("/api") 15 | @Api(value = "Guidelines", description = "Describes the guidelines for using " + 16 | " Spring boot 2.0 with Consul integration", 17 | protocols = "http", consumes = MediaType.APPLICATION_JSON_VALUE, 18 | produces = MediaType.APPLICATION_JSON_VALUE) 19 | public class RestApi { 20 | 21 | @Autowired 22 | private ConsulConfiguration consulConfiguration; 23 | 24 | @RequestMapping(value = "/readConsulConfig", method = RequestMethod.GET) 25 | @ApiOperation(value = "Make a GET request read the Consul Configuration", 26 | produces = "application/json", response = ResponseEntity.class) 27 | @ApiResponses(value = { 28 | @ApiResponse(code = 200, message = "The GET call is Successful"), 29 | @ApiResponse(code = 500, message = "The GET call is Failed"), 30 | @ApiResponse(code = 404, message = "The API could not be found") 31 | }) 32 | public ResponseEntity readConsulConfiguration() { 33 | return new ResponseEntity(consulConfiguration.toString(), HttpStatus.OK); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-consul/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: spring-boot-consul 4 | cloud: 5 | consul: 6 | host: localhost 7 | port: 8500 8 | discovery: 9 | tags: spring-boot-consul 10 | enabled: true 11 | config: 12 | enabled: true 13 | format: files 14 | fail-fast: true 15 | server: 16 | servlet: 17 | contextPath: /spring-boot-consul 18 | logging: 19 | level: 20 | ROOT: DEBUG 21 | -------------------------------------------------------------------------------- /spring-boot-file-upload/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | com.tuturself 8 | spring-boot-file-upload 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 2.0.1.RELEASE 15 | 16 | 17 | 18 | 19 | 1.16.20 20 | 5.0.5.RELEASE 21 | 2.0.0.M5 22 | 2.8.0 23 | UTF-8 24 | UTF-8 25 | 1.8 26 | 27 | 28 | 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-web 34 | 35 | 36 | org.springframework 37 | spring-context 38 | ${spring-framework-version} 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-test 43 | test 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-consul-all 48 | ${spring-cloud-consul-version} 49 | 50 | 51 | org.springframework.cloud 52 | spring-cloud-consul-discovery 53 | ${spring-cloud-consul-version} 54 | 55 | 56 | 57 | 58 | 59 | io.springfox 60 | springfox-swagger2 61 | ${swagger.version} 62 | 63 | 64 | io.springfox 65 | springfox-swagger-ui 66 | ${swagger.version} 67 | 68 | 69 | 70 | 71 | 72 | org.projectlombok 73 | lombok 74 | ${lombok.version} 75 | provided 76 | 77 | 78 | commons-fileupload 79 | commons-fileupload 80 | 1.3.3 81 | 82 | 83 | 84 | org.apache.commons 85 | commons-io 86 | 1.3.2 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | org.apache.maven.plugins 95 | maven-compiler-plugin 96 | 3.5.1 97 | 98 | ${java.version} 99 | ${java.version} 100 | ${java.version} 101 | 102 | 103 | 104 | org.springframework.boot 105 | spring-boot-maven-plugin 106 | 107 | true 108 | 109 | 110 | 111 | 112 | 113 | src/main/resources 114 | true 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | spring-milestones 123 | Spring Milestones 124 | http://repo.spring.io/milestone 125 | 126 | false 127 | 128 | 129 | 130 | 131 | 132 | 133 | org.springframework.cloud 134 | spring-cloud-dependencies 135 | Finchley.M7 136 | pom 137 | import 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /spring-boot-file-upload/src/main/java/com/tuturself/SpringBoot2FileUpload.java: -------------------------------------------------------------------------------- 1 | package com.tuturself; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.web.multipart.commons.CommonsMultipartResolver; 10 | 11 | /** 12 | * Created by Arpan Das on 4/17/2018. 13 | */ 14 | 15 | @Slf4j 16 | @EnableDiscoveryClient 17 | @SpringBootApplication 18 | @EnableAutoConfiguration 19 | public class SpringBoot2FileUpload { 20 | 21 | public static void main(String[] args) { 22 | log.info("SpringBoot2FileUpload Application is Starting..."); 23 | try { 24 | SpringApplication.run(SpringBoot2FileUpload.class, args); 25 | } catch (Exception e) { 26 | log.error("Error occurred while starting SpringBoot2FileUpload"); 27 | } 28 | log.info("SpringBoot2FileUpload Application Started.."); 29 | } 30 | 31 | @Bean(name = "multipartResolver") 32 | public CommonsMultipartResolver multipartResolver() { 33 | CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(); 34 | multipartResolver.setMaxUploadSize(-1); 35 | return multipartResolver; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-file-upload/src/main/java/com/tuturself/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.service.Contact; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | /** 15 | * @author Arpan Das 16 | */ 17 | @Configuration 18 | @EnableSwagger2 19 | public class SwaggerConfig { 20 | 21 | @Bean 22 | public Docket api() { 23 | return new Docket(DocumentationType.SWAGGER_2) 24 | .select() 25 | .apis(RequestHandlerSelectors.basePackage("com.tuturself.webservice")) 26 | .paths(PathSelectors.any()) 27 | .build().apiInfo(metaData()) 28 | .useDefaultResponseMessages(false); 29 | } 30 | 31 | private ApiInfo metaData() { 32 | return new ApiInfoBuilder() 33 | .title("Spring Boot 2.0 File Upload example with Consul Integration & Swagger 2.8.0") 34 | .description("Upload file with Swagger-ui 2.8.0 using Spring Boot 2.0 Spring Cloud Consul") 35 | .version("version 1.0") 36 | .contact(new Contact("Tutu'rself", "https://www.tuturself.com", "arpan.kgp@gmail.com")) 37 | .build(); 38 | } 39 | } -------------------------------------------------------------------------------- /spring-boot-file-upload/src/main/java/com/tuturself/webservice/FileUploadRestApi.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.webservice; 2 | 3 | import io.swagger.annotations.*; 4 | import org.apache.commons.io.FileUtils; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestPart; 11 | import org.springframework.web.bind.annotation.RestController; 12 | import org.springframework.web.multipart.MultipartFile; 13 | 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.util.List; 17 | 18 | @RestController 19 | @RequestMapping("/upload") 20 | @Api(value = "Guidelines", description = "Describes the guidelines for " + 21 | " Spring boot 2.0.1 for uploading large file using Swagger UI") 22 | public class FileUploadRestApi { 23 | 24 | @PostMapping 25 | @ApiOperation(value = "Make a POST request to upload the file", 26 | produces = "application/json", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) 27 | @ApiResponses(value = { 28 | @ApiResponse(code = 200, message = "The POST call is Successful"), 29 | @ApiResponse(code = 500, message = "The POST call is Failed"), 30 | @ApiResponse(code = 404, message = "The API could not be found") 31 | }) 32 | public ResponseEntity uploadFile( 33 | @ApiParam(name = "file", value = "Select the file to Upload", required = true) 34 | @RequestPart("file") MultipartFile file) { 35 | 36 | try { 37 | File testFile = new File("test"); 38 | FileUtils.writeByteArrayToFile(testFile, file.getBytes()); 39 | List lines = FileUtils.readLines(testFile); 40 | lines.forEach(line -> System.out.println(line)); 41 | } catch (IOException e) { 42 | e.printStackTrace(); 43 | return new ResponseEntity("Failed", HttpStatus.INTERNAL_SERVER_ERROR); 44 | } 45 | return new ResponseEntity("Done", HttpStatus.OK); 46 | } 47 | } -------------------------------------------------------------------------------- /spring-boot-file-upload/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: spring-boot-file-upload 4 | cloud: 5 | consul: 6 | host: localhost 7 | port: 8500 8 | discovery: 9 | tags: spring-boot-file-upload 10 | enabled: true 11 | config: 12 | enabled: true 13 | format: files 14 | fail-fast: true -------------------------------------------------------------------------------- /spring-boot-jdbc/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if(mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if(mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if(!outputFile.getParentFile().exists()) { 87 | if(!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /spring-boot-jdbc/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninja-panda/spring-boot-example/00b41debaddaa0ece2ae606c7c9d0f39c2a2f40e/spring-boot-jdbc/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-jdbc/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /spring-boot-jdbc/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /spring-boot-jdbc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.0.M6 9 | 10 | 11 | com.tuturself 12 | demo 13 | 0.0.1-SNAPSHOT 14 | demo 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-jdbc 30 | 31 | 32 | 33 | org.projectlombok 34 | lombok 35 | 1.18.10 36 | provided 37 | 38 | 39 | 40 | mysql 41 | mysql-connector-java 42 | runtime 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-test 47 | test 48 | 49 | 50 | org.junit.vintage 51 | junit-vintage-engine 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | spring-milestones 69 | Spring Milestones 70 | https://repo.spring.io/milestone 71 | 72 | 73 | 74 | 75 | spring-milestones 76 | Spring Milestones 77 | https://repo.spring.io/milestone 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/java/com/tuturself/demo/API.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo; 2 | 3 | import com.tuturself.demo.model.City; 4 | import com.tuturself.demo.model.Country; 5 | import com.tuturself.demo.service.Repository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.util.List; 12 | 13 | @RestController 14 | public class API { 15 | 16 | private String message = "Data saved successfully"; 17 | 18 | @Autowired 19 | private Repository repository; 20 | 21 | @GetMapping("/city/{cityId}") 22 | public ResponseEntity getCity(@PathVariable("cityId") Integer cityId) { 23 | City city = repository.getCityById(cityId); 24 | return new ResponseEntity(city, HttpStatus.OK); 25 | } 26 | 27 | @GetMapping("/country/{countryId}/cities") 28 | public ResponseEntity getCityListByCountryId(@PathVariable("countryId") Integer countryId) { 29 | List cityList = repository.getCityListByCountryId(countryId); 30 | return new ResponseEntity(cityList, HttpStatus.OK); 31 | } 32 | 33 | @GetMapping("/country/{countryId}") 34 | public ResponseEntity getCountryById(@PathVariable("countryId") Integer countryId) { 35 | Country country = repository.getCountryById(countryId); 36 | return new ResponseEntity(country, HttpStatus.OK); 37 | } 38 | 39 | @GetMapping("/countries") 40 | public ResponseEntity getCountryList() { 41 | List countryList = repository.getCountryList(); 42 | return new ResponseEntity(countryList, HttpStatus.OK); 43 | } 44 | 45 | @PostMapping("/country") 46 | public ResponseEntity addCountry(@RequestParam("name") String countryName) { 47 | Country country = new Country(); 48 | country.setName(countryName); 49 | repository.save(country, false); 50 | return new ResponseEntity(message, HttpStatus.OK); 51 | } 52 | 53 | @PutMapping("/country/{countryId}") 54 | public ResponseEntity updateCountryById(@PathVariable("countryId") Integer countryId, 55 | @RequestParam("name") String countryName) { 56 | Country country = new Country(); 57 | country.setId(countryId); 58 | country.setName(countryName); 59 | repository.save(country, true); 60 | return new ResponseEntity(message, HttpStatus.OK); 61 | } 62 | 63 | @PostMapping("/city") 64 | public ResponseEntity addCity(@RequestParam("countryId") Integer countryId, 65 | @RequestParam("name") String cityName) { 66 | City city = new City(); 67 | city.setCountryId(countryId); 68 | city.setName(cityName); 69 | repository.save(city, false); 70 | return new ResponseEntity(message, HttpStatus.OK); 71 | } 72 | 73 | @PutMapping("/city/{cityId}") 74 | public ResponseEntity updateCityById(@PathVariable("cityId") Integer cityId, 75 | @RequestParam("name") String cityName, 76 | @RequestParam("countryId") Integer countryId) { 77 | City city = new City(); 78 | city.setId(cityId); 79 | city.setName(cityName); 80 | city.setCountryId(countryId); 81 | return new ResponseEntity(city, HttpStatus.OK); 82 | } 83 | 84 | @DeleteMapping("/city/{cityId}") 85 | public ResponseEntity deleteCity(@PathVariable("cityId") Integer cityId) { 86 | repository.deleteCityById(cityId); 87 | return new ResponseEntity("The City with cityId" + cityId + " is deleted from database", HttpStatus.OK); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/java/com/tuturself/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/java/com/tuturself/demo/mapper/CityMapper.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo.mapper; 2 | 3 | import com.tuturself.demo.model.City; 4 | import org.springframework.jdbc.core.RowMapper; 5 | 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | 9 | public class CityMapper implements RowMapper { 10 | 11 | @Override 12 | public City mapRow(ResultSet row, int rowNum) throws SQLException { 13 | City city = new City(); 14 | city.setId(row.getInt("city_id")); 15 | city.setName(row.getString("city")); 16 | city.setCountryId(row.getInt("country_id")); 17 | city.setCountryName(row.getString("country")); 18 | return city; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/java/com/tuturself/demo/mapper/CountryMapper.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo.mapper; 2 | 3 | import com.tuturself.demo.model.Country; 4 | import org.springframework.jdbc.core.RowMapper; 5 | 6 | import java.sql.ResultSet; 7 | import java.sql.SQLException; 8 | 9 | public class CountryMapper implements RowMapper { 10 | 11 | @Override 12 | public Country mapRow(ResultSet row, int rowNum) throws SQLException { 13 | Country country = new Country(); 14 | country.setId(row.getInt("country_id")); 15 | country.setName(row.getString("country")); 16 | return country; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/java/com/tuturself/demo/model/City.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class City { 7 | 8 | private Integer id; 9 | private String name; 10 | private Integer countryId; 11 | private String countryName; 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/java/com/tuturself/demo/model/Country.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class Country { 9 | 10 | private Integer id; 11 | private String name; 12 | private List cityList; 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/java/com/tuturself/demo/service/QueryProvider.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo.service; 2 | 3 | import lombok.Getter; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.context.annotation.PropertySource; 7 | 8 | @Getter 9 | @Configuration 10 | @PropertySource("classpath:/Queries.properties") 11 | public class QueryProvider { 12 | 13 | @Value("${city}") 14 | private String city; 15 | 16 | @Value("${country}") 17 | private String country; 18 | 19 | @Value("${add.country}") 20 | private String addCountry; 21 | 22 | @Value("${add.city}") 23 | private String addCity; 24 | 25 | @Value("${update.country}") 26 | private String updateCountry; 27 | 28 | @Value("${update.city}") 29 | private String updateCity; 30 | } 31 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/java/com/tuturself/demo/service/Repository.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo.service; 2 | 3 | import com.tuturself.demo.mapper.CityMapper; 4 | import com.tuturself.demo.mapper.CountryMapper; 5 | import com.tuturself.demo.model.City; 6 | import com.tuturself.demo.model.Country; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.jdbc.core.JdbcTemplate; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | @Service 14 | public class Repository { 15 | 16 | private final JdbcTemplate jdbcTemplate; 17 | 18 | @Autowired 19 | private QueryProvider queryProvider; 20 | 21 | @Autowired 22 | public Repository(JdbcTemplate jdbcTemplate) { 23 | this.jdbcTemplate = jdbcTemplate; 24 | } 25 | 26 | public City getCityById(Integer cityId) { 27 | String query = queryProvider.getCity() + " and ci.city_id = ?"; 28 | return this.jdbcTemplate.queryForObject(query, new Object[]{cityId}, new CityMapper()); 29 | } 30 | 31 | public List getCityListByCountryId(Integer countryId) { 32 | String query = queryProvider.getCity() + " and co.country_id = ?"; 33 | return this.jdbcTemplate.query(query, new Object[]{countryId}, new CityMapper()); 34 | } 35 | 36 | public Country getCountryById(Integer countryId) { 37 | String query = queryProvider.getCountry() + " and co.country_id = ?"; 38 | Country country = this.jdbcTemplate.queryForObject(query, new Object[]{countryId}, new CountryMapper()); 39 | if (country != null) { 40 | country.setCityList(getCityListByCountryId(country.getId())); 41 | } 42 | return country; 43 | } 44 | 45 | public List getCountryList() { 46 | List countryList = this.jdbcTemplate.query(queryProvider.getCountry(), new CountryMapper()); 47 | if (countryList != null && !countryList.isEmpty()) { 48 | countryList.forEach(country -> { 49 | country.setCityList(getCityListByCountryId(country.getId())); 50 | }); 51 | } 52 | return countryList; 53 | } 54 | 55 | public void save(City city, boolean isUpdate) { 56 | if (isUpdate) { 57 | jdbcTemplate.update(queryProvider.getUpdateCity(), city.getName(), city.getId()); 58 | } else { 59 | jdbcTemplate.update(queryProvider.getAddCity(), city.getName(), city.getCountryId()); 60 | } 61 | } 62 | 63 | public void save(Country country, boolean isUpdate) { 64 | if (isUpdate) { 65 | jdbcTemplate.update(queryProvider.getUpdateCountry(), country.getName(), country.getId()); 66 | } else { 67 | jdbcTemplate.update(queryProvider.getAddCountry(), country.getName()); 68 | } 69 | } 70 | 71 | public void deleteCityById(Integer cityId) { 72 | String query = "delete from city where city_id = ?"; 73 | jdbcTemplate.update(query, cityId); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/resources/Queries.properties: -------------------------------------------------------------------------------- 1 | city=select ci.city_id,ci.city,co.country_id,co.country \ 2 | from city ci, country co \ 3 | where ci.country_id = co.country_id 4 | 5 | country=select country_id,co.country from country co where 1=1 6 | 7 | add.country=insert into country (country) values (?) 8 | add.city=insert into city (city,country_id) values (?,?) 9 | 10 | update.country=update country set country =? where country_id=? 11 | update.city=update city set city = ? where city_id=? 12 | 13 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://localhost:3306/tutorial 3 | spring.datasource.username=root 4 | spring.datasource.password= root 5 | spring.datasource.tomcat.max-wait=20000 6 | spring.datasource.tomcat.max-active=50 7 | spring.datasource.tomcat.max-idle=20 8 | spring.datasource.tomcat.min-idle=15 9 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/main/resources/db.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `country` ( 2 | `country_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, 3 | `country` varchar(50) NOT NULL, 4 | `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 5 | PRIMARY KEY (`country_id`) 6 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 7 | 8 | CREATE TABLE `city` ( 9 | `city_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, 10 | `city` varchar(50) NOT NULL, 11 | `country_id` smallint(5) unsigned NOT NULL, 12 | `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 13 | PRIMARY KEY (`city_id`), 14 | KEY `idx_fk_country_id` (`country_id`), 15 | CONSTRAINT `fk_city_country` FOREIGN KEY (`country_id`) REFERENCES `country` (`country_id`) ON UPDATE CASCADE 16 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 17 | -------------------------------------------------------------------------------- /spring-boot-jdbc/src/test/java/com/tuturself/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-jersey/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.tuturself 5 | spring.boot.jersey 6 | 0.0.1-SNAPSHOT 7 | spring-boot-jersey 8 | 9 | 10 | org.springframework.boot 11 | spring-boot-starter-parent 12 | 1.5.1.RELEASE 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-jersey 19 | 20 | 21 | 22 | 23 | 1.8 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-maven-plugin 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /spring-boot-jersey/src/main/java/spring/boot/jersey/sample/JerseyConfig.java: -------------------------------------------------------------------------------- 1 | package spring.boot.jersey.sample; 2 | 3 | import javax.ws.rs.ApplicationPath; 4 | import javax.ws.rs.ext.ContextResolver; 5 | import javax.ws.rs.ext.Provider; 6 | 7 | import org.glassfish.jersey.server.ResourceConfig; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Component; 10 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | @Component 14 | @ApplicationPath("/personrepo") 15 | public class JerseyConfig extends ResourceConfig { 16 | 17 | @Autowired 18 | public JerseyConfig(ObjectMapper objectMapper) { 19 | // register endpoints 20 | packages("spring.boot.jersey.sample.rest"); 21 | // register jackson for json 22 | register(new ObjectMapperContextResolver(objectMapper)); 23 | } 24 | 25 | @Provider 26 | public static class ObjectMapperContextResolver implements ContextResolver { 27 | private final ObjectMapper mapper; 28 | public ObjectMapperContextResolver(ObjectMapper mapper) { 29 | this.mapper = mapper; 30 | } 31 | 32 | @Override 33 | public ObjectMapper getContext(Class type) { 34 | return mapper; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-jersey/src/main/java/spring/boot/jersey/sample/SpringBootJerseyApplication.java: -------------------------------------------------------------------------------- 1 | package spring.boot.jersey.sample; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | 6 | @SpringBootApplication 7 | public class SpringBootJerseyApplication { 8 | 9 | public static void main(String[] args) { 10 | new SpringApplicationBuilder(SpringBootJerseyApplication.class).run(args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-jersey/src/main/java/spring/boot/jersey/sample/data/Person.java: -------------------------------------------------------------------------------- 1 | package spring.boot.jersey.sample.data; 2 | 3 | public class Person { 4 | 5 | private int personId; 6 | private String name; 7 | private String email; 8 | 9 | public Person(int personId, String name, String email) { 10 | super(); 11 | this.personId = personId; 12 | this.name = name; 13 | this.email = email; 14 | } 15 | 16 | public int getPersonId() { 17 | return personId; 18 | } 19 | 20 | public void setPersonId(int personId) { 21 | this.personId = personId; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public String getEmail() { 33 | return email; 34 | } 35 | 36 | public void setEmail(String email) { 37 | this.email = email; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-boot-jersey/src/main/java/spring/boot/jersey/sample/data/PersonService.java: -------------------------------------------------------------------------------- 1 | package spring.boot.jersey.sample.data; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service 11 | public class PersonService { 12 | 13 | private final List personList = new ArrayList<>(); 14 | 15 | @PostConstruct 16 | public void init() { 17 | personList.add(new Person(1, "Bari kruchten", "b.kruchten@xyz.com")); 18 | personList.add(new Person(2, "Juliet Roker", "jrocker@hkmail.com")); 19 | personList.add(new Person(3, "Idalia Clover", "clover@hmail.com")); 20 | personList.add(new Person(1, "Aspaiht", "aspaiht.t@xyz.com")); 21 | } 22 | 23 | public Person getById(int personId) { 24 | return personList.stream().filter((person) -> person.getPersonId() == personId).findFirst().get(); 25 | } 26 | 27 | public List getAllPersons() { 28 | return personList; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-jersey/src/main/java/spring/boot/jersey/sample/rest/PersonSearchEndPoint.java: -------------------------------------------------------------------------------- 1 | package spring.boot.jersey.sample.rest; 2 | 3 | import javax.ws.rs.GET; 4 | import javax.ws.rs.Path; 5 | import javax.ws.rs.PathParam; 6 | import javax.ws.rs.Produces; 7 | import javax.ws.rs.core.Response; 8 | 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | 12 | import spring.boot.jersey.sample.data.Person; 13 | import spring.boot.jersey.sample.data.PersonService; 14 | 15 | @Component 16 | @Path("/search") 17 | @Produces("application/json") 18 | public class PersonSearchEndPoint { 19 | 20 | @Autowired 21 | private PersonService personService; 22 | 23 | @Path("/{personId}") 24 | @GET 25 | public Response getById(@PathParam("personId") final int personId) { 26 | final Person person = personService.getById(personId); 27 | return Response.ok(person).build(); 28 | } 29 | 30 | @GET 31 | public Response getAllPersons() { 32 | return Response.ok(personService.getAllPersons()).build(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-jersey/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | _____ _ _ _ __ 2 | |_ _| | | ( ) | | / _| 3 | | | _ _ | |_ _ _|/ _ __ ___ ___ | || |_ 4 | | || | | || __|| | | | | '__|/ __| / _ \| || _| 5 | | || |_| || |_ | |_| | | | \__ \| __/| || | 6 | \_/ \__,_| \__| \__,_| |_| |___/ \___||_||_| 7 | 8 | ${Ansi.GREEN} :: Spring Boot ::${spring-boot.formatted-version} ${Ansi.DEFAULT} 9 | -------------------------------------------------------------------------------- /spring-boot-logback/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.tuturself 5 | spring-boot-logback 6 | ${application.version}-${release.number} 7 | spring-boot-logback 8 | 9 | 10 | 1.8 11 | 1.0.0 12 | SNAPSHOT 13 | 14 | 15 | 16 | org.springframework.boot 17 | spring-boot-starter-parent 18 | 1.5.1.RELEASE 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | 29 | org.jfairy 30 | jfairy 31 | 0.3.0 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | 42 | 43 | 44 | 45 | 46 | spring-releases 47 | https://repo.spring.io/libs-release 48 | 49 | 50 | 51 | 52 | 53 | spring-releases 54 | https://repo.spring.io/libs-release 55 | 56 | 57 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/java/com/tuturself/spring/boot/StudentSearchApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class StudentSearchApplication { 10 | 11 | private final static Logger logger = LoggerFactory.getLogger(StudentSearchApplication.class); 12 | 13 | public static void main(String[] args) throws Exception { 14 | logger.debug("StudentSearchApplication STARTing..."); 15 | SpringApplication.run(StudentSearchApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/java/com/tuturself/spring/boot/api/StudentAPI.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.api; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.jfairy.Fairy; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestParam; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | import com.tuturself.spring.boot.model.Student; 16 | 17 | @RestController 18 | public class StudentAPI { 19 | 20 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 21 | 22 | private static Map studentDB; 23 | private Fairy fairy = Fairy.create(); 24 | 25 | /** 26 | * Create a Dummy Student database 27 | * 28 | * @throws Exception 29 | */ 30 | 31 | @PostConstruct 32 | public void init() throws Exception { 33 | logger.info("Intializng Student Database.."); 34 | studentDB = new HashMap<>(); 35 | for (int i = 0; i < 100; i++) { 36 | Student student = new Student(i, fairy.person()); 37 | studentDB.put(new Integer(i), student); 38 | } 39 | logger.info("Student Database intialized.."); 40 | } 41 | 42 | @RequestMapping("/students") 43 | public Student searchStudent(@RequestParam(name = "studentId", required = true) Integer studentId) { 44 | logger.debug("Searching for student with studentId ::" + studentId); 45 | Student student = getStudentById(studentId); 46 | return student; 47 | } 48 | 49 | private Student getStudentById(Integer studentId) { 50 | logger.info("Searching from student database for studentId : " + studentId); 51 | return studentDB.get(studentId); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/java/com/tuturself/spring/boot/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.model; 2 | 3 | import org.jfairy.producer.person.Address; 4 | import org.jfairy.producer.person.Person; 5 | import org.jfairy.producer.person.Person.Sex; 6 | import org.joda.time.DateTime; 7 | 8 | public class Student { 9 | 10 | private Integer studentId; 11 | private Address address; 12 | private String firstName; 13 | private String middleName; 14 | private String lastName; 15 | private String email; 16 | private Sex sex; 17 | private String telephoneNumber; 18 | private DateTime dateOfBirth; 19 | private Integer age; 20 | private String companyEmail; 21 | private String nationalIdentityCardNumber; 22 | private String nationalIdentificationNumber; 23 | 24 | public Student(int studentId, Person p) { 25 | this.studentId = studentId; 26 | this.nationalIdentityCardNumber = p.nationalIdentificationNumber(); 27 | this.address = p.getAddress(); 28 | this.firstName = p.firstName(); 29 | this.middleName = p.middleName(); 30 | this.lastName = p.lastName(); 31 | this.email = p.email(); 32 | this.sex = p.sex(); 33 | this.telephoneNumber = p.telephoneNumber(); 34 | this.dateOfBirth = p.dateOfBirth(); 35 | this.age = p.age(); 36 | this.nationalIdentificationNumber = p.nationalIdentificationNumber(); 37 | this.companyEmail = p.companyEmail(); 38 | } 39 | 40 | public Integer getStudentId() { 41 | return studentId; 42 | } 43 | 44 | public Address getAddress() { 45 | return address; 46 | } 47 | 48 | public String getFirstName() { 49 | return firstName; 50 | } 51 | 52 | public String getMiddleName() { 53 | return middleName; 54 | } 55 | 56 | public String getLastName() { 57 | return lastName; 58 | } 59 | 60 | public String getEmail() { 61 | return email; 62 | } 63 | 64 | public Sex getSex() { 65 | return sex; 66 | } 67 | 68 | public String getTelephoneNumber() { 69 | return telephoneNumber; 70 | } 71 | 72 | public DateTime getDateOfBirth() { 73 | return dateOfBirth; 74 | } 75 | 76 | public Integer getAge() { 77 | return age; 78 | } 79 | 80 | public String getCompanyEmail() { 81 | return companyEmail; 82 | } 83 | 84 | public String getNationalIdentityCardNumber() { 85 | return nationalIdentityCardNumber; 86 | } 87 | 88 | public String getNationalIdentificationNumber() { 89 | return nationalIdentificationNumber; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | org.springframework.web: ERROR 4 | com.tuturself: DEBUG 5 | pattern: 6 | console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" 7 | file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" 8 | file: ./logs/application.log -------------------------------------------------------------------------------- /spring-boot-route/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninja-panda/spring-boot-example/00b41debaddaa0ece2ae606c7c9d0f39c2a2f40e/spring-boot-route/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-route/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /spring-boot-route/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-boot-route/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-boot-route/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.tuturself.example 7 | spring-boot-route 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-route 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-actuator 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-webflux 35 | 36 | 37 | org.projectlombok 38 | lombok 39 | true 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | io.projectreactor 49 | reactor-test 50 | test 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /spring-boot-route/src/main/java/com/tuturself/example/springbootroute/Employee.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.example.springbootroute; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.UUID; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | @NoArgsConstructor 12 | class Employee { 13 | 14 | private UUID employeeId; 15 | private String name; 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-route/src/main/java/com/tuturself/example/springbootroute/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.example.springbootroute; 2 | 3 | import org.springframework.stereotype.Repository; 4 | 5 | import java.util.*; 6 | 7 | @Repository 8 | public class EmployeeRepository { 9 | 10 | List employeeList = new ArrayList<>(); 11 | 12 | public EmployeeRepository() { 13 | employeeList.add(new Employee(UUID.randomUUID(), "Robert Barnes")); 14 | employeeList.add(new Employee(UUID.randomUUID(), "Robin Bennett")); 15 | employeeList.add(new Employee(UUID.randomUUID(), "Harvey Berg")); 16 | employeeList.add(new Employee(UUID.randomUUID(), "Joanne Dalton")); 17 | employeeList.add(new Employee(UUID.randomUUID(), "Keifer Davey")); 18 | employeeList.add(new Employee(UUID.randomUUID(), "Grace Dobson")); 19 | } 20 | 21 | public List findAll() { 22 | return this.employeeList; 23 | } 24 | 25 | public List findById(String empIdStr) { 26 | UUID empId = UUID.fromString(empIdStr); 27 | Optional optionalEmp = employeeList.stream().filter(e -> e.getEmployeeId().equals(empId)).findFirst(); 28 | if (optionalEmp.isPresent()) 29 | return Arrays.asList(optionalEmp.get()); 30 | else return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-route/src/main/java/com/tuturself/example/springbootroute/SpringBootRouteApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.example.springbootroute; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.web.reactive.function.server.RequestPredicates; 7 | import org.springframework.web.reactive.function.server.RouterFunction; 8 | import org.springframework.web.reactive.function.server.RouterFunctions; 9 | import org.springframework.web.reactive.function.server.ServerResponse; 10 | import reactor.core.publisher.Flux; 11 | 12 | import java.time.Duration; 13 | import java.util.List; 14 | 15 | @SpringBootApplication 16 | public class SpringBootRouteApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(SpringBootRouteApplication.class, args); 20 | } 21 | 22 | @Bean 23 | RouterFunction routes(EmployeeRepository er) { 24 | return RouterFunctions.route(RequestPredicates.GET("/employees"), 25 | r -> ServerResponse.ok().body(Flux.just(er.findAll()), List.class)) 26 | .andRoute(RequestPredicates.GET("/employees/{id}"), 27 | r -> ServerResponse.ok().body(Flux.just(er.findById(r.pathVariable("id"))), List.class)) 28 | .andRoute(RequestPredicates.GET("/delay"), 29 | r -> ServerResponse.ok().body(Flux.just("Hello World!").delayElements( 30 | Duration.ofSeconds(10000)), String.class)); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-boot-route/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port = 8090 -------------------------------------------------------------------------------- /spring-boot-route/src/test/java/com/tuturself/example/springbootroute/SpringBootRouteApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.example.springbootroute; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringBootRouteApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-swagger/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.tuturself 5 | spring-boot-swagger 6 | 0.0.1-SNAPSHOT 7 | spring-boot-swagger 8 | spring-boot Swagger Integration 9 | 10 | 11 | 1.8 12 | 2.5.0 13 | 1.0.0 14 | SNAPSHOT 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-parent 20 | 1.5.1.RELEASE 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | 30 | 31 | io.springfox 32 | springfox-swagger2 33 | ${swagger.version} 34 | 35 | 36 | 37 | io.springfox 38 | springfox-swagger-ui 39 | ${swagger.version} 40 | 41 | 42 | 43 | 44 | org.jfairy 45 | jfairy 46 | 0.3.0 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | 57 | 58 | 59 | 60 | 61 | spring-releases 62 | https://repo.spring.io/libs-release 63 | 64 | 65 | 66 | 67 | 68 | spring-releases 69 | https://repo.spring.io/libs-release 70 | 71 | 72 | -------------------------------------------------------------------------------- /spring-boot-swagger/src/main/java/com/tuturself/spring/boot/StudentSearchApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class StudentSearchApplication { 10 | 11 | private final static Logger logger = LoggerFactory.getLogger(StudentSearchApplication.class); 12 | 13 | public static void main(String[] args) throws Exception { 14 | logger.debug("StudentSearchApplication is STARTing..."); 15 | SpringApplication.run(StudentSearchApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-swagger/src/main/java/com/tuturself/spring/boot/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.PathSelectors; 6 | import springfox.documentation.builders.RequestHandlerSelectors; 7 | import springfox.documentation.service.ApiInfo; 8 | import springfox.documentation.spi.DocumentationType; 9 | import springfox.documentation.spring.web.plugins.Docket; 10 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 11 | 12 | @Configuration 13 | @EnableSwagger2 14 | public class SwaggerConfig { 15 | 16 | @Bean 17 | public Docket api() { 18 | return new Docket(DocumentationType.SWAGGER_2) 19 | .select() 20 | .apis(RequestHandlerSelectors.basePackage("com.tuturself.spring.boot.api")) 21 | .paths(PathSelectors.any()) 22 | .build().apiInfo(apiInfo()); 23 | } 24 | 25 | private ApiInfo apiInfo() { 26 | ApiInfo apiInfo = new ApiInfo( 27 | "StudentSearchApplication", 28 | "An application to search Student from a Student repository by studentId", 29 | "StudentSearchApplication v1", 30 | "Terms of service", 31 | "tuturself@gmail.com", 32 | "License of API", 33 | "License URL"); 34 | return apiInfo; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-swagger/src/main/java/com/tuturself/spring/boot/api/StudentAPI.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.api; 2 | 3 | import java.util.List; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RequestHeader; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import com.tuturself.spring.boot.model.Student; 18 | import com.tuturself.spring.boot.service.StudentService; 19 | 20 | import io.swagger.annotations.Api; 21 | import io.swagger.annotations.ApiImplicitParam; 22 | import io.swagger.annotations.ApiImplicitParams; 23 | import io.swagger.annotations.ApiOperation; 24 | import io.swagger.annotations.ApiParam; 25 | 26 | @RestController 27 | @RequestMapping(value = "/students") 28 | @Api(value = "API to search Student from a Student Repository by different serach parameters", 29 | description = "This API provides the capability to search Student from a Student Repository", produces = "application/json") 30 | public class StudentAPI { 31 | 32 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 33 | 34 | @Autowired 35 | private StudentService studentService; 36 | 37 | @ApiOperation(value = "Search Student by studentId", produces = "application/json") 38 | @RequestMapping(value = "/{studentId}", method = RequestMethod.GET) 39 | public ResponseEntity searchStudentById( 40 | @ApiParam(name = "studentId", 41 | value = "The Id of the Student to be viewed", 42 | required = true) 43 | @PathVariable Integer studentId) { 44 | logger.debug("Searching for student with studentId ::" + studentId); 45 | Student student = null; 46 | try { 47 | student = studentService.getStudentById(studentId); 48 | logger.debug("Student found with studentId ::" + studentId); 49 | } catch (Exception ex) { 50 | logger.error("Error occurred in searchStudentById >>", ex, ex.getMessage()); 51 | return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 52 | } 53 | return new ResponseEntity(student, HttpStatus.OK); 54 | } 55 | 56 | @ApiOperation(value = "Search for all Students whose age is greater than input age", produces = "application/json") 57 | @RequestMapping(value = "/greaterThanAge/{age}", method = RequestMethod.GET) 58 | public ResponseEntity filterStudentsByAge( 59 | @ApiParam(name = "age", 60 | value = "filtering age", 61 | required = true) @PathVariable Integer age) { 62 | List studentList = null; 63 | try { 64 | studentList = studentService.filterByAge(age); 65 | } catch (Exception ex) { 66 | logger.error("Error occurred in filterStudentsByAge >>", ex, ex.getMessage()); 67 | return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 68 | } 69 | return new ResponseEntity(studentList, HttpStatus.OK); 70 | } 71 | 72 | @ApiOperation(value = "Search for all Students who are from input city", produces = "application/json") 73 | @RequestMapping(value = "/fromCity/{cityName}", method = RequestMethod.GET) 74 | public ResponseEntity filterStudentsByCity( 75 | @ApiParam(name = "cityName", value = "filtering city name", required = true) 76 | @PathVariable String cityName) { 77 | List studentList = null; 78 | try { 79 | studentList = studentService.filterByCity(cityName); 80 | } catch (Exception ex) { 81 | logger.error("Error occurred in filterStudentsByCity >>", ex, ex.getMessage()); 82 | return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 83 | } 84 | return new ResponseEntity(studentList, HttpStatus.OK); 85 | } 86 | 87 | @ApiOperation(value = "Search for all students who are from given city and " 88 | + "whose age are greater than input age", produces = "application/json") 89 | @ApiImplicitParams({ 90 | @ApiImplicitParam(name = "schoolId", value = "School Id", required = true, dataType = "String", paramType = "header"), 91 | @ApiImplicitParam(name = "age", value = "Age of Student", required = true, dataType = "Integer", paramType = "query"), 92 | @ApiImplicitParam(name = "cityName", value = "City of Student", required = true, dataType = "String", paramType = "query") }) 93 | @RequestMapping(value = "/filterByAgeAndCity", method = RequestMethod.GET) 94 | public ResponseEntity filterStudentsByAgeAndCity(@RequestHeader(name = "schoolId") String userId, 95 | @RequestParam Integer age,@RequestParam String cityName) { 96 | 97 | List studentList = null; 98 | try { 99 | studentList = studentService.filterByAgeAndCity(age, cityName); 100 | } catch (Exception ex) { 101 | logger.error("Error occurred in filterStudentsByAgeAndCity >>", ex, ex.getMessage()); 102 | return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 103 | } 104 | return new ResponseEntity(studentList, HttpStatus.OK); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /spring-boot-swagger/src/main/java/com/tuturself/spring/boot/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.model; 2 | 3 | import org.jfairy.producer.person.Address; 4 | import org.jfairy.producer.person.Person; 5 | import org.jfairy.producer.person.Person.Sex; 6 | import org.joda.time.DateTime; 7 | 8 | public class Student { 9 | 10 | private Integer studentId; 11 | private Address address; 12 | private String firstName; 13 | private String middleName; 14 | private String lastName; 15 | private String email; 16 | private Sex sex; 17 | private String telephoneNumber; 18 | private DateTime dateOfBirth; 19 | private Integer age; 20 | private String companyEmail; 21 | private String nationalIdentityCardNumber; 22 | private String nationalIdentificationNumber; 23 | 24 | public Student(int studentId, Person p) { 25 | this.studentId = studentId; 26 | this.nationalIdentityCardNumber = p.nationalIdentificationNumber(); 27 | this.address = p.getAddress(); 28 | this.firstName = p.firstName(); 29 | this.middleName = p.middleName(); 30 | this.lastName = p.lastName(); 31 | this.email = p.email(); 32 | this.sex = p.sex(); 33 | this.telephoneNumber = p.telephoneNumber(); 34 | this.dateOfBirth = p.dateOfBirth(); 35 | this.age = p.age(); 36 | this.nationalIdentificationNumber = p.nationalIdentificationNumber(); 37 | this.companyEmail = p.companyEmail(); 38 | } 39 | 40 | public Integer getStudentId() { 41 | return studentId; 42 | } 43 | 44 | public Address getAddress() { 45 | return address; 46 | } 47 | 48 | public String getFirstName() { 49 | return firstName; 50 | } 51 | 52 | public String getMiddleName() { 53 | return middleName; 54 | } 55 | 56 | public String getLastName() { 57 | return lastName; 58 | } 59 | 60 | public String getEmail() { 61 | return email; 62 | } 63 | 64 | public Sex getSex() { 65 | return sex; 66 | } 67 | 68 | public String getTelephoneNumber() { 69 | return telephoneNumber; 70 | } 71 | 72 | public DateTime getDateOfBirth() { 73 | return dateOfBirth; 74 | } 75 | 76 | public Integer getAge() { 77 | return age; 78 | } 79 | 80 | public String getCompanyEmail() { 81 | return companyEmail; 82 | } 83 | 84 | public String getNationalIdentityCardNumber() { 85 | return nationalIdentityCardNumber; 86 | } 87 | 88 | public String getNationalIdentificationNumber() { 89 | return nationalIdentificationNumber; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /spring-boot-swagger/src/main/java/com/tuturself/spring/boot/service/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.service; 2 | 3 | import java.util.HashMap; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.stream.Collectors; 7 | 8 | import javax.annotation.PostConstruct; 9 | 10 | import org.jfairy.Fairy; 11 | import org.springframework.stereotype.Service; 12 | 13 | import com.tuturself.spring.boot.model.Student; 14 | 15 | @Service 16 | public class StudentService { 17 | 18 | private static Map studentDB; 19 | private Fairy fairy = Fairy.create(); 20 | 21 | @PostConstruct 22 | public void init() throws Exception { 23 | studentDB = new HashMap<>(); 24 | for (int i = 0; i < 100; i++) { 25 | Student student = new Student(i, fairy.person()); 26 | studentDB.put(new Integer(i), student); 27 | } 28 | } 29 | 30 | public Student getStudentById(Integer studentId) { 31 | return studentDB.get(studentId); 32 | } 33 | 34 | public List filterByAge(Integer age) { 35 | List studentList = studentDB.entrySet().stream().filter(e -> e.getValue().getAge() > age) 36 | .map(Map.Entry::getValue).collect(Collectors.toList()); 37 | return studentList; 38 | } 39 | 40 | public List filterByCity(String cityName) { 41 | List studentList = studentDB.entrySet().stream() 42 | .filter(e -> e.getValue().getAddress().getCity().equals(cityName)).map(Map.Entry::getValue) 43 | .collect(Collectors.toList()); 44 | return studentList; 45 | } 46 | 47 | public List filterByAgeAndCity(Integer age, String cityName) { 48 | List studentList = studentDB.entrySet().stream() 49 | .filter(e -> e.getValue().getAddress().getCity().equals(cityName) && e.getValue().getAge() > age) 50 | .map(Map.Entry::getValue).collect(Collectors.toList()); 51 | return studentList; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-boot-swagger/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | org.springframework.web: ERROR 4 | com.tuturself: DEBUG 5 | pattern: 6 | console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" 7 | file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" 8 | file: ./logs/application.log -------------------------------------------------------------------------------- /spring-boot-web/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.tuturself 6 | spring-boot-web 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | 11 | org.springframework.boot 12 | spring-boot-starter-parent 13 | 1.5.1.RELEASE 14 | 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-test 24 | test 25 | 26 | 27 | com.jayway.jsonpath 28 | json-path 29 | test 30 | 31 | 32 | 33 | 34 | 1.8 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | 49 | spring-releases 50 | https://repo.spring.io/libs-release 51 | 52 | 53 | 54 | 55 | spring-releases 56 | https://repo.spring.io/libs-release 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /spring-boot-web/src/main/java/com/tuturself/springboot/web/SpringBootWebApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springboot.web; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | 7 | import com.tuturself.springboot.web.service.PersonService; 8 | 9 | @SpringBootApplication 10 | public class SpringBootWebApplication { 11 | 12 | public static void main(String[] args) throws Exception { 13 | SpringApplication.run(SpringBootWebApplication.class, args); 14 | } 15 | 16 | /** 17 | * Defining the bean {@link PersonService} 18 | * 19 | * @return {@link PersonService} 20 | */ 21 | @Bean 22 | public PersonService personService() { 23 | return new PersonService(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-boot-web/src/main/java/com/tuturself/springboot/web/configuration/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springboot.web.configuration; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 7 | 8 | import com.tuturself.springboot.web.interceptor.RequestInterceptor; 9 | 10 | @Configuration 11 | public class AppConfig extends WebMvcConfigurerAdapter { 12 | 13 | @Autowired 14 | RequestInterceptor requestInterceptor; 15 | 16 | @Override 17 | public void addInterceptors(InterceptorRegistry registry) { 18 | registry.addInterceptor(requestInterceptor); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-web/src/main/java/com/tuturself/springboot/web/controller/PersonAPI.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springboot.web.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.tuturself.springboot.web.model.Person; 9 | import com.tuturself.springboot.web.service.PersonService; 10 | 11 | @RestController 12 | @RequestMapping("/search") 13 | public class PersonAPI { 14 | 15 | @Autowired 16 | private PersonService personService; 17 | 18 | @RequestMapping("/person") 19 | public Person searchStudent(@RequestParam(name = "personId", required = true) 20 | Integer personId) { 21 | Person person = personService.getPersonById(personId); 22 | return person; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot-web/src/main/java/com/tuturself/springboot/web/interceptor/RequestInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springboot.web.interceptor; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.bind.ServletRequestUtils; 8 | import org.springframework.web.servlet.ModelAndView; 9 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 10 | 11 | @Component 12 | public class RequestInterceptor extends HandlerInterceptorAdapter { 13 | 14 | /** 15 | * This is not a good practice to use sysout. Always integrate any logger 16 | * with your application. We will discuss about integrating logger with 17 | * spring boot application in some later article 18 | */ 19 | @Override 20 | public boolean preHandle(HttpServletRequest request, 21 | HttpServletResponse response, Object object) throws Exception { 22 | System.out.println("In preHandle we are Intercepting the Request"); 23 | System.out.println("____________________________________________"); 24 | String requestURI = request.getRequestURI(); 25 | Integer personId = ServletRequestUtils.getIntParameter(request, "personId", 0); 26 | System.out.println("RequestURI::" + requestURI + 27 | " || Search for Person with personId ::" + personId); 28 | System.out.println("____________________________________________"); 29 | return true; 30 | } 31 | 32 | @Override 33 | public void postHandle(HttpServletRequest request, HttpServletResponse response, 34 | Object object, ModelAndView model) 35 | throws Exception { 36 | System.out.println("_________________________________________"); 37 | System.out.println("In postHandle request processing " 38 | + "completed by @RestController"); 39 | System.out.println("_________________________________________"); 40 | } 41 | 42 | @Override 43 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, 44 | Object object, Exception arg3) 45 | throws Exception { 46 | System.out.println("________________________________________"); 47 | System.out.println("In afterCompletion Request Completed"); 48 | System.out.println("________________________________________"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-boot-web/src/main/java/com/tuturself/springboot/web/model/Person.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springboot.web.model; 2 | 3 | public class Person { 4 | 5 | private Integer personId; 6 | private String name; 7 | private Long ssn; 8 | 9 | public Person(Integer personId, String name, Long ssn) { 10 | super(); 11 | this.personId = personId; 12 | this.name = name; 13 | this.ssn = ssn; 14 | } 15 | 16 | public Integer getPersonId() { 17 | return personId; 18 | } 19 | 20 | public void setPersonId(Integer personId) { 21 | this.personId = personId; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public Long getSsn() { 33 | return ssn; 34 | } 35 | 36 | public void setSsn(Long ssn) { 37 | this.ssn = ssn; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-boot-web/src/main/java/com/tuturself/springboot/web/service/PersonService.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springboot.web.service; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import com.tuturself.springboot.web.model.Person; 9 | 10 | public class PersonService { 11 | 12 | private static Map personDB; 13 | 14 | @PostConstruct 15 | public void init() throws Exception { 16 | personDB = new HashMap<>(); 17 | for (int i = 0; i < 100; i++) { 18 | Person person = new Person(i, "Person-name-" + i, System.currentTimeMillis()); 19 | personDB.put(new Integer(i), person); 20 | } 21 | } 22 | 23 | public Person getPersonById(Integer id) { 24 | return personDB.get(id); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot-web/src/test/java/com/tuturself/springboot/web/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springboot.web; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring-boot-websocket/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninja-panda/spring-boot-example/00b41debaddaa0ece2ae606c7c9d0f39c2a2f40e/spring-boot-websocket/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-websocket/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /spring-boot-websocket/mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Migwn, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 204 | echo $MAVEN_PROJECTBASEDIR 205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 206 | 207 | # For Cygwin, switch paths to Windows format before running java 208 | if $cygwin; then 209 | [ -n "$M2_HOME" ] && 210 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 211 | [ -n "$JAVA_HOME" ] && 212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 213 | [ -n "$CLASSPATH" ] && 214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 215 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 217 | fi 218 | 219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 220 | 221 | exec "$JAVACMD" \ 222 | $MAVEN_OPTS \ 223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 226 | -------------------------------------------------------------------------------- /spring-boot-websocket/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 84 | @REM Fallback to current working directory if not found. 85 | 86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 88 | 89 | set EXEC_DIR=%CD% 90 | set WDIR=%EXEC_DIR% 91 | :findBaseDir 92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 93 | cd .. 94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 95 | set WDIR=%CD% 96 | goto findBaseDir 97 | 98 | :baseDirFound 99 | set MAVEN_PROJECTBASEDIR=%WDIR% 100 | cd "%EXEC_DIR%" 101 | goto endDetectBaseDir 102 | 103 | :baseDirNotFound 104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 105 | cd "%EXEC_DIR%" 106 | 107 | :endDetectBaseDir 108 | 109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 110 | 111 | @setlocal EnableExtensions EnableDelayedExpansion 112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 114 | 115 | :endReadAdditionalConfig 116 | 117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 118 | 119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 121 | 122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 123 | if ERRORLEVEL 1 goto error 124 | goto end 125 | 126 | :error 127 | set ERROR_CODE=1 128 | 129 | :end 130 | @endlocal & set ERROR_CODE=%ERROR_CODE% 131 | 132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 136 | :skipRcPost 137 | 138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 140 | 141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 142 | 143 | exit /B %ERROR_CODE% 144 | -------------------------------------------------------------------------------- /spring-boot-websocket/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.tuturself 7 | spring-boot-websocket 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | spring-boot-websocket 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-websocket 35 | 36 | 37 | com.google.code.gson 38 | gson 39 | 40 | 41 | 42 | org.projectlombok 43 | lombok 44 | true 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-maven-plugin 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /spring-boot-websocket/src/main/java/com/tuturself/springbootwebsocket/SpringBootWebsocketApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springbootwebsocket; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootWebsocketApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootWebsocketApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-websocket/src/main/java/com/tuturself/springbootwebsocket/TomcatEmbeded.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springbootwebsocket; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.catalina.Context; 5 | import org.apache.catalina.connector.Connector; 6 | import org.apache.tomcat.util.descriptor.web.SecurityCollection; 7 | import org.apache.tomcat.util.descriptor.web.SecurityConstraint; 8 | import org.apache.tomcat.websocket.server.WsSci; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer; 11 | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.web.SpringServletContainerInitializer; 15 | 16 | @Slf4j 17 | @Configuration 18 | public class TomcatEmbeded extends SpringServletContainerInitializer { 19 | 20 | @Value("${server.port}") 21 | private Integer httpsPort; 22 | 23 | @Value("${server.http-port}") 24 | private Integer httpPort; 25 | 26 | 27 | @Bean 28 | public TomcatServletWebServerFactory servletContainer() { 29 | TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() { 30 | protected void postProcessContext(Context context) { 31 | SecurityConstraint securityConstraint = new SecurityConstraint(); 32 | securityConstraint.setUserConstraint("CONFIDENTIAL"); 33 | SecurityCollection collection = new SecurityCollection(); 34 | collection.addPattern("/*"); 35 | securityConstraint.addCollection(collection); 36 | context.addConstraint(securityConstraint); 37 | } 38 | }; 39 | tomcat.addAdditionalTomcatConnectors(initiateHttpConnector()); 40 | return tomcat; 41 | } 42 | 43 | private Connector initiateHttpConnector() { 44 | Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); 45 | connector.setScheme("http"); 46 | connector.setPort(httpPort); 47 | connector.setSecure(false); 48 | connector.setRedirectPort(httpsPort); 49 | return connector; 50 | } 51 | 52 | 53 | @Bean 54 | public TomcatContextCustomizer tomcatContextCustomizer() { 55 | log.info("TOMCATCONTEXTCUSTOMIZER INITILIZED"); 56 | return new TomcatContextCustomizer() { 57 | 58 | @Override 59 | public void customize(Context context) { 60 | // TODO Auto-generated method stub 61 | context.addServletContainerInitializer(new WsSci(), null); 62 | } 63 | }; 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /spring-boot-websocket/src/main/java/com/tuturself/springbootwebsocket/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springbootwebsocket; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.converter.MessageConverter; 5 | import org.springframework.messaging.simp.config.ChannelRegistration; 6 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 7 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 8 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 9 | import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; 10 | 11 | import java.util.List; 12 | 13 | @Configuration 14 | @EnableWebSocketMessageBroker 15 | public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { 16 | 17 | /** 18 | * Message broker to carry the messages back to the client on destinations prefixed with 19 | * "/topic" and "/queue". "/app" prefix for messages that are bound for @MessageMapping-annotated 20 | * methods in controller class. This prefix will be used to define all the message mappings; for 21 | * example, "/app/message" is the endpoint that the WebSocketController.processMessageFromClient() 22 | * method is mapped to handle 23 | * 24 | * @param config 25 | */ 26 | @Override 27 | public void configureMessageBroker(MessageBrokerRegistry config) { 28 | config.enableSimpleBroker("/topic/", "/queue/"); 29 | config.setApplicationDestinationPrefixes("/app"); 30 | } 31 | 32 | @Override 33 | public void registerStompEndpoints(StompEndpointRegistry registry) { 34 | registry.addEndpoint("/greeting").setAllowedOrigins("*"); 35 | } 36 | 37 | @Override 38 | public void configureClientInboundChannel(ChannelRegistration channelRegistration) { 39 | } 40 | 41 | @Override 42 | public void configureClientOutboundChannel(ChannelRegistration channelRegistration) { 43 | } 44 | 45 | @Override 46 | public boolean configureMessageConverters(List arg0) { 47 | return true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-websocket/src/main/java/com/tuturself/springbootwebsocket/WebSocketEndpoint.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springbootwebsocket; 2 | 3 | import com.google.gson.Gson; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.messaging.handler.annotation.MessageExceptionHandler; 6 | import org.springframework.messaging.handler.annotation.MessageMapping; 7 | import org.springframework.messaging.handler.annotation.Payload; 8 | import org.springframework.messaging.simp.annotation.SendToUser; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.Map; 12 | 13 | @Slf4j 14 | @RestController 15 | public class WebSocketEndpoint { 16 | 17 | 18 | @MessageMapping("/message") 19 | @SendToUser("/queue/reply") 20 | public String processMessageFromClient(@Payload String message) throws Exception { 21 | String name = new Gson().fromJson(message, Map.class).get("name").toString(); 22 | log.info("Message received from client :" + name); 23 | return name; 24 | } 25 | 26 | @MessageExceptionHandler 27 | @SendToUser("/queue/errors") 28 | public String handleException(Throwable exception) { 29 | return exception.getMessage(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-websocket/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: spring-boot-websocket 4 | 5 | #### SSL Configurations STARTS Here #### 6 | server: 7 | port: 8443 8 | http-port: 8099 9 | ssl: 10 | key-store: classpath:keystore.p12 11 | key-store-password: test@123 12 | keyStoreType: PKCS12 13 | keyAlias: https-integration 14 | #### SSL Configurations ENDS Here #### 15 | 16 | logging: 17 | level: 18 | org.springframework: INFO 19 | com.qualys: INFO 20 | pattern: 21 | console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" 22 | file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" 23 | file: /tmp/logs/spring-boot-websocket.log -------------------------------------------------------------------------------- /spring-boot-websocket/src/main/resources/keystore.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ninja-panda/spring-boot-example/00b41debaddaa0ece2ae606c7c9d0f39c2a2f40e/spring-boot-websocket/src/main/resources/keystore.p12 -------------------------------------------------------------------------------- /spring-boot-websocket/src/test/java/com/tuturself/springbootwebsocket/SpringBootWebsocketApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springbootwebsocket; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringBootWebsocketApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-websocket/src/test/java/com/tuturself/springbootwebsocket/Test1.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.springbootwebsocket; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Test1 { 7 | 8 | public static void main(String[] args) { 9 | 10 | int[] arr = {4, 3, 6, 2, 1, 1}; 11 | printTwiceAndMissingNumber(arr); 12 | 13 | int[] arr1 = {1, 3, 8, 3, 7, 4, 5, 2, 2, 5, 3, 9, 7}; 14 | printFirstRepetitiveNumber(arr1); 15 | } 16 | 17 | /** 18 | * In an array of all positive numbers one number is 19 | * missing and one number occurs twice 20 | * 21 | * @param arr 22 | */ 23 | public static void printTwiceAndMissingNumber(int[] arr) { 24 | Map aMap = new HashMap<>(); 25 | int max = 0; 26 | int min = Integer.MAX_VALUE; 27 | for (int i : arr) { 28 | if (i > max) { 29 | max = i; 30 | } 31 | if (min > i) { 32 | min = i; 33 | } 34 | if (aMap.get(i) == null) { 35 | aMap.put(i, true); 36 | } else { 37 | System.out.println(i + " occurs twice"); 38 | } 39 | } 40 | for (int i = min; i <= max; i++) { 41 | if (aMap.get(i) == null) { 42 | System.out.println(i + " is missing"); 43 | } 44 | } 45 | } 46 | 47 | public static void printFirstRepetitiveNumber(int[] arr) { 48 | Map aMap = new HashMap<>(); 49 | for (int i = 0; i < arr.length; i++) { 50 | Integer index = aMap.get(arr[i]); 51 | if (index == null) { 52 | aMap.put(arr[i], (i + 1)); 53 | } else if (index > 0) { 54 | aMap.put(arr[i], (index * -1)); 55 | } 56 | } 57 | int min = Integer.MIN_VALUE; 58 | int firstRepeat = 0; 59 | for(Map.Entry entry : aMap.entrySet()){ 60 | if(entry.getValue() < 0){ 61 | if(entry.getValue() > min){ 62 | min = entry.getValue(); 63 | firstRepeat = entry.getKey(); 64 | } 65 | } 66 | } 67 | System.out.println(firstRepeat); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /spring.boot.filter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | com.tuturself 8 | spring.boot.filter 9 | 0.0.1-SNAPSHOT 10 | spring.boot.filter 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 1.5.1.RELEASE 16 | 17 | 18 | 19 | 1.8 20 | UTF-8 21 | 1.5.1.RELEASE 22 | 4.12 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-web 30 | ${spring-boot.version} 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-actuator 36 | ${spring-boot.version} 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-maven-plugin 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /spring.boot.filter/src/main/java/com/tuturself/spring/boot/filter/HeaderMapRequestWrapper.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.filter; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletRequestWrapper; 5 | import java.util.*; 6 | 7 | 8 | public class HeaderMapRequestWrapper extends HttpServletRequestWrapper { 9 | /** 10 | * construct a wrapper for this request 11 | * 12 | * @param request 13 | */ 14 | public HeaderMapRequestWrapper(HttpServletRequest request) { 15 | super(request); 16 | } 17 | 18 | private Map headerMap = new HashMap(); 19 | 20 | /** 21 | * add a header with given name and value 22 | * 23 | * @param name 24 | * @param value 25 | */ 26 | public void addHeader(String name, String value) { 27 | headerMap.put(name, value); 28 | } 29 | 30 | @Override 31 | public String getHeader(String name) { 32 | String headerValue = super.getHeader(name); 33 | if (headerMap.containsKey(name)) { 34 | headerValue = headerMap.get(name); 35 | } 36 | return headerValue; 37 | } 38 | 39 | /** 40 | * get the Header names 41 | */ 42 | @Override 43 | public Enumeration getHeaderNames() { 44 | List names = Collections.list(super.getHeaderNames()); 45 | for (String name : headerMap.keySet()) { 46 | names.add(name); 47 | } 48 | return Collections.enumeration(names); 49 | } 50 | 51 | @Override 52 | public Enumeration getHeaders(String name) { 53 | List values = Collections.list(super.getHeaders(name)); 54 | if (headerMap.containsKey(name)) { 55 | values.add(headerMap.get(name)); 56 | } 57 | return Collections.enumeration(values); 58 | } 59 | } -------------------------------------------------------------------------------- /spring.boot.filter/src/main/java/com/tuturself/spring/boot/filter/SpringFilterApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @SpringBootApplication 9 | public class SpringFilterApplication { 10 | 11 | private final static Logger logger = LoggerFactory.getLogger(SpringFilterApplication.class); 12 | 13 | public static void main(String[] args) throws Exception { 14 | logger.debug("SpringFilterApplication is STARTing..."); 15 | SpringApplication.run(SpringFilterApplication.class, args); 16 | } 17 | } -------------------------------------------------------------------------------- /spring.boot.filter/src/main/java/com/tuturself/spring/boot/filter/WebApi.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.http.HttpStatus; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.RequestHeader; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | @RequestMapping("/test") 14 | public class WebApi { 15 | 16 | private static final Logger logger = LoggerFactory.getLogger(WebApi.class); 17 | 18 | @RequestMapping(method = RequestMethod.GET) 19 | public ResponseEntity doSomething(@RequestHeader(name = "remote_addr") String remoteAddress) { 20 | logger.debug("The Remote address added by WebFiler is :: {}", remoteAddress); 21 | ResponseEntity response = null; 22 | try { 23 | response = new ResponseEntity("SUCCESS", HttpStatus.OK); 24 | } catch (Exception ex) { 25 | logger.error(ex.getMessage(), ex); 26 | return new ResponseEntity(ex.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); 27 | } 28 | return response; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring.boot.filter/src/main/java/com/tuturself/spring/boot/filter/WebFilter.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.filter; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.core.Ordered; 7 | import org.springframework.core.annotation.Order; 8 | 9 | import javax.servlet.*; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | 14 | @Configuration 15 | @Order(Ordered.HIGHEST_PRECEDENCE) 16 | public class WebFilter implements Filter { 17 | 18 | private static final Logger logger = LoggerFactory.getLogger(WebFilter.class); 19 | 20 | private static final boolean CONDITION = true; 21 | 22 | @Override 23 | public void init(FilterConfig filterConfig) throws ServletException { 24 | logger.debug("Initiating WebFilter >> "); 25 | } 26 | 27 | @Override 28 | public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, 29 | ServletException { 30 | if (CONDITION == true) { 31 | HttpServletRequest req = (HttpServletRequest) request; 32 | HeaderMapRequestWrapper requestWrapper = new HeaderMapRequestWrapper(req); 33 | String remote_addr = request.getRemoteAddr(); 34 | requestWrapper.addHeader("remote_addr", remote_addr); 35 | chain.doFilter(requestWrapper, response); // Goes to default servlet. 36 | } 37 | else { 38 | ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_BAD_REQUEST); 39 | } 40 | } 41 | 42 | @Override 43 | public void destroy() { 44 | logger.debug("Destroying WebFilter >> "); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring.boot.filter/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | org.springframework.web: ERROR 4 | com.tuturself: DEBUG 5 | pattern: 6 | console: "%d{yyyy-MM-dd HH:mm:ss} - %msg%n" 7 | file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" 8 | file: /tmp/application.log -------------------------------------------------------------------------------- /spring.boot.integration.db/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.tuturself 6 | spring.boot.jdbc 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | spring.boot.integration.db 11 | http://maven.apache.org 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.1.RELEASE 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-test 27 | test 28 | 29 | 30 | com.jayway.jsonpath 31 | json-path 32 | test 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-jdbc 39 | 40 | 41 | org.apache.tomcat 42 | tomcat-jdbc 43 | 44 | 45 | 46 | 47 | 48 | 49 | com.zaxxer 50 | HikariCP 51 | 52 | 53 | 54 | 55 | mysql 56 | mysql-connector-java 57 | 58 | 59 | 60 | 61 | 62 | 1.8 63 | UTF-8 64 | 65 | 66 | 67 | 68 | 69 | 70 | org.springframework.boot 71 | spring-boot-maven-plugin 72 | 73 | 74 | 75 | 76 | 77 | 78 | spring-releases 79 | https://repo.spring.io/libs-release 80 | 81 | 82 | 83 | 84 | spring-releases 85 | https://repo.spring.io/libs-release 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /spring.boot.integration.db/src/main/java/com/tuturself/spring/boot/StudentSearchApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | 9 | @SpringBootApplication 10 | public class StudentSearchApplication { 11 | 12 | @Autowired 13 | DataSource dataSource; 14 | 15 | public static void main(String[] args) throws Exception { 16 | SpringApplication.run(StudentSearchApplication.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring.boot.integration.db/src/main/java/com/tuturself/spring/boot/api/StudentAPI.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.api; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.tuturself.spring.boot.model.Student; 10 | import com.tuturself.spring.boot.service.StudentRepository; 11 | 12 | @RestController 13 | public class StudentAPI { 14 | 15 | @Autowired 16 | private StudentRepository studentRepository; 17 | 18 | @RequestMapping("/students") 19 | public List searchStudent() { 20 | List students = studentRepository.findAll(); 21 | return students; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring.boot.integration.db/src/main/java/com/tuturself/spring/boot/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.model; 2 | 3 | public class Student { 4 | 5 | private Integer studentId; 6 | private String firstName; 7 | private String lastName; 8 | private String email; 9 | 10 | public Student(Integer studentId, String firstName, String lastName, String email) { 11 | super(); 12 | this.studentId = studentId; 13 | this.firstName = firstName; 14 | this.lastName = lastName; 15 | this.email = email; 16 | } 17 | 18 | public Integer getStudentId() { 19 | return studentId; 20 | } 21 | 22 | public void setStudentId(Integer studentId) { 23 | this.studentId = studentId; 24 | } 25 | 26 | public String getFirstName() { 27 | return firstName; 28 | } 29 | 30 | public void setFirstName(String firstName) { 31 | this.firstName = firstName; 32 | } 33 | 34 | public String getLastName() { 35 | return lastName; 36 | } 37 | 38 | public void setLastName(String lastName) { 39 | this.lastName = lastName; 40 | } 41 | 42 | public String getEmail() { 43 | return email; 44 | } 45 | 46 | public void setEmail(String email) { 47 | this.email = email; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring.boot.integration.db/src/main/java/com/tuturself/spring/boot/service/StudentRepository.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.jdbc.core.JdbcTemplate; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import com.tuturself.spring.boot.model.Student; 10 | 11 | @Repository 12 | public class StudentRepository { 13 | 14 | @Autowired 15 | private JdbcTemplate jdbcTemplate; 16 | 17 | // Find all students, By Java 8 we can create a custom RowMapper 18 | public List findAll() { 19 | 20 | List result = jdbcTemplate.query("SELECT studentId, firstName,lastName, email FROM student", 21 | (rs, rowNum) -> new Student(rs.getInt("studentId"), rs.getString("firstName"), rs.getString("lastName"), 22 | rs.getString("email"))); 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring.boot.integration.db/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles.active: default 3 | --- 4 | spring: 5 | profiles: default 6 | spring.datasource: 7 | driverClassName: com.mysql.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/myappdb?autoReconnect=true 9 | username: root 10 | password: root 11 | management: 12 | security: 13 | enabled: true 14 | role: ADMIN 15 | --- 16 | spring: 17 | profiles: qa 18 | spring.datasource: 19 | url: jdbc:mysql://qa.myapp.com:3306/myappdb?autoReconnect=true 20 | username: qauser 21 | password: qapassword -------------------------------------------------------------------------------- /spring.boot.integration.db/src/test/java/com/tuturself/spring/boot/integration/db/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.integration.db; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /spring.boot/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.tuturself 6 | spring.boot 7 | 0.0.1-SNAPSHOT 8 | 9 | ../spring.boot.filter 10 | 11 | pom 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.5.1.RELEASE 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-test 27 | test 28 | 29 | 30 | com.jayway.jsonpath 31 | json-path 32 | test 33 | 34 | 35 | org.jfairy 36 | jfairy 37 | 0.3.0 38 | 39 | 40 | 41 | 42 | 1.8 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-maven-plugin 51 | 52 | 53 | 54 | 55 | 56 | 57 | spring-releases 58 | https://repo.spring.io/libs-release 59 | 60 | 61 | 62 | 63 | spring-releases 64 | https://repo.spring.io/libs-release 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /spring.boot/src/main/java/com/tuturself/spring/boot/StudentSearchApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.context.annotation.Bean; 6 | 7 | import com.tuturself.spring.boot.service.StudentService; 8 | 9 | @SpringBootApplication 10 | public class StudentSearchApplication { 11 | 12 | public static void main(String[] args) throws Exception { 13 | SpringApplication.run(StudentSearchApplication.class, args); 14 | } 15 | 16 | /** 17 | * It is generally considered best practice to put exposed beans in 18 | * configuration classes, which are logically grouped. 19 | * 20 | * For example, you might have several configuration classes with a number 21 | * of beans contained within each. Here we create the bean in Main class 22 | * just for simplicity 23 | */ 24 | @Bean 25 | public StudentService studentService() { 26 | return new StudentService(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring.boot/src/main/java/com/tuturself/spring/boot/api/StudentAPI.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.api; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.tuturself.spring.boot.model.Student; 9 | import com.tuturself.spring.boot.service.StudentService; 10 | 11 | @RestController 12 | public class StudentAPI { 13 | 14 | @Autowired 15 | private StudentService studentService; 16 | 17 | @RequestMapping("/students") 18 | public Student searchStudent(@RequestParam(name = "studentId", required = true) Integer studentId) { 19 | Student student = studentService.getStudentById(studentId); 20 | return student; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring.boot/src/main/java/com/tuturself/spring/boot/model/Student.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.model; 2 | 3 | import org.jfairy.producer.person.Address; 4 | import org.jfairy.producer.person.Person; 5 | import org.jfairy.producer.person.Person.Sex; 6 | import org.joda.time.DateTime; 7 | 8 | public class Student { 9 | 10 | private Integer studentId; 11 | private Address address; 12 | private String firstName; 13 | private String middleName; 14 | private String lastName; 15 | private String email; 16 | private Sex sex; 17 | private String telephoneNumber; 18 | private DateTime dateOfBirth; 19 | private Integer age; 20 | private String companyEmail; 21 | private String nationalIdentityCardNumber; 22 | private String nationalIdentificationNumber; 23 | 24 | public Student(int studentId, Person p) { 25 | this.studentId = studentId; 26 | this.nationalIdentityCardNumber = p.nationalIdentificationNumber(); 27 | this.address = p.getAddress(); 28 | this.firstName = p.firstName(); 29 | this.middleName = p.middleName(); 30 | this.lastName = p.lastName(); 31 | this.email = p.email(); 32 | this.sex = p.sex(); 33 | this.telephoneNumber = p.telephoneNumber(); 34 | this.dateOfBirth = p.dateOfBirth(); 35 | this.age = p.age(); 36 | this.nationalIdentificationNumber = p.nationalIdentificationNumber(); 37 | this.companyEmail = p.companyEmail(); 38 | } 39 | 40 | public Integer getStudentId() { 41 | return studentId; 42 | } 43 | 44 | public Address getAddress() { 45 | return address; 46 | } 47 | 48 | public String getFirstName() { 49 | return firstName; 50 | } 51 | 52 | public String getMiddleName() { 53 | return middleName; 54 | } 55 | 56 | public String getLastName() { 57 | return lastName; 58 | } 59 | 60 | public String getEmail() { 61 | return email; 62 | } 63 | 64 | public Sex getSex() { 65 | return sex; 66 | } 67 | 68 | public String getTelephoneNumber() { 69 | return telephoneNumber; 70 | } 71 | 72 | public DateTime getDateOfBirth() { 73 | return dateOfBirth; 74 | } 75 | 76 | public Integer getAge() { 77 | return age; 78 | } 79 | 80 | public String getCompanyEmail() { 81 | return companyEmail; 82 | } 83 | 84 | public String getNationalIdentityCardNumber() { 85 | return nationalIdentityCardNumber; 86 | } 87 | 88 | public String getNationalIdentificationNumber() { 89 | return nationalIdentificationNumber; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /spring.boot/src/main/java/com/tuturself/spring/boot/service/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.service; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.jfairy.Fairy; 9 | import org.springframework.stereotype.Service; 10 | 11 | import com.tuturself.spring.boot.model.Student; 12 | 13 | @Service 14 | public class StudentService { 15 | 16 | private static Map studentDB; 17 | 18 | private Fairy fairy = Fairy.create(); 19 | 20 | @PostConstruct 21 | public void init() throws Exception { 22 | studentDB = new HashMap<>(); 23 | for (int i = 0; i < 100; i++) { 24 | Student student = new Student(i,fairy.person()); 25 | studentDB.put(new Integer(i), student); 26 | } 27 | } 28 | 29 | public Student getStudentById(Integer studentId) { 30 | return studentDB.get(studentId); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring.boot/src/test/java/com/tuturself/spring/boot/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /springboot.cassandra/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | com.tuturself 6 | springboot.cassandra 7 | 0.0.1-SNAPSHOT 8 | springboot-cassandra 9 | http://maven.apache.org 10 | 11 | 12 | 1.8 13 | UTF-8 14 | 3.1.0 15 | 1.16.8 16 | 1.1.7 17 | 4.3.5.RELEASE 18 | 5.1.0 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-parent 24 | 1.5.1.RELEASE 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-test 36 | test 37 | 38 | 39 | com.fasterxml.jackson.core 40 | jackson-databind 41 | 2.8.1 42 | 43 | 44 | 45 | org.springframework 46 | spring-context 47 | ${spring.version} 48 | 49 | 50 | 51 | org.springframework 52 | spring-web 53 | ${spring.version} 54 | 55 | 56 | 57 | org.springframework 58 | spring-core 59 | ${spring.version} 60 | 61 | 62 | 63 | org.springframework 64 | spring-beans 65 | ${spring.version} 66 | 67 | 68 | 69 | 70 | 71 | com.datastax.cassandra 72 | cassandra-driver-core 73 | ${cassandra.driver} 74 | 75 | 76 | com.datastax.cassandra 77 | cassandra-driver-extras 78 | ${cassandra.driver} 79 | 80 | 81 | 82 | info.archinnov 83 | achilles-core 84 | ${achilles.version} 85 | 86 | 87 | 88 | 89 | info.archinnov 90 | achilles-junit 91 | ${achilles.version} 92 | 93 | 94 | slf4j-log4j12 95 | org.slf4j 96 | 97 | 98 | test 99 | 100 | 101 | 102 | ch.qos.logback 103 | logback-classic 104 | ${logback.version} 105 | 106 | 107 | ch.qos.logback 108 | logback-core 109 | ${logback.version} 110 | 111 | 112 | 113 | org.projectlombok 114 | lombok 115 | ${lombok.version} 116 | provided 117 | 118 | 119 | 120 | junit 121 | junit 122 | 3.8.1 123 | test 124 | 125 | 126 | -------------------------------------------------------------------------------- /springboot.cassandra/src/main/java/com/tuturself/spring/boot/cassandra/StudentSearchApplication.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.cassandra; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | 6 | @SpringBootApplication 7 | public class StudentSearchApplication { 8 | 9 | public static void main(String[] args) throws Exception { 10 | new SpringApplicationBuilder(StudentSearchApplication.class).web(true).run(args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot.cassandra/src/main/java/com/tuturself/spring/boot/cassandra/api/StudentSearchAPI.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.cassandra.api; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.http.HttpStatus; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.RequestBody; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.tuturself.spring.boot.cassandra.entity.Student; 13 | import com.tuturself.spring.boot.cassandra.repo.StudentRepository; 14 | 15 | @RestController 16 | public class StudentSearchAPI { 17 | 18 | @Autowired 19 | private StudentRepository studentRepository; 20 | 21 | @RequestMapping("/students/{studentId}") 22 | public Student searchStudent(@PathVariable("studentId") Integer studentId) { 23 | Student student = studentRepository.findById(studentId); 24 | return student; 25 | } 26 | 27 | @RequestMapping(value = "/students/add", method = RequestMethod.POST) 28 | public ResponseEntity addStudent(@RequestBody Student student) { 29 | System.out.println(student); 30 | studentRepository.addStudent(student); 31 | return new ResponseEntity(student, HttpStatus.OK); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot.cassandra/src/main/java/com/tuturself/spring/boot/cassandra/entity/Student.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.cassandra.entity; 2 | 3 | import info.archinnov.achilles.annotations.Column; 4 | import info.archinnov.achilles.annotations.PartitionKey; 5 | import info.archinnov.achilles.annotations.Table; 6 | 7 | @Table(keyspace = "test_cassandra", table = "student") 8 | public class Student { 9 | 10 | @PartitionKey(value = 1) 11 | @Column("student_id") 12 | Integer studentId; 13 | 14 | @Column("name") 15 | String name; 16 | 17 | @Column("department") 18 | String department; 19 | 20 | @Column("phone_no") 21 | String phoneNo; 22 | 23 | public Integer getStudentId() { 24 | return studentId; 25 | } 26 | 27 | public void setStudentId(Integer studentId) { 28 | this.studentId = studentId; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getDepartment() { 40 | return department; 41 | } 42 | 43 | public void setDepartment(String department) { 44 | this.department = department; 45 | } 46 | 47 | public String getPhoneNo() { 48 | return phoneNo; 49 | } 50 | 51 | public void setPhoneNo(String phoneNo) { 52 | this.phoneNo = phoneNo; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /springboot.cassandra/src/main/java/com/tuturself/spring/boot/cassandra/manager/CassandraConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.cassandra.manager; 2 | 3 | import java.net.InetSocketAddress; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | import com.datastax.driver.core.Cluster; 11 | import com.datastax.driver.core.HostDistance; 12 | import com.datastax.driver.core.PlainTextAuthProvider; 13 | import com.datastax.driver.core.PoolingOptions; 14 | import com.google.common.collect.Lists; 15 | 16 | import info.archinnov.achilles.generated.ManagerFactory; 17 | import info.archinnov.achilles.generated.ManagerFactoryBuilder; 18 | 19 | @Configuration 20 | public class CassandraConfiguration { 21 | 22 | @Value("${cassandra.host}") 23 | private String cassandraHost; 24 | 25 | @Value("${cassandra.cluster.name}") 26 | private String clusterName; 27 | 28 | @Value("${cassandra.cluster.pooling.minThread}") 29 | private int minThread; 30 | 31 | @Value("${cassandra.cluster.pooling.maxThread}") 32 | private int maxThread; 33 | 34 | @Value("${cassandra.cluster.pooling.timeout}") 35 | private int timeout; 36 | 37 | @Value("${cassandra.keyspaces.keyspace.name}") 38 | private String keyspace; 39 | 40 | @Value("${cassandra.cluster.user}") 41 | private String userName; 42 | 43 | @Value("${cassandra.cluster.password}") 44 | private String password; 45 | 46 | @Bean(destroyMethod = "shutDown") 47 | public ManagerFactory configureManagerFactory() { 48 | 49 | PoolingOptions poolingOptions = new PoolingOptions(); 50 | poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, maxThread); 51 | poolingOptions.setPoolTimeoutMillis(timeout); 52 | poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, maxThread); 53 | PlainTextAuthProvider authProvider = new PlainTextAuthProvider(userName, password); 54 | Cluster cluster = Cluster.builder().addContactPointsWithPorts(getIpAddressList()) 55 | .withClusterName(clusterName).withAuthProvider(authProvider).withPoolingOptions(poolingOptions).build(); 56 | final ManagerFactory factory = ManagerFactoryBuilder 57 | .builder(cluster).doForceSchemaCreation(true).withDefaultKeyspaceName(keyspace) 58 | .build(); 59 | return factory; 60 | } 61 | 62 | private List getIpAddressList() { 63 | 64 | List cassandraHosts = Lists.newArrayList(); 65 | for (String host : cassandraHost.split(",")) { 66 | InetSocketAddress socketAddress = new InetSocketAddress(host.split(":")[0], 67 | Integer.valueOf(host.split(":")[1])); 68 | cassandraHosts.add(socketAddress); 69 | } 70 | return cassandraHosts; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /springboot.cassandra/src/main/java/com/tuturself/spring/boot/cassandra/manager/ManagerConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.cassandra.manager; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import info.archinnov.achilles.generated.ManagerFactory; 8 | import info.archinnov.achilles.generated.manager.Student_Manager; 9 | 10 | @Configuration 11 | public class ManagerConfiguration { 12 | 13 | @Autowired 14 | private ManagerFactory managerFactory; 15 | 16 | @Bean 17 | public Student_Manager getStudentManager() { 18 | return managerFactory.forStudent(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot.cassandra/src/main/java/com/tuturself/spring/boot/cassandra/repo/StudentRepository.java: -------------------------------------------------------------------------------- 1 | package com.tuturself.spring.boot.cassandra.repo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | 6 | import com.tuturself.spring.boot.cassandra.entity.Student; 7 | 8 | import info.archinnov.achilles.generated.manager.Student_Manager; 9 | 10 | @Service 11 | public class StudentRepository { 12 | 13 | @Autowired 14 | private Student_Manager student_Manager; 15 | 16 | public Student findById(Integer studentId) { 17 | return student_Manager.crud().findById(studentId).get(); 18 | } 19 | 20 | public void addStudent(Student student) { 21 | student_Manager.crud().insert(student).ifNotExists(false).execute(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springboot.cassandra/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: spring-boot-cassandra 4 | cassandra: 5 | host: 127.0.0.1:9042,127.0.0.2:9042,127.0.0.3:9042 6 | cluster: 7 | name: test 8 | user: root 9 | password: root 10 | pooling: 11 | minThread: 5 12 | maxThread: 10 13 | timeout: 5000 14 | keyspaces: 15 | keyspace: 16 | name: test_cassandra 17 | -------------------------------------------------------------------------------- /test: -------------------------------------------------------------------------------- 1 | This is a Test File. 2 | Created to test the file upload process in spring boot 2 using swagger-ui. 3 | Happy Learning in Tutu'rself... --------------------------------------------------------------------------------