Commit 75092d1748587ecff8c7d0c5de6696b3a96c62a1
0 parents
Exists in
master
and in
1 other branch
fix: 初次提交
Showing
29 changed files
with
1490 additions
and
0 deletions
Show diff stats
1 | +++ a/.gitignore | |
... | ... | @@ -0,0 +1,33 @@ |
1 | +HELP.md | |
2 | +target/ | |
3 | +!.mvn/wrapper/maven-wrapper.jar | |
4 | +!**/src/main/**/target/ | |
5 | +!**/src/test/**/target/ | |
6 | + | |
7 | +### STS ### | |
8 | +.apt_generated | |
9 | +.classpath | |
10 | +.factorypath | |
11 | +.project | |
12 | +.settings | |
13 | +.springBeans | |
14 | +.sts4-cache | |
15 | + | |
16 | +### IntelliJ IDEA ### | |
17 | +.idea | |
18 | +*.iws | |
19 | +*.iml | |
20 | +*.ipr | |
21 | + | |
22 | +### NetBeans ### | |
23 | +/nbproject/private/ | |
24 | +/nbbuild/ | |
25 | +/dist/ | |
26 | +/nbdist/ | |
27 | +/.nb-gradle/ | |
28 | +build/ | |
29 | +!**/src/main/**/build/ | |
30 | +!**/src/test/**/build/ | |
31 | + | |
32 | +### VS Code ### | |
33 | +.vscode/ | ... | ... |
1 | +++ a/mvnw | |
... | ... | @@ -0,0 +1,322 @@ |
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 | +# https://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 | +# Maven 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*) | |
57 | + darwin=true | |
58 | + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home | |
59 | + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html | |
60 | + if [ -z "$JAVA_HOME" ]; then | |
61 | + if [ -x "/usr/libexec/java_home" ]; then | |
62 | + export JAVA_HOME="$(/usr/libexec/java_home)" | |
63 | + else | |
64 | + export JAVA_HOME="/Library/Java/Home" | |
65 | + fi | |
66 | + fi | |
67 | + ;; | |
68 | +esac | |
69 | + | |
70 | +if [ -z "$JAVA_HOME" ]; then | |
71 | + if [ -r /etc/gentoo-release ]; then | |
72 | + JAVA_HOME=$(java-config --jre-home) | |
73 | + fi | |
74 | +fi | |
75 | + | |
76 | +if [ -z "$M2_HOME" ]; then | |
77 | + ## resolve links - $0 may be a link to maven's home | |
78 | + PRG="$0" | |
79 | + | |
80 | + # need this for relative symlinks | |
81 | + while [ -h "$PRG" ]; do | |
82 | + ls=$(ls -ld "$PRG") | |
83 | + link=$(expr "$ls" : '.*-> \(.*\)$') | |
84 | + if expr "$link" : '/.*' >/dev/null; then | |
85 | + PRG="$link" | |
86 | + else | |
87 | + PRG="$(dirname "$PRG")/$link" | |
88 | + fi | |
89 | + done | |
90 | + | |
91 | + saveddir=$(pwd) | |
92 | + | |
93 | + M2_HOME=$(dirname "$PRG")/.. | |
94 | + | |
95 | + # make it fully qualified | |
96 | + M2_HOME=$(cd "$M2_HOME" && pwd) | |
97 | + | |
98 | + cd "$saveddir" | |
99 | + # echo Using m2 at $M2_HOME | |
100 | +fi | |
101 | + | |
102 | +# For Cygwin, ensure paths are in UNIX format before anything is touched | |
103 | +if $cygwin; then | |
104 | + [ -n "$M2_HOME" ] && | |
105 | + M2_HOME=$(cygpath --unix "$M2_HOME") | |
106 | + [ -n "$JAVA_HOME" ] && | |
107 | + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") | |
108 | + [ -n "$CLASSPATH" ] && | |
109 | + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") | |
110 | +fi | |
111 | + | |
112 | +# For Mingw, ensure paths are in UNIX format before anything is touched | |
113 | +if $mingw; then | |
114 | + [ -n "$M2_HOME" ] && | |
115 | + M2_HOME="$( ( | |
116 | + cd "$M2_HOME" | |
117 | + pwd | |
118 | + ))" | |
119 | + [ -n "$JAVA_HOME" ] && | |
120 | + JAVA_HOME="$( ( | |
121 | + cd "$JAVA_HOME" | |
122 | + pwd | |
123 | + ))" | |
124 | +fi | |
125 | + | |
126 | +if [ -z "$JAVA_HOME" ]; then | |
127 | + javaExecutable="$(which javac)" | |
128 | + if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then | |
129 | + # readlink(1) is not available as standard on Solaris 10. | |
130 | + readLink=$(which readlink) | |
131 | + if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then | |
132 | + if $darwin; then | |
133 | + javaHome="$(dirname \"$javaExecutable\")" | |
134 | + javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" | |
135 | + else | |
136 | + javaExecutable="$(readlink -f \"$javaExecutable\")" | |
137 | + fi | |
138 | + javaHome="$(dirname \"$javaExecutable\")" | |
139 | + javaHome=$(expr "$javaHome" : '\(.*\)/bin') | |
140 | + JAVA_HOME="$javaHome" | |
141 | + export JAVA_HOME | |
142 | + fi | |
143 | + fi | |
144 | +fi | |
145 | + | |
146 | +if [ -z "$JAVACMD" ]; then | |
147 | + if [ -n "$JAVA_HOME" ]; then | |
148 | + if [ -x "$JAVA_HOME/jre/sh/java" ]; then | |
149 | + # IBM's JDK on AIX uses strange locations for the executables | |
150 | + JAVACMD="$JAVA_HOME/jre/sh/java" | |
151 | + else | |
152 | + JAVACMD="$JAVA_HOME/bin/java" | |
153 | + fi | |
154 | + else | |
155 | + JAVACMD="$(which java)" | |
156 | + fi | |
157 | +fi | |
158 | + | |
159 | +if [ ! -x "$JAVACMD" ]; then | |
160 | + echo "Error: JAVA_HOME is not defined correctly." >&2 | |
161 | + echo " We cannot execute $JAVACMD" >&2 | |
162 | + exit 1 | |
163 | +fi | |
164 | + | |
165 | +if [ -z "$JAVA_HOME" ]; then | |
166 | + echo "Warning: JAVA_HOME environment variable is not set." | |
167 | +fi | |
168 | + | |
169 | +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher | |
170 | + | |
171 | +# traverses directory structure from process work directory to filesystem root | |
172 | +# first directory with .mvn subdirectory is considered project base directory | |
173 | +find_maven_basedir() { | |
174 | + | |
175 | + if [ -z "$1" ]; then | |
176 | + echo "Path not specified to find_maven_basedir" | |
177 | + return 1 | |
178 | + fi | |
179 | + | |
180 | + basedir="$1" | |
181 | + wdir="$1" | |
182 | + while [ "$wdir" != '/' ]; do | |
183 | + if [ -d "$wdir"/.mvn ]; then | |
184 | + basedir=$wdir | |
185 | + break | |
186 | + fi | |
187 | + # workaround for JBEAP-8937 (on Solaris 10/Sparc) | |
188 | + if [ -d "${wdir}" ]; then | |
189 | + wdir=$( | |
190 | + cd "$wdir/.." | |
191 | + pwd | |
192 | + ) | |
193 | + fi | |
194 | + # end of workaround | |
195 | + done | |
196 | + echo "${basedir}" | |
197 | +} | |
198 | + | |
199 | +# concatenates all lines of a file | |
200 | +concat_lines() { | |
201 | + if [ -f "$1" ]; then | |
202 | + echo "$(tr -s '\n' ' ' <"$1")" | |
203 | + fi | |
204 | +} | |
205 | + | |
206 | +BASE_DIR=$(find_maven_basedir "$(pwd)") | |
207 | +if [ -z "$BASE_DIR" ]; then | |
208 | + exit 1 | |
209 | +fi | |
210 | + | |
211 | +########################################################################################## | |
212 | +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central | |
213 | +# This allows using the maven wrapper in projects that prohibit checking in binary data. | |
214 | +########################################################################################## | |
215 | +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then | |
216 | + if [ "$MVNW_VERBOSE" = true ]; then | |
217 | + echo "Found .mvn/wrapper/maven-wrapper.jar" | |
218 | + fi | |
219 | +else | |
220 | + if [ "$MVNW_VERBOSE" = true ]; then | |
221 | + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." | |
222 | + fi | |
223 | + if [ -n "$MVNW_REPOURL" ]; then | |
224 | + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |
225 | + else | |
226 | + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |
227 | + fi | |
228 | + while IFS="=" read key value; do | |
229 | + case "$key" in wrapperUrl) | |
230 | + jarUrl="$value" | |
231 | + break | |
232 | + ;; | |
233 | + esac | |
234 | + done <"$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" | |
235 | + if [ "$MVNW_VERBOSE" = true ]; then | |
236 | + echo "Downloading from: $jarUrl" | |
237 | + fi | |
238 | + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" | |
239 | + if $cygwin; then | |
240 | + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") | |
241 | + fi | |
242 | + | |
243 | + if command -v wget >/dev/null; then | |
244 | + if [ "$MVNW_VERBOSE" = true ]; then | |
245 | + echo "Found wget ... using wget" | |
246 | + fi | |
247 | + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then | |
248 | + wget "$jarUrl" -O "$wrapperJarPath" | |
249 | + else | |
250 | + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" | |
251 | + fi | |
252 | + elif command -v curl >/dev/null; then | |
253 | + if [ "$MVNW_VERBOSE" = true ]; then | |
254 | + echo "Found curl ... using curl" | |
255 | + fi | |
256 | + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then | |
257 | + curl -o "$wrapperJarPath" "$jarUrl" -f | |
258 | + else | |
259 | + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f | |
260 | + fi | |
261 | + | |
262 | + else | |
263 | + if [ "$MVNW_VERBOSE" = true ]; then | |
264 | + echo "Falling back to using Java to download" | |
265 | + fi | |
266 | + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" | |
267 | + # For Cygwin, switch paths to Windows format before running javac | |
268 | + if $cygwin; then | |
269 | + javaClass=$(cygpath --path --windows "$javaClass") | |
270 | + fi | |
271 | + if [ -e "$javaClass" ]; then | |
272 | + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then | |
273 | + if [ "$MVNW_VERBOSE" = true ]; then | |
274 | + echo " - Compiling MavenWrapperDownloader.java ..." | |
275 | + fi | |
276 | + # Compiling the Java class | |
277 | + ("$JAVA_HOME/bin/javac" "$javaClass") | |
278 | + fi | |
279 | + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then | |
280 | + # Running the downloader | |
281 | + if [ "$MVNW_VERBOSE" = true ]; then | |
282 | + echo " - Running MavenWrapperDownloader.java ..." | |
283 | + fi | |
284 | + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") | |
285 | + fi | |
286 | + fi | |
287 | + fi | |
288 | +fi | |
289 | +########################################################################################## | |
290 | +# End of extension | |
291 | +########################################################################################## | |
292 | + | |
293 | +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} | |
294 | +if [ "$MVNW_VERBOSE" = true ]; then | |
295 | + echo $MAVEN_PROJECTBASEDIR | |
296 | +fi | |
297 | +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" | |
298 | + | |
299 | +# For Cygwin, switch paths to Windows format before running java | |
300 | +if $cygwin; then | |
301 | + [ -n "$M2_HOME" ] && | |
302 | + M2_HOME=$(cygpath --path --windows "$M2_HOME") | |
303 | + [ -n "$JAVA_HOME" ] && | |
304 | + JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") | |
305 | + [ -n "$CLASSPATH" ] && | |
306 | + CLASSPATH=$(cygpath --path --windows "$CLASSPATH") | |
307 | + [ -n "$MAVEN_PROJECTBASEDIR" ] && | |
308 | + MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") | |
309 | +fi | |
310 | + | |
311 | +# Provide a "standardized" way to retrieve the CLI args that will | |
312 | +# work with both Windows and non-Windows executions. | |
313 | +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" | |
314 | +export MAVEN_CMD_LINE_ARGS | |
315 | + | |
316 | +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain | |
317 | + | |
318 | +exec "$JAVACMD" \ | |
319 | + $MAVEN_OPTS \ | |
320 | + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ | |
321 | + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ | |
322 | + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" | ... | ... |
1 | +++ a/mvnw.cmd | |
... | ... | @@ -0,0 +1,182 @@ |
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 Maven 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 keystroke 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 by 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.5.6/maven-wrapper-0.5.6.jar" | |
124 | + | |
125 | +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( | |
126 | + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B | |
127 | +) | |
128 | + | |
129 | +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central | |
130 | +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. | |
131 | +if exist %WRAPPER_JAR% ( | |
132 | + if "%MVNW_VERBOSE%" == "true" ( | |
133 | + echo Found %WRAPPER_JAR% | |
134 | + ) | |
135 | +) else ( | |
136 | + if not "%MVNW_REPOURL%" == "" ( | |
137 | + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" | |
138 | + ) | |
139 | + if "%MVNW_VERBOSE%" == "true" ( | |
140 | + echo Couldn't find %WRAPPER_JAR%, downloading it ... | |
141 | + echo Downloading from: %DOWNLOAD_URL% | |
142 | + ) | |
143 | + | |
144 | + powershell -Command "&{"^ | |
145 | + "$webclient = new-object System.Net.WebClient;"^ | |
146 | + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ | |
147 | + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ | |
148 | + "}"^ | |
149 | + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ | |
150 | + "}" | |
151 | + if "%MVNW_VERBOSE%" == "true" ( | |
152 | + echo Finished downloading %WRAPPER_JAR% | |
153 | + ) | |
154 | +) | |
155 | +@REM End of extension | |
156 | + | |
157 | +@REM Provide a "standardized" way to retrieve the CLI args that will | |
158 | +@REM work with both Windows and non-Windows executions. | |
159 | +set MAVEN_CMD_LINE_ARGS=%* | |
160 | + | |
161 | +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* | |
162 | +if ERRORLEVEL 1 goto error | |
163 | +goto end | |
164 | + | |
165 | +:error | |
166 | +set ERROR_CODE=1 | |
167 | + | |
168 | +:end | |
169 | +@endlocal & set ERROR_CODE=%ERROR_CODE% | |
170 | + | |
171 | +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost | |
172 | +@REM check for post script, once with legacy .bat ending and once with .cmd ending | |
173 | +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" | |
174 | +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" | |
175 | +:skipRcPost | |
176 | + | |
177 | +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' | |
178 | +if "%MAVEN_BATCH_PAUSE%" == "on" pause | |
179 | + | |
180 | +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% | |
181 | + | |
182 | +exit /B %ERROR_CODE% | ... | ... |
1 | +++ a/pom.xml | |
... | ... | @@ -0,0 +1,103 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
4 | + <modelVersion>4.0.0</modelVersion> | |
5 | + <parent> | |
6 | + <groupId>org.springframework.boot</groupId> | |
7 | + <artifactId>spring-boot-starter-parent</artifactId> | |
8 | + <version>2.2.11.RELEASE</version> | |
9 | + <relativePath/> <!-- lookup parent from repository --> | |
10 | + </parent> | |
11 | + <groupId>com.example</groupId> | |
12 | + <artifactId>demo</artifactId> | |
13 | + <version>0.0.1-SNAPSHOT</version> | |
14 | + <name>mina</name> | |
15 | + <description>Demo project for Spring Boot</description> | |
16 | + <properties> | |
17 | + <java.version>1.8</java.version> | |
18 | + </properties> | |
19 | + <dependencies> | |
20 | + <dependency> | |
21 | + <groupId>org.springframework.boot</groupId> | |
22 | + <artifactId>spring-boot-starter-web</artifactId> | |
23 | + </dependency> | |
24 | + | |
25 | + <dependency> | |
26 | + <groupId>org.springframework.boot</groupId> | |
27 | + <artifactId>spring-boot-devtools</artifactId> | |
28 | + <scope>runtime</scope> | |
29 | + <optional>true</optional> | |
30 | + </dependency> | |
31 | + <dependency> | |
32 | + <groupId>org.projectlombok</groupId> | |
33 | + <artifactId>lombok</artifactId> | |
34 | + <optional>true</optional> | |
35 | + </dependency> | |
36 | + <dependency> | |
37 | + <groupId>org.springframework.boot</groupId> | |
38 | + <artifactId>spring-boot-starter-test</artifactId> | |
39 | + <scope>test</scope> | |
40 | + <exclusions> | |
41 | + <exclusion> | |
42 | + <groupId>org.junit.vintage</groupId> | |
43 | + <artifactId>junit-vintage-engine</artifactId> | |
44 | + </exclusion> | |
45 | + </exclusions> | |
46 | + </dependency> | |
47 | + <!--导入模板引擎才能实现页面跳转--> | |
48 | + <dependency> | |
49 | + <groupId>org.springframework.boot</groupId> | |
50 | + <artifactId>spring-boot-starter-thymeleaf</artifactId> | |
51 | + </dependency> | |
52 | + <!--springbootSecurity--> | |
53 | + <dependency> | |
54 | + <groupId>org.springframework.boot</groupId> | |
55 | + <artifactId>spring-boot-starter-security</artifactId> | |
56 | + </dependency> | |
57 | + | |
58 | + <!--rabbitmq--> | |
59 | + <dependency> | |
60 | + <groupId>org.springframework.boot</groupId> | |
61 | + <artifactId>spring-boot-starter-amqp</artifactId> | |
62 | + </dependency> | |
63 | + | |
64 | + <!--spring-statemachine--> | |
65 | + <dependency> | |
66 | + <groupId>org.springframework.statemachine</groupId> | |
67 | + <artifactId>spring-statemachine-core</artifactId> | |
68 | + <version>1.2.0.RELEASE</version> | |
69 | + </dependency> | |
70 | + | |
71 | + <!--mina--> | |
72 | + <dependency> | |
73 | + <groupId>org.apache.mina</groupId> | |
74 | + <artifactId>mina-core</artifactId> | |
75 | + <version>2.1.3</version> | |
76 | + </dependency> | |
77 | + <dependency> | |
78 | + <groupId>org.apache.mina</groupId> | |
79 | + <artifactId>mina-integration-spring</artifactId> | |
80 | + <version>1.1.7</version> | |
81 | + </dependency> | |
82 | + | |
83 | + | |
84 | + </dependencies> | |
85 | + | |
86 | + <build> | |
87 | + <plugins> | |
88 | + <plugin> | |
89 | + <groupId>org.springframework.boot</groupId> | |
90 | + <artifactId>spring-boot-maven-plugin</artifactId> | |
91 | + <configuration> | |
92 | + <excludes> | |
93 | + <exclude> | |
94 | + <groupId>org.projectlombok</groupId> | |
95 | + <artifactId>lombok</artifactId> | |
96 | + </exclude> | |
97 | + </excludes> | |
98 | + </configuration> | |
99 | + </plugin> | |
100 | + </plugins> | |
101 | + </build> | |
102 | + | |
103 | +</project> | ... | ... |
1 | +++ a/src/main/java/com/example/mina/Application.java | |
... | ... | @@ -0,0 +1,13 @@ |
1 | +package com.example.mina; | |
2 | + | |
3 | +import org.springframework.boot.SpringApplication; | |
4 | +import org.springframework.boot.autoconfigure.SpringBootApplication; | |
5 | + | |
6 | +@SpringBootApplication | |
7 | +public class Application { | |
8 | + | |
9 | + public static void main(String[] args) { | |
10 | + SpringApplication.run(Application.class, args); | |
11 | + } | |
12 | + | |
13 | +} | ... | ... |
1 | +++ a/src/main/java/com/example/mina/config/ConfigMina.java | |
... | ... | @@ -0,0 +1,97 @@ |
1 | +package com.example.mina.config; | |
2 | + | |
3 | +import com.example.mina.mina.code.ByteFactory; | |
4 | +import com.example.mina.mina.server.MinaServerHandler; | |
5 | +import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; | |
6 | +import org.apache.mina.core.service.IoAcceptor; | |
7 | +import org.apache.mina.core.session.IdleStatus; | |
8 | +import org.apache.mina.filter.codec.ProtocolCodecFilter; | |
9 | +import org.apache.mina.filter.executor.ExecutorFilter; | |
10 | +import org.apache.mina.filter.logging.LoggingFilter; | |
11 | +import org.apache.mina.transport.socket.nio.NioSocketAcceptor; | |
12 | +import org.springframework.context.annotation.Bean; | |
13 | +import org.springframework.context.annotation.Configuration; | |
14 | + | |
15 | +import java.io.IOException; | |
16 | +import java.net.InetSocketAddress; | |
17 | + | |
18 | +/** | |
19 | + * @author dy | |
20 | + * @date 2021/3/3 | |
21 | + */ | |
22 | +@Configuration | |
23 | +public class ConfigMina { | |
24 | + | |
25 | + /** | |
26 | + * 配置mina的多线程过滤器 | |
27 | + * | |
28 | + * @return | |
29 | + */ | |
30 | + @Bean | |
31 | + public ExecutorFilter executorFilter() { | |
32 | + //设置初始化线程数,最大线程数 | |
33 | + ExecutorFilter executorFilter = new ExecutorFilter(10, 20); | |
34 | + return executorFilter; | |
35 | + } | |
36 | + | |
37 | + /** | |
38 | + * 配置mina的转码过滤器 | |
39 | + * | |
40 | + * @return | |
41 | + */ | |
42 | + @Bean | |
43 | + public ProtocolCodecFilter protocolCodecFilter() { | |
44 | +// TextLineCodecFactory factory = new TextLineCodecFactory(Charset.forName("UTF-8"), | |
45 | +// LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue()); | |
46 | + | |
47 | + | |
48 | + //TextLineCodecFactory factory = new TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue()); | |
49 | + ProtocolCodecFilter pcf = new ProtocolCodecFilter(new ByteFactory()); | |
50 | + //ProtocolCodecFilter pcf = new ProtocolCodecFilter(factory); | |
51 | + return pcf; | |
52 | + } | |
53 | + | |
54 | + /** | |
55 | + * 配置mina的日志过滤器 | |
56 | + * | |
57 | + * @return | |
58 | + */ | |
59 | + @Bean | |
60 | + public LoggingFilter loggingFilter() { | |
61 | + return new LoggingFilter(); | |
62 | + } | |
63 | + | |
64 | + /** | |
65 | + * 将过滤器注入到mina的链式管理器中 | |
66 | + * | |
67 | + * @return | |
68 | + */ | |
69 | + @Bean | |
70 | + public DefaultIoFilterChainBuilder defaultIoFilterChainBuilder() { | |
71 | + DefaultIoFilterChainBuilder def = new DefaultIoFilterChainBuilder(); | |
72 | + def.addLast("executor", executorFilter()); | |
73 | + def.addLast("logger", loggingFilter()); | |
74 | + def.addLast("protocol", protocolCodecFilter()); | |
75 | + return def; | |
76 | + } | |
77 | + | |
78 | + /** | |
79 | + * 开启mina的server服务,并设置对应的参数 | |
80 | + * | |
81 | + * @return | |
82 | + * @throws IOException | |
83 | + */ | |
84 | + @Bean | |
85 | + public IoAcceptor ioAcceptor() throws IOException { | |
86 | + IoAcceptor nio = new NioSocketAcceptor(); | |
87 | + //设置缓冲区大小 | |
88 | + nio.getSessionConfig().setReadBufferSize(2048); | |
89 | + //设置空闲状态时间,10秒没操作就进入空闲状态 | |
90 | + nio.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10); | |
91 | + nio.setFilterChainBuilder(defaultIoFilterChainBuilder()); | |
92 | + nio.setHandler(new MinaServerHandler()); | |
93 | + nio.bind(new InetSocketAddress(9098)); | |
94 | + return nio; | |
95 | + } | |
96 | + | |
97 | +} | ... | ... |
src/main/java/com/example/mina/config/SecurityConfig.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/config/SecurityConfig.java | |
... | ... | @@ -0,0 +1,27 @@ |
1 | +package com.example.mina.config; | |
2 | + | |
3 | +import org.springframework.context.annotation.Configuration; | |
4 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
5 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | |
6 | + | |
7 | +/** | |
8 | + * @author dy | |
9 | + * @date 2021/2/25 | |
10 | + */ | |
11 | +@Configuration | |
12 | +public class SecurityConfig extends WebSecurityConfigurerAdapter { | |
13 | + | |
14 | + @Override | |
15 | + protected void configure(HttpSecurity http) throws Exception { | |
16 | + // 首页所有人都可以访问,功能也只有对应有权限的人才能访问到 | |
17 | + // 请求授权的规则 | |
18 | + | |
19 | +// http.authorizeRequests() | |
20 | +// .antMatchers("/").permitAll() | |
21 | +// .antMatchers("/level1/**").hasRole("vip1") | |
22 | +// .antMatchers("/level2/**").hasRole("vip2") | |
23 | +// .antMatchers("/level3/**").hasRole("vip3"); | |
24 | + // 开启自动配置的登录功能 | |
25 | + http.formLogin(); | |
26 | + } | |
27 | +} | ... | ... |
src/main/java/com/example/mina/controller/RouterController.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/controller/RouterController.java | |
... | ... | @@ -0,0 +1,41 @@ |
1 | +package com.example.mina.controller; | |
2 | + | |
3 | +import lombok.extern.slf4j.Slf4j; | |
4 | +import org.springframework.stereotype.Controller; | |
5 | +import org.springframework.web.bind.annotation.GetMapping; | |
6 | +import org.springframework.web.bind.annotation.PathVariable; | |
7 | + | |
8 | +/** | |
9 | + * @author dy | |
10 | + * @date 2021/2/22 | |
11 | + */ | |
12 | +@Controller | |
13 | +@Slf4j | |
14 | +public class RouterController { | |
15 | + | |
16 | + @GetMapping({"/", "/index"}) | |
17 | + public String index() { | |
18 | + log.info("是否进入程序"); | |
19 | + return "/index"; | |
20 | + } | |
21 | + | |
22 | + @GetMapping("/toLogin") | |
23 | + public String toLogin() { | |
24 | + return "views/login"; | |
25 | + } | |
26 | + | |
27 | + @GetMapping("/level1/{id}") | |
28 | + public String level1(@PathVariable("id") int id) { | |
29 | + return "views/level1/" + id; | |
30 | + } | |
31 | + | |
32 | + @GetMapping("/level2/{id}") | |
33 | + public String level2(@PathVariable("id") int id) { | |
34 | + return "views/level2/" + id; | |
35 | + } | |
36 | + | |
37 | + @GetMapping("/level3/{id}") | |
38 | + public String level3(@PathVariable("id") int id) { | |
39 | + return "views/level3/" + id; | |
40 | + } | |
41 | +} | ... | ... |
1 | +++ a/src/main/java/com/example/mina/http/HttpSimulator.java | |
... | ... | @@ -0,0 +1,136 @@ |
1 | +package com.example.mina.http; | |
2 | + | |
3 | +import java.io.*; | |
4 | +import java.net.InetSocketAddress; | |
5 | +import java.net.Socket; | |
6 | + | |
7 | +/** | |
8 | + * @author dy | |
9 | + * @date 2021/3/4 | |
10 | + */ | |
11 | +public class HttpSimulator { | |
12 | + | |
13 | + private Socket socket; | |
14 | + | |
15 | + private int port = 80; | |
16 | + | |
17 | + private String host = "localhost"; | |
18 | + | |
19 | + private String request = ""; // HTTP请求消息 | |
20 | + | |
21 | + private boolean isPost, isHead; | |
22 | + | |
23 | + | |
24 | + public void run() throws Exception { | |
25 | + BufferedReader reader = new BufferedReader(new InputStreamReader( | |
26 | + System.in)); | |
27 | + while (true) // 开始大循环 | |
28 | + { | |
29 | + try { | |
30 | + if (!readHostAndPort(reader)) { | |
31 | + break; | |
32 | + } | |
33 | + readHttpRequest(reader); | |
34 | + sendHttpRequest(); | |
35 | + readHttpResponse(reader); | |
36 | + | |
37 | + } catch (Exception e) { | |
38 | + System.out.println("err:" + e.getMessage()); | |
39 | + | |
40 | + } | |
41 | + | |
42 | + } | |
43 | + | |
44 | + } | |
45 | + | |
46 | + | |
47 | + public static void main(String[] args) throws Exception { | |
48 | + new HttpSimulator().run(); | |
49 | + | |
50 | + } | |
51 | + | |
52 | + private boolean readHostAndPort(BufferedReader consoleReader) | |
53 | + throws Exception { | |
54 | + System.out.print("host:port>"); | |
55 | + String[] ss = null; | |
56 | + String s = consoleReader.readLine(); | |
57 | + if (s.equals("q")) { | |
58 | + return false; | |
59 | + } else { | |
60 | + ss = s.split("[:]"); | |
61 | + if (!ss[0].equals("")) { | |
62 | + host = ss[0]; | |
63 | + } | |
64 | + if (ss.length > 1) { | |
65 | + port = Integer.parseInt(ss[1]); | |
66 | + } | |
67 | + System.out.println(host + ":" + String.valueOf(port)); | |
68 | + return true; | |
69 | + } | |
70 | + } | |
71 | + | |
72 | + private void readHttpRequest(BufferedReader consoleReader) | |
73 | + throws Exception { | |
74 | + System.out.println("请输入HTTP请求:"); | |
75 | + String s = consoleReader.readLine(); | |
76 | + request = s + "\r\n"; | |
77 | + boolean isPost = s.substring(0, 4).equals("POST"); | |
78 | + boolean isHead = s.substring(0, 4).equals("HEAD"); | |
79 | + while (!(s = consoleReader.readLine()).equals("")) { | |
80 | + request = request + s + "\r\n"; | |
81 | + } | |
82 | + request = request + "\r\n"; | |
83 | + if (isPost) { | |
84 | + System.out.println("请输入POST方法的内容:"); | |
85 | + s = consoleReader.readLine(); | |
86 | + request = request + s; | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + private void sendHttpRequest() throws Exception { | |
91 | + socket = new Socket(); | |
92 | + socket.setSoTimeout(10 * 1000); | |
93 | + System.out.println("正在连接服务器"); | |
94 | + socket.connect(new InetSocketAddress(host, port), 10 * 1000); | |
95 | + System.out.println("服务器连接成功!"); | |
96 | + OutputStream out = socket.getOutputStream(); | |
97 | + OutputStreamWriter writer = new OutputStreamWriter(out); | |
98 | + writer.write(request); | |
99 | + writer.flush(); | |
100 | + } | |
101 | + | |
102 | + private void readHttpResponse(BufferedReader consoleReader) { | |
103 | + String s = ""; | |
104 | + try { | |
105 | + InputStream in = socket.getInputStream(); | |
106 | + InputStreamReader inReader = new InputStreamReader(in); | |
107 | + BufferedReader socketReader = new BufferedReader(inReader); | |
108 | + System.out.println("---------HTTP头---------"); | |
109 | + boolean b = true; // true: 未读取消息头 false: 已经读取消息头 | |
110 | + while ((s = socketReader.readLine()) != null) { | |
111 | + if (s.equals("") && b == true && !isHead) { | |
112 | + System.out.println("------------------------"); | |
113 | + b = false; | |
114 | + System.out.print("是否显示HTTP的内容(Y/N):"); | |
115 | + String choice = consoleReader.readLine(); | |
116 | + if (choice.equals("Y") || choice.equals("y")) { | |
117 | + System.out.println("---------HTTP内容---------"); | |
118 | + continue; | |
119 | + } else { | |
120 | + break; | |
121 | + } | |
122 | + } else { | |
123 | + System.out.println(s); | |
124 | + } | |
125 | + } | |
126 | + } catch (Exception e) { | |
127 | + System.out.println("err:" + e.getMessage()); | |
128 | + } finally { | |
129 | + try { | |
130 | + socket.close(); | |
131 | + } catch (Exception e) { | |
132 | + } | |
133 | + } | |
134 | + System.out.println("------------------------"); | |
135 | + } | |
136 | +} | ... | ... |
src/main/java/com/example/mina/mina/client/MinaClient.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/mina/client/MinaClient.java | |
... | ... | @@ -0,0 +1,40 @@ |
1 | +package com.example.mina.mina.client; | |
2 | + | |
3 | +import org.apache.mina.core.service.IoConnector; | |
4 | +import org.apache.mina.filter.codec.ProtocolCodecFilter; | |
5 | +import org.apache.mina.filter.codec.textline.LineDelimiter; | |
6 | +import org.apache.mina.filter.codec.textline.TextLineCodecFactory; | |
7 | +import org.apache.mina.transport.socket.nio.NioSocketConnector; | |
8 | + | |
9 | +import java.net.InetSocketAddress; | |
10 | +import java.nio.charset.Charset; | |
11 | + | |
12 | +/** | |
13 | + * @author dy | |
14 | + * @date 2021/3/3 | |
15 | + */ | |
16 | +public class MinaClient { | |
17 | + | |
18 | + public static void main(String[] args) { | |
19 | + //1、创建客户端IoService | |
20 | + IoConnector connector = new NioSocketConnector(); | |
21 | + //客户端链接超时时间 | |
22 | + connector.setConnectTimeoutMillis(30000); | |
23 | + //2、客户端过滤器 | |
24 | + connector.getFilterChain().addLast("test", | |
25 | + new ProtocolCodecFilter( | |
26 | + new TextLineCodecFactory( | |
27 | + Charset.forName("UTF-8"), | |
28 | + LineDelimiter.WINDOWS.getValue(), | |
29 | + LineDelimiter.WINDOWS.getValue() | |
30 | + ) | |
31 | + ) | |
32 | + ); | |
33 | + //3、客户端IoHandler,发生消息 | |
34 | + connector.setHandler(new MinaClientHandler("2")); | |
35 | + //连接服务端 | |
36 | + connector.connect(new InetSocketAddress("localhost", 9098)); | |
37 | + | |
38 | + } | |
39 | + | |
40 | +} | ... | ... |
src/main/java/com/example/mina/mina/client/MinaClientHandler.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/mina/client/MinaClientHandler.java | |
... | ... | @@ -0,0 +1,39 @@ |
1 | +package com.example.mina.mina.client; | |
2 | + | |
3 | +import org.apache.mina.core.service.IoHandlerAdapter; | |
4 | +import org.apache.mina.core.session.IoSession; | |
5 | + | |
6 | +/** | |
7 | + * @author dy | |
8 | + * @date 2021/3/3 | |
9 | + */ | |
10 | +public class MinaClientHandler extends IoHandlerAdapter { | |
11 | + | |
12 | + private final String values; | |
13 | + | |
14 | + public MinaClientHandler(String values) { | |
15 | + this.values = values; | |
16 | + } | |
17 | + | |
18 | + @Override | |
19 | + public void sessionOpened(IoSession session) { | |
20 | + session.write(values); | |
21 | +// //调用IoService的dispose方法关闭线程,这样每次调用client方法发送数据之后就会关闭client | |
22 | +// IoService service = session.getService(); | |
23 | +// service.dispose(); | |
24 | + | |
25 | + } | |
26 | + | |
27 | + /** | |
28 | + * 接收服务器端反馈消息 | |
29 | + * | |
30 | + * @param session | |
31 | + * @param message | |
32 | + * @throws Exception | |
33 | + */ | |
34 | + @Override | |
35 | + public void messageReceived(IoSession session, Object message) throws Exception { | |
36 | + System.out.println("收到服务器响应消息:" + message); | |
37 | + } | |
38 | + | |
39 | +} | ... | ... |
src/main/java/com/example/mina/mina/code/ByteDecoder.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/mina/code/ByteDecoder.java | |
... | ... | @@ -0,0 +1,29 @@ |
1 | +package com.example.mina.mina.code; | |
2 | + | |
3 | +import org.apache.mina.core.buffer.IoBuffer; | |
4 | +import org.apache.mina.core.session.IoSession; | |
5 | +import org.apache.mina.filter.codec.ProtocolDecoder; | |
6 | +import org.apache.mina.filter.codec.ProtocolDecoderAdapter; | |
7 | +import org.apache.mina.filter.codec.ProtocolDecoderOutput; | |
8 | +import org.slf4j.Logger; | |
9 | +import org.slf4j.LoggerFactory; | |
10 | + | |
11 | +/** | |
12 | + * @author dy | |
13 | + * @date 2021/3/3 | |
14 | + */ | |
15 | +public class ByteDecoder extends ProtocolDecoderAdapter { | |
16 | + //打印日志信息 | |
17 | + private final static Logger log = LoggerFactory | |
18 | + .getLogger(ProtocolDecoder.class); | |
19 | + | |
20 | + @Override | |
21 | + public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { | |
22 | + int limit = in.limit(); | |
23 | + byte[] bytes = new byte[limit]; | |
24 | + | |
25 | + in.get(bytes); | |
26 | + | |
27 | + out.write(bytes); | |
28 | + } | |
29 | +} | ... | ... |
src/main/java/com/example/mina/mina/code/ByteEnCoder.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/mina/code/ByteEnCoder.java | |
... | ... | @@ -0,0 +1,37 @@ |
1 | +package com.example.mina.mina.code; | |
2 | + | |
3 | +import org.apache.mina.core.buffer.IoBuffer; | |
4 | +import org.apache.mina.core.session.IoSession; | |
5 | +import org.apache.mina.filter.codec.ProtocolEncoder; | |
6 | +import org.apache.mina.filter.codec.ProtocolEncoderAdapter; | |
7 | +import org.apache.mina.filter.codec.ProtocolEncoderOutput; | |
8 | +import org.slf4j.Logger; | |
9 | +import org.slf4j.LoggerFactory; | |
10 | + | |
11 | +/** | |
12 | + * @author dy | |
13 | + * @date 2021/3/3 | |
14 | + */ | |
15 | +public class ByteEnCoder extends ProtocolEncoderAdapter { | |
16 | + //用于打印日志信息 | |
17 | + private final static Logger log = LoggerFactory | |
18 | + .getLogger(ProtocolEncoder.class); | |
19 | + | |
20 | + //编码 将数据包转成字节数组 | |
21 | + @Override | |
22 | + public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { | |
23 | + byte[] bytes = (byte[]) message; | |
24 | + | |
25 | + IoBuffer buffer = IoBuffer.allocate(256); | |
26 | + buffer.setAutoExpand(true); | |
27 | + | |
28 | + buffer.put(bytes); | |
29 | + buffer.flip(); | |
30 | + | |
31 | + out.write(buffer); | |
32 | + out.flush(); | |
33 | + | |
34 | + buffer.free(); | |
35 | + } | |
36 | + | |
37 | +} | ... | ... |
src/main/java/com/example/mina/mina/code/ByteFactory.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/mina/code/ByteFactory.java | |
... | ... | @@ -0,0 +1,34 @@ |
1 | +package com.example.mina.mina.code; | |
2 | + | |
3 | +import org.apache.mina.core.session.IoSession; | |
4 | +import org.apache.mina.filter.codec.ProtocolCodecFactory; | |
5 | +import org.apache.mina.filter.codec.ProtocolDecoder; | |
6 | +import org.apache.mina.filter.codec.ProtocolEncoder; | |
7 | + | |
8 | +/** | |
9 | + * @author dy | |
10 | + * @date 2021/3/3 | |
11 | + */ | |
12 | +public class ByteFactory implements ProtocolCodecFactory { | |
13 | + private final ByteDecoder decoder; | |
14 | + private final ByteEnCoder encoder; | |
15 | + | |
16 | + //构造 | |
17 | + public ByteFactory() { | |
18 | + encoder = new ByteEnCoder(); | |
19 | + decoder = new ByteDecoder(); | |
20 | + } | |
21 | + | |
22 | + @Override | |
23 | + public ProtocolDecoder getDecoder(IoSession arg0) throws Exception { | |
24 | + // TODO Auto-generated method stub | |
25 | + return decoder; | |
26 | + } | |
27 | + | |
28 | + @Override | |
29 | + public ProtocolEncoder getEncoder(IoSession arg0) throws Exception { | |
30 | + // TODO Auto-generated method stub | |
31 | + return encoder; | |
32 | + } | |
33 | + | |
34 | +} | ... | ... |
src/main/java/com/example/mina/mina/server/MinaServer.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/mina/server/MinaServer.java | |
... | ... | @@ -0,0 +1,92 @@ |
1 | +package com.example.mina.mina.server; | |
2 | + | |
3 | +import com.example.mina.mina.code.ByteFactory; | |
4 | +import org.apache.mina.core.service.IoAcceptor; | |
5 | +import org.apache.mina.core.session.IdleStatus; | |
6 | +import org.apache.mina.filter.codec.ProtocolCodecFilter; | |
7 | +import org.apache.mina.filter.codec.textline.LineDelimiter; | |
8 | +import org.apache.mina.filter.codec.textline.TextLineCodecFactory; | |
9 | +import org.apache.mina.filter.executor.ExecutorFilter; | |
10 | +import org.apache.mina.filter.logging.LogLevel; | |
11 | +import org.apache.mina.filter.logging.LoggingFilter; | |
12 | +import org.apache.mina.transport.socket.nio.NioSocketAcceptor; | |
13 | + | |
14 | +import java.io.IOException; | |
15 | +import java.net.InetSocketAddress; | |
16 | +import java.nio.charset.Charset; | |
17 | + | |
18 | +/** | |
19 | + * @author dy | |
20 | + * @date 2021/3/3 | |
21 | + */ | |
22 | +public class MinaServer { | |
23 | + | |
24 | + public static ExecutorFilter executorFilter() { | |
25 | + //设置初始化线程数,最大线程数 | |
26 | + ExecutorFilter executorFilter = new ExecutorFilter(10, 20); | |
27 | + return executorFilter; | |
28 | + } | |
29 | + | |
30 | + public static LoggingFilter loggingFilter() { | |
31 | + return new LoggingFilter(); | |
32 | + } | |
33 | + | |
34 | + public static ProtocolCodecFilter protocolCodecFilter() { | |
35 | +// TextLineCodecFactory factory = new TextLineCodecFactory(Charset.forName("UTF-8"), | |
36 | +// LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue()); | |
37 | + | |
38 | + | |
39 | + //TextLineCodecFactory factory = new TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue()); | |
40 | + ProtocolCodecFilter pcf = new ProtocolCodecFilter(new ByteFactory()); | |
41 | + //ProtocolCodecFilter pcf = new ProtocolCodecFilter(factory); | |
42 | + return pcf; | |
43 | + } | |
44 | + | |
45 | + public static void main(String[] args) throws IOException { | |
46 | + /*IoAcceptor nio = new NioSocketAcceptor(); | |
47 | + //设置缓冲区大小 | |
48 | + nio.getSessionConfig().setReadBufferSize(2048); | |
49 | + //设置空闲状态时间,10秒没操作就进入空闲状态 | |
50 | + nio.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10); | |
51 | + | |
52 | + DefaultIoFilterChainBuilder def = new DefaultIoFilterChainBuilder(); | |
53 | + def.addLast("executor", executorFilter()); | |
54 | + def.addLast("logger", loggingFilter()); | |
55 | + def.addLast("protocol", protocolCodecFilter()); | |
56 | + | |
57 | + nio.setFilterChainBuilder(def); | |
58 | + nio.setHandler(new MinaServerHandler()); | |
59 | + nio.bind(new InetSocketAddress(9098));*/ | |
60 | + | |
61 | + | |
62 | + | |
63 | + | |
64 | + | |
65 | + //1、创建IoService,拥有监听是否有客户端链接 | |
66 | + IoAcceptor acceptor = new NioSocketAcceptor(); | |
67 | + //设置缓冲区大小 | |
68 | + acceptor.getSessionConfig().setReadBufferSize(2048); | |
69 | + //设置空闲状态时间,10秒没操作就进入空闲状态 | |
70 | + acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10); | |
71 | + | |
72 | + //创建日志过滤器,mina内部使用的是slf4j日志,加入日志之后可以查看mina的运行细节信息 | |
73 | + LoggingFilter log = new LoggingFilter(); | |
74 | + log.setSessionOpenedLogLevel(LogLevel.INFO); | |
75 | + acceptor.getFilterChain().addLast("logger", log); | |
76 | + | |
77 | + //2、实现过滤器 | |
78 | + //acceptor.getFilterChain().addLast("protocol", protocolCodecFilter()); | |
79 | + acceptor.getFilterChain().addLast("protocol", | |
80 | + new ProtocolCodecFilter( | |
81 | + new TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue()) | |
82 | + ) | |
83 | + ); | |
84 | + //3、实现IoHandler,并注册到IoService | |
85 | + acceptor.setHandler(new MinaServerHandler()); | |
86 | + //绑定端口,绑定之前必须设置handler实现类 | |
87 | + acceptor.bind(new InetSocketAddress(9098)); | |
88 | + | |
89 | + | |
90 | + } | |
91 | + | |
92 | +} | ... | ... |
src/main/java/com/example/mina/mina/server/MinaServerHandler.java
0 → 100644
1 | +++ a/src/main/java/com/example/mina/mina/server/MinaServerHandler.java | |
... | ... | @@ -0,0 +1,141 @@ |
1 | +package com.example.mina.mina.server; | |
2 | + | |
3 | +import org.apache.mina.core.service.IoHandlerAdapter; | |
4 | +import org.apache.mina.core.session.IoSession; | |
5 | + | |
6 | +import java.io.ByteArrayOutputStream; | |
7 | +import java.io.ObjectOutputStream; | |
8 | +import java.net.SocketAddress; | |
9 | +import java.nio.charset.Charset; | |
10 | +import java.nio.charset.StandardCharsets; | |
11 | + | |
12 | +/** | |
13 | + * @author dy | |
14 | + * @date 2021/3/3 | |
15 | + */ | |
16 | +public class MinaServerHandler extends IoHandlerAdapter { | |
17 | + | |
18 | + @Override | |
19 | + public void messageReceived(IoSession session, Object message) throws Exception { | |
20 | +// String command = new String(ObjectToByte(message)).trim(); | |
21 | +// | |
22 | +// if (command.startsWith("ATTN ALL MAX")) {//set all to max | |
23 | +// for (int i = 1; i < dataBuffer.getMaxRow(); i++) { | |
24 | +// dataBuffer.setOffset(i, dataBuffer.getMaxAtten()); | |
25 | +// } | |
26 | +// | |
27 | +// return NONE; | |
28 | +// } else if (command.startsWith("ATTN?")) {//get | |
29 | +// String[] sss = command.split(" "); | |
30 | +// if (sss.length >= 2) { | |
31 | +// LogUtils.println(sss[0], sss[1]); | |
32 | +// | |
33 | +// int row = StrUtil.toInt(sss[1]); | |
34 | +// if (row >= 0 && row <= dataBuffer.getMaxRow()) { | |
35 | +// String str = String.valueOf(dataBuffer.getOffset(row)); | |
36 | +// LogUtils.println("AeroflexVirtualBoxService::handleCommand return : ", str); | |
37 | +// return str.getBytes(); | |
38 | +// } | |
39 | +// } | |
40 | +// | |
41 | +// return ERROR; | |
42 | +// } else if (command.startsWith("ATTN")) {//Set, Follow by ATTN? | |
43 | +// LogUtils.println("command.startsWith(\"ATTN\")"); | |
44 | +// String[] aa = command.split(";"); | |
45 | +// | |
46 | +// LogUtils.println(aa[0], aa[1]); | |
47 | +// | |
48 | +// String[] sss = aa[0].split(" "); | |
49 | +// StrUtil.printArray(sss); | |
50 | +// | |
51 | +// if (sss.length >= 3) { | |
52 | +// int row = StrUtil.toInt(sss[1]); | |
53 | +// int val = StrUtil.toInt(sss[2]); | |
54 | +// | |
55 | +// System.out.println(row + "/" + val); | |
56 | +// | |
57 | +// | |
58 | +// if (row >= 0 && row <= dataBuffer.getMaxRow()) { | |
59 | +// if (val >= 0 && val <= dataBuffer.getMaxAtten()) { | |
60 | +// dataBuffer.setOffset(row, val); | |
61 | +// | |
62 | +// String str = String.valueOf(dataBuffer.getOffset(row)); | |
63 | +// LogUtils.println("handleCommand return =====> ", str); | |
64 | +// return str.getBytes(); | |
65 | +// } | |
66 | +// } | |
67 | +// } | |
68 | + | |
69 | + //业务代码在这里编写处理 | |
70 | + String str = new String((byte[])message); | |
71 | + System.out.println("The message received is [" + str + "]"); | |
72 | + //获取客户端的连接地址 | |
73 | + SocketAddress socketAddress = session.getRemoteAddress(); | |
74 | + System.out.println(socketAddress); | |
75 | + String send = "消息已处理,你可以去玩了。。。"; | |
76 | + //响应给对应客户端信息 | |
77 | + session.write(send.getBytes()); | |
78 | + session.closeNow(); | |
79 | +// // 此处关闭session后客户端无法接收到服务器反馈的消息 | |
80 | +// if (str.endsWith("quit")) { | |
81 | +// //注意:在这里调用close方法之后,只是关闭当前的tcp连接,server端还正常运行, | |
82 | +// //需要调用IoService的dispose方法才能关闭server端,client端同理 | |
83 | +// | |
84 | +// return; | |
85 | +// } | |
86 | + } | |
87 | + | |
88 | + @Override | |
89 | + public void sessionCreated(IoSession session) throws Exception { | |
90 | + System.out.println("server session created"); | |
91 | + super.sessionCreated(session); | |
92 | + } | |
93 | + | |
94 | + @Override | |
95 | + public void sessionOpened(IoSession session) throws Exception { | |
96 | + System.out.println("server session Opened"); | |
97 | + super.sessionOpened(session); | |
98 | + } | |
99 | + | |
100 | + @Override | |
101 | + public void sessionClosed(IoSession session) throws Exception { | |
102 | + System.out.println("server session Closed"); | |
103 | + super.sessionClosed(session); | |
104 | + } | |
105 | + | |
106 | + /** | |
107 | + * 在IoHandlerAdapter中有一个messageSent的方法,但是重写这个方法之后,不会发送数据,该方法只有数据发送成功之后才会调用, | |
108 | + * 所以在 messageReceived 方法中使用 session.write("消息已处理,你可以去玩了。。。"); 给客户端响应数据 | |
109 | + * | |
110 | + * @param session | |
111 | + * @param message | |
112 | + * @throws Exception | |
113 | + */ | |
114 | + @Override | |
115 | + public void messageSent(IoSession session, Object message) throws Exception { | |
116 | + // TODO Auto-generated method stub | |
117 | + System.out.println("发送数据成功了。。。" + message); | |
118 | + // session.write("testSent"); | |
119 | + super.messageSent(session, message); | |
120 | + } | |
121 | + | |
122 | + private byte[] ObjectToByte(Object obj) { | |
123 | + byte[] bytes = null; | |
124 | + try { | |
125 | + // object to bytearray | |
126 | + ByteArrayOutputStream bo = new ByteArrayOutputStream(); | |
127 | + ObjectOutputStream oo = new ObjectOutputStream(bo); | |
128 | + oo.writeObject(obj); | |
129 | + | |
130 | + bytes = bo.toByteArray(); | |
131 | + | |
132 | + bo.close(); | |
133 | + oo.close(); | |
134 | + } catch (Exception e) { | |
135 | + System.out.println("translation" + e.getMessage()); | |
136 | + e.printStackTrace(); | |
137 | + } | |
138 | + return bytes; | |
139 | + } | |
140 | + | |
141 | +} | ... | ... |
No preview for this file type
1 | +++ a/src/main/resources/application.yml | |
... | ... | @@ -0,0 +1,13 @@ |
1 | +server: | |
2 | + port: 8080 | |
3 | + servlet: | |
4 | + context-path: /test | |
5 | + | |
6 | +# rabbitmq配置 | |
7 | + #spring: | |
8 | + # rabbitmq: | |
9 | + # host: localhost | |
10 | + # port: 5672 | |
11 | + # username: guest | |
12 | + # password: guest | |
13 | + # virtual-host: / | |
0 | 14 | \ No newline at end of file | ... | ... |