Skip to content

Commit 02ddc58

Browse files
authored
Merge pull request #251 from lets-blade/dev
Dev
2 parents 2a0dd9f + 781e30e commit 02ddc58

Some content is hidden

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

48 files changed

+2462
-955
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ If you think this item is good can [star](https://github.com/biezhi/blade/starga
3939
* [x] High performance, 100 concurrent qps 14w/s
4040
* [x] Run the `JAR` package to open the web service
4141
* [x] Streaming API style
42+
* [x] `CSRF` and `XSS` defense
43+
* [x] `Basic Auth` and `Authorization`
4244
* [x] Supports plug-in extensions
4345
* [x] Support webjars resources
4446
* [x] Based on `cron` expression of tasks
@@ -62,7 +64,7 @@ Create a basic `Maven` project
6264
<dependency>
6365
<groupId>com.bladejava</groupId>
6466
<artifactId>blade-mvc</artifactId>
65-
<version>2.0.8-R3</version>
67+
<version>2.0.8.RELEASE</version>
6668
</dependency>
6769
```
6870

@@ -71,7 +73,7 @@ Create a basic `Maven` project
7173
or `Gradle`:
7274

7375
```sh
74-
compile 'com.bladejava:blade-mvc:2.0.8-R3'
76+
compile 'com.bladejava:blade-mvc:2.0.8.RELEASE'
7577
```
7678

7779
Write `main` method, try `Hello World`

README_CN.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
* [x] 模板引擎支持,视图开发更灵活
3838
* [x] 高性能,100并发下qps 14w/s
3939
* [x] 运行 `JAR` 包即可开启 web 服务
40+
* [x] 支持 `CSRF``XSS` 防御
41+
* [x] 支持 `BasicAuth` 和权限管理
4042
* [x] 流式API风格
4143
* [x] 支持插件扩展
4244
* [x] 支持 webjars 资源
@@ -61,7 +63,7 @@
6163
<dependency>
6264
<groupId>com.bladejava</groupId>
6365
<artifactId>blade-mvc</artifactId>
64-
<version>2.0.8-R3</version>
66+
<version>2.0.8.RELEASE</version>
6567
</dependency>
6668
```
6769

@@ -70,7 +72,7 @@
7072
或者 `Gradle`:
7173

7274
```sh
73-
compile 'com.bladejava:blade-mvc:2.0.8-R3'
75+
compile 'com.bladejava:blade-mvc:2.0.8.RELEASE'
7476
```
7577

7678
编写 `main` 函数写一个 `Hello World`

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'eclipse'
44
apply plugin: 'idea'
55

66
group = 'com.bladejava'
7-
version = '2.0.8-R1'
7+
version = '2.0.8-RELEASE'
88

99
description = 'blade-mvc'
1010

@@ -20,7 +20,7 @@ tasks.withType(JavaCompile) {
2020
}
2121

2222
def bladeAsmVersion = '0.0.1'
23-
def bladeLogVersion = '0.1.3'
23+
def bladeLogVersion = '0.1.5'
2424
def junitVersion = '4.12'
2525
def slf4jApiVersion = '1.7.21'
2626
def nettyVersion = '4.1.25.Final'

gradlew.bat

+84-84
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
1-
@if "%DEBUG%" == "" @echo off
2-
@rem ##########################################################################
3-
@rem
4-
@rem Gradle startup script for Windows
5-
@rem
6-
@rem ##########################################################################
7-
8-
@rem Set local scope for the variables with windows NT shell
9-
if "%OS%"=="Windows_NT" setlocal
10-
11-
set DIRNAME=%~dp0
12-
if "%DIRNAME%" == "" set DIRNAME=.
13-
set APP_BASE_NAME=%~n0
14-
set APP_HOME=%DIRNAME%
15-
16-
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS=
18-
19-
@rem Find java.exe
20-
if defined JAVA_HOME goto findJavaFromJavaHome
21-
22-
set JAVA_EXE=java.exe
23-
%JAVA_EXE% -version >NUL 2>&1
24-
if "%ERRORLEVEL%" == "0" goto init
25-
26-
echo.
27-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28-
echo.
29-
echo Please set the JAVA_HOME variable in your environment to match the
30-
echo location of your Java installation.
31-
32-
goto fail
33-
34-
:findJavaFromJavaHome
35-
set JAVA_HOME=%JAVA_HOME:"=%
36-
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37-
38-
if exist "%JAVA_EXE%" goto init
39-
40-
echo.
41-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42-
echo.
43-
echo Please set the JAVA_HOME variable in your environment to match the
44-
echo location of your Java installation.
45-
46-
goto fail
47-
48-
:init
49-
@rem Get command-line arguments, handling Windows variants
50-
51-
if not "%OS%" == "Windows_NT" goto win9xME_args
52-
53-
:win9xME_args
54-
@rem Slurp the command line arguments.
55-
set CMD_LINE_ARGS=
56-
set _SKIP=2
57-
58-
:win9xME_args_slurp
59-
if "x%~1" == "x" goto execute
60-
61-
set CMD_LINE_ARGS=%*
62-
63-
:execute
64-
@rem Setup the command line
65-
66-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67-
68-
@rem Execute Gradle
69-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70-
71-
:end
72-
@rem End local scope for the variables with windows NT shell
73-
if "%ERRORLEVEL%"=="0" goto mainEnd
74-
75-
:fail
76-
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77-
rem the _cmd.exe /c_ return code!
78-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79-
exit /b 1
80-
81-
:mainEnd
82-
if "%OS%"=="Windows_NT" endlocal
83-
84-
:omega
1+
@if "%DEBUG%" == "" @echo off
2+
@rem ##########################################################################
3+
@rem
4+
@rem Gradle startup script for Windows
5+
@rem
6+
@rem ##########################################################################
7+
8+
@rem Set local scope for the variables with windows NT shell
9+
if "%OS%"=="Windows_NT" setlocal
10+
11+
set DIRNAME=%~dp0
12+
if "%DIRNAME%" == "" set DIRNAME=.
13+
set APP_BASE_NAME=%~n0
14+
set APP_HOME=%DIRNAME%
15+
16+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17+
set DEFAULT_JVM_OPTS=
18+
19+
@rem Find java.exe
20+
if defined JAVA_HOME goto findJavaFromJavaHome
21+
22+
set JAVA_EXE=java.exe
23+
%JAVA_EXE% -version >NUL 2>&1
24+
if "%ERRORLEVEL%" == "0" goto init
25+
26+
echo.
27+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28+
echo.
29+
echo Please set the JAVA_HOME variable in your environment to match the
30+
echo location of your Java installation.
31+
32+
goto fail
33+
34+
:findJavaFromJavaHome
35+
set JAVA_HOME=%JAVA_HOME:"=%
36+
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37+
38+
if exist "%JAVA_EXE%" goto init
39+
40+
echo.
41+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42+
echo.
43+
echo Please set the JAVA_HOME variable in your environment to match the
44+
echo location of your Java installation.
45+
46+
goto fail
47+
48+
:init
49+
@rem Get command-line arguments, handling Windows variants
50+
51+
if not "%OS%" == "Windows_NT" goto win9xME_args
52+
53+
:win9xME_args
54+
@rem Slurp the command line arguments.
55+
set CMD_LINE_ARGS=
56+
set _SKIP=2
57+
58+
:win9xME_args_slurp
59+
if "x%~1" == "x" goto execute
60+
61+
set CMD_LINE_ARGS=%*
62+
63+
:execute
64+
@rem Setup the command line
65+
66+
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67+
68+
@rem Execute Gradle
69+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70+
71+
:end
72+
@rem End local scope for the variables with windows NT shell
73+
if "%ERRORLEVEL%"=="0" goto mainEnd
74+
75+
:fail
76+
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77+
rem the _cmd.exe /c_ return code!
78+
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79+
exit /b 1
80+
81+
:mainEnd
82+
if "%OS%"=="Windows_NT" endlocal
83+
84+
:omega

pom.xml

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.bladejava</groupId>
77
<artifactId>blade-mvc</artifactId>
8-
<version>2.0.8-R3</version>
8+
<version>2.0.8.RELEASE</version>
99
<packaging>jar</packaging>
1010

1111
<name>blade</name>
@@ -37,8 +37,8 @@
3737
<junit.version>4.12</junit.version>
3838
<slf4j-api.version>1.7.25</slf4j-api.version>
3939
<netty.version>4.1.25.Final</netty.version>
40-
<blade-asm.version>0.0.1</blade-asm.version>
41-
<blade-log.version>0.1.4</blade-log.version>
40+
<blade-asm.version>0.0.2-SNAPSHOT</blade-asm.version>
41+
<blade-log.version>0.1.5</blade-log.version>
4242
<gson.version>2.8.5</gson.version>
4343
<bootstrap.version>4.1.0</bootstrap.version>
4444
<mockito.version>1.10.19</mockito.version>
@@ -52,7 +52,6 @@
5252
<groupId>org.slf4j</groupId>
5353
<artifactId>slf4j-api</artifactId>
5454
<version>${slf4j-api.version}</version>
55-
<scope>provided</scope>
5655
</dependency>
5756

5857
<dependency>

src/main/java/com/blade/Blade.java

+22-10
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,11 @@ public Blade devMode(boolean devMode) {
417417
return this;
418418
}
419419

420-
public boolean isAutoRefreshDir(){
421-
return environment.get(ENV_KEY_AUTO_REFRESH_DIR).isPresent();
420+
public boolean isAutoRefreshDir() {
421+
return environment.get(ENV_KEY_AUTO_REFRESH_DIR).isPresent();
422422
}
423423

424-
public void setAutoRefreshDir(String dir){
424+
public void setAutoRefreshDir(String dir) {
425425
environment.set(ENV_KEY_AUTO_REFRESH_DIR, dir);
426426
}
427427

@@ -649,7 +649,7 @@ public Blade disableSession() {
649649
return this;
650650
}
651651

652-
public Blade watchEnvChange(boolean watchEnvChange){
652+
public Blade watchEnvChange(boolean watchEnvChange) {
653653
this.environment.set(ENV_KEY_APP_WATCH_ENV, watchEnvChange);
654654
return this;
655655
}
@@ -711,29 +711,29 @@ public Blade start(Class<?> bootClass, @NonNull String address, int port, String
711711
thread.start();
712712
started = true;
713713

714-
Thread resourceFilesRefreshThread = new Thread(()-> {
714+
Thread resourceFilesRefreshThread = new Thread(() -> {
715715

716716
try {
717717
FileChangeDetector fileChangeDetector = new FileChangeDetector(environment.get(ENV_KEY_AUTO_REFRESH_DIR).get());
718-
fileChangeDetector.processEvent( (event , filePath) ->{
718+
fileChangeDetector.processEvent((event, filePath) -> {
719719
try {
720720
//TODO: add support for Create and Delete
721-
if(event.equals(StandardWatchEventKinds.ENTRY_MODIFY)) {
721+
if (event.equals(StandardWatchEventKinds.ENTRY_MODIFY)) {
722722
Path destPath = FileChangeDetector.getDestPath(filePath, environment);
723723
Files.copy(filePath, destPath, StandardCopyOption.REPLACE_EXISTING);
724724
}
725-
}catch (IOException e){
725+
} catch (IOException e) {
726726
log.error("Exception when trying to copy updated file");
727727
startupExceptionHandler.accept(e);
728728
}
729729
});
730-
}catch (IOException e){
730+
} catch (IOException e) {
731731
startupExceptionHandler.accept(e);
732732
}
733733

734734
});
735735

736-
if (devMode() && isAutoRefreshDir()){
736+
if (devMode() && isAutoRefreshDir()) {
737737
log.info("auto refresh is enabled");
738738
resourceFilesRefreshThread.start();
739739
}
@@ -840,6 +840,18 @@ public Blade threadName(String threadName) {
840840
return this;
841841
}
842842

843+
/**
844+
* Set context path, default is "/"
845+
*
846+
* @param contextPath context path
847+
* @return return blade instance
848+
* @since 2.0.8-RELEASE
849+
*/
850+
public Blade contextPath(String contextPath) {
851+
environment.set(ENV_KEY_CONTEXT_PATH, contextPath);
852+
return this;
853+
}
854+
843855
/**
844856
* Get WebSocket Handler
845857
*

src/main/java/com/blade/exception/ValidatorException.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
public class ValidatorException extends RuntimeException {
2727

2828
@Getter
29-
private String code;
29+
private Integer code;
3030

31-
public ValidatorException(String code, String message) {
31+
public ValidatorException(Integer code, String message) {
3232
super(message);
3333
this.code = code;
3434
}

0 commit comments

Comments
 (0)