Skip to content

Commit

Permalink
Merge pull request lets-blade#1 from lets-blade/master
Browse files Browse the repository at this point in the history
pull request1
  • Loading branch information
wuma2020 authored Jan 26, 2019
2 parents 6757d03 + 55e516a commit 2a4c96c
Show file tree
Hide file tree
Showing 37 changed files with 815 additions and 345 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If you think it's good, you can support it with a [star](https://github.com/biez
* [x] Source is less than `500kb`, learning it is also simple
* [x] RESTful-style routing design
* [x] Template engine support, view development more flexible
* [x] High performance, 100 concurrent qps 14w/s
* [x] High performance, 100 concurrent qps 20w/s
* [x] Run the `JAR` package to open the web service
* [x] Streams-style API
* [x] `CSRF` and `XSS` defense
Expand Down Expand Up @@ -64,14 +64,14 @@ Run with `Maven`:
<dependency>
<groupId>com.bladejava</groupId>
<artifactId>blade-mvc</artifactId>
<version>2.0.12.BETA</version>
<version>2.0.14.RELEASE</version>
</dependency>
```

or `Gradle`:

```sh
compile 'com.bladejava:blade-mvc:2.0.12.BETA'
compile 'com.bladejava:blade-mvc:2.0.14.RELEASE'
```

Write the `main` method and the `Hello World`:
Expand All @@ -84,7 +84,6 @@ public static void main(String[] args) {

Open http://localhost:9000 in your browser to see your first `Blade` application!


## Contents

- [**`Register Route`**](#register-route)
Expand Down Expand Up @@ -679,9 +678,9 @@ Thanks goes to these wonderful people

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars2.githubusercontent.com/u/3849072?s=460&v=4" width="100px;"/><br /><sub><b>王爵nice</b></sub>](https://twitter.com/biezhii) | [<img src="https://avatars2.githubusercontent.com/u/9401233?s=460&v=4" width="100px;"/><br /><sub><b>ccqy66</b></sub>](https://github.com/ccqy66) | [<img src="https://avatars0.githubusercontent.com/u/9024855?s=460&v=4" width="100px;"/><br /><sub><b>王晓辉(Eddie)</b></sub>](https://github.com/eddie-wang) | [<img src="https://avatars2.githubusercontent.com/u/2503423?s=460&v=4" width="100px;"/><br /><sub><b>代码家</b></sub>](https://github.com/daimajia) | [<img src="https://avatars2.githubusercontent.com/u/9032795?s=460&v=4" width="100px;"/><br /><sub><b>David Dong</b></sub>](https://github.com/dongm2ez) | [<img src="https://avatars1.githubusercontent.com/u/10883521?s=460&v=4" width="100px;"/><br /><sub><b>José Vieira Neto</b></sub>](https://github.com/NetoDevel) | [<img src="https://avatars0.githubusercontent.com/u/59744?s=460&v=4" width="100px;"/><br /><sub><b>Schneeman</b></sub>](https://github.com/schneems) |
| [<img src="https://avatars2.githubusercontent.com/u/3849072?s=460&v=4" width="100px;"/><br /><sub><b>biezhi</b></sub>](https://twitter.com/biezhii) | [<img src="https://avatars2.githubusercontent.com/u/8097340?s=460&v=4" width="100px;"/><br /><sub><b>ydq</b></sub>](https://github.com/ydq) | [<img src="https://avatars2.githubusercontent.com/u/9401233?s=460&v=4" width="100px;"/><br /><sub><b>ccqy66</b></sub>](https://github.com/ccqy66) | [<img src="https://avatars0.githubusercontent.com/u/9024855?s=460&v=4" width="100px;"/><br /><sub><b>王晓辉(Eddie)</b></sub>](https://github.com/eddie-wang) | [<img src="https://avatars2.githubusercontent.com/u/2503423?s=460&v=4" width="100px;"/><br /><sub><b>代码家</b></sub>](https://github.com/daimajia) | [<img src="https://avatars2.githubusercontent.com/u/9032795?s=460&v=4" width="100px;"/><br /><sub><b>David Dong</b></sub>](https://github.com/dongm2ez) | [<img src="https://avatars1.githubusercontent.com/u/10883521?s=460&v=4" width="100px;"/><br /><sub><b>José Vieira Neto</b></sub>](https://github.com/NetoDevel) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars1.githubusercontent.com/u/497803?s=460&v=4" width="100px;"/><br /><sub><b>Mohd Farid</b></sub>](https://github.com/mfarid) | [<img src="https://avatars3.githubusercontent.com/u/1326893?s=460&v=4" width="100px;"/><br /><sub><b>sumory</b></sub>](https://github.com/sumory) | [<img src="https://avatars3.githubusercontent.com/u/463602?s=460&v=4" width="100px;"/><br /><sub><b>Uday K</b></sub>](https://github.com/udaykadaboina) | [<img src="https://avatars0.githubusercontent.com/u/11169857?s=460&v=4" width="100px;"/><br /><sub><b>Antony Kwok</b></sub>](https://github.com/Awakens) | &nbsp; | &nbsp; | &nbsp; |
| [<img src="https://avatars1.githubusercontent.com/u/497803?s=460&v=4" width="100px;"/><br /><sub><b>Mohd Farid</b></sub>](https://github.com/mfarid) | [<img src="https://avatars3.githubusercontent.com/u/1326893?s=460&v=4" width="100px;"/><br /><sub><b>sumory</b></sub>](https://github.com/sumory) | [<img src="https://avatars3.githubusercontent.com/u/463602?s=460&v=4" width="100px;"/><br /><sub><b>Uday K</b></sub>](https://github.com/udaykadaboina) | [<img src="https://avatars0.githubusercontent.com/u/11169857?s=460&v=4" width="100px;"/><br /><sub><b>Antony Kwok</b></sub>](https://github.com/Awakens) | [<img src="https://avatars0.githubusercontent.com/u/59744?s=460&v=4" width="100px;"/><br /><sub><b>Schneeman</b></sub>](https://github.com/schneems) | &nbsp; | &nbsp; |
<!-- ALL-CONTRIBUTORS-LIST:END -->

Contributions of any kind are welcome!
Expand Down
10 changes: 5 additions & 5 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* [x] 源码不到 `500kb`,学习也简单
* [x] Restful风格路由设计
* [x] 模板引擎支持,视图开发更灵活
* [x] 高性能,100并发下qps 14w/s
* [x] 高性能,100 并发下qps 20w/s
* [x] 运行 `JAR` 包即可开启 web 服务
* [x] 支持 `CSRF``XSS` 防御
* [x] 支持 `BasicAuth` 和权限管理
Expand Down Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>com.bladejava</groupId>
<artifactId>blade-mvc</artifactId>
<version>2.0.12.BETA</version>
<version>2.0.14.RELEASE</version>
</dependency>
```

Expand All @@ -70,7 +70,7 @@
或者 `Gradle`:

```sh
compile 'com.bladejava:blade-mvc:2.0.12.BETA'
compile 'com.bladejava:blade-mvc:2.0.14.RELEASE'
```

编写 `main` 函数写一个 `Hello World`
Expand Down Expand Up @@ -675,9 +675,9 @@ public class GolbalExceptionHandler extends DefaultExceptionHandler {

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars2.githubusercontent.com/u/3849072?s=460&v=4" width="100px;"/><br /><sub><b>王爵nice</b></sub>](https://twitter.com/biezhii) | [<img src="https://avatars2.githubusercontent.com/u/9401233?s=460&v=4" width="100px;"/><br /><sub><b>ccqy66</b></sub>](https://github.com/ccqy66) | [<img src="https://avatars0.githubusercontent.com/u/9024855?s=460&v=4" width="100px;"/><br /><sub><b>王晓辉(Eddie)</b></sub>](https://github.com/eddie-wang) | [<img src="https://avatars2.githubusercontent.com/u/2503423?s=460&v=4" width="100px;"/><br /><sub><b>代码家</b></sub>](https://github.com/daimajia) | [<img src="https://avatars2.githubusercontent.com/u/9032795?s=460&v=4" width="100px;"/><br /><sub><b>David Dong</b></sub>](https://github.com/dongm2ez) | [<img src="https://avatars1.githubusercontent.com/u/10883521?s=460&v=4" width="100px;"/><br /><sub><b>José Vieira Neto</b></sub>](https://github.com/NetoDevel) | [<img src="https://avatars0.githubusercontent.com/u/59744?s=460&v=4" width="100px;"/><br /><sub><b>Schneeman</b></sub>](https://github.com/schneems) |
| [<img src="https://avatars2.githubusercontent.com/u/3849072?s=460&v=4" width="100px;"/><br /><sub><b>biezhi</b></sub>](https://twitter.com/biezhii) | [<img src="https://avatars2.githubusercontent.com/u/8097340?s=460&v=4" width="100px;"/><br /><sub><b>ydq</b></sub>](https://github.com/ydq) | [<img src="https://avatars2.githubusercontent.com/u/9401233?s=460&v=4" width="100px;"/><br /><sub><b>ccqy66</b></sub>](https://github.com/ccqy66) | [<img src="https://avatars0.githubusercontent.com/u/9024855?s=460&v=4" width="100px;"/><br /><sub><b>王晓辉(Eddie)</b></sub>](https://github.com/eddie-wang) | [<img src="https://avatars2.githubusercontent.com/u/2503423?s=460&v=4" width="100px;"/><br /><sub><b>代码家</b></sub>](https://github.com/daimajia) | [<img src="https://avatars2.githubusercontent.com/u/9032795?s=460&v=4" width="100px;"/><br /><sub><b>David Dong</b></sub>](https://github.com/dongm2ez) | [<img src="https://avatars1.githubusercontent.com/u/10883521?s=460&v=4" width="100px;"/><br /><sub><b>José Vieira Neto</b></sub>](https://github.com/NetoDevel) |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars1.githubusercontent.com/u/497803?s=460&v=4" width="100px;"/><br /><sub><b>Mohd Farid</b></sub>](https://github.com/mfarid) | [<img src="https://avatars3.githubusercontent.com/u/1326893?s=460&v=4" width="100px;"/><br /><sub><b>sumory</b></sub>](https://github.com/sumory) | [<img src="https://avatars3.githubusercontent.com/u/463602?s=460&v=4" width="100px;"/><br /><sub><b>Uday K</b></sub>](https://github.com/udaykadaboina) | [<img src="https://avatars0.githubusercontent.com/u/11169857?s=460&v=4" width="100px;"/><br /><sub><b>Antony Kwok</b></sub>](https://github.com/Awakens) | &nbsp; | &nbsp; | &nbsp; |
| [<img src="https://avatars1.githubusercontent.com/u/497803?s=460&v=4" width="100px;"/><br /><sub><b>Mohd Farid</b></sub>](https://github.com/mfarid) | [<img src="https://avatars3.githubusercontent.com/u/1326893?s=460&v=4" width="100px;"/><br /><sub><b>sumory</b></sub>](https://github.com/sumory) | [<img src="https://avatars3.githubusercontent.com/u/463602?s=460&v=4" width="100px;"/><br /><sub><b>Uday K</b></sub>](https://github.com/udaykadaboina) | [<img src="https://avatars0.githubusercontent.com/u/11169857?s=460&v=4" width="100px;"/><br /><sub><b>Antony Kwok</b></sub>](https://github.com/Awakens) | [<img src="https://avatars0.githubusercontent.com/u/59744?s=460&v=4" width="100px;"/><br /><sub><b>Schneeman</b></sub>](https://github.com/schneems) | &nbsp; | &nbsp; |
<!-- ALL-CONTRIBUTORS-LIST:END -->

## 开源协议
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'eclipse'
apply plugin: 'idea'

group = 'com.bladejava'
version = '2.0.12.ALPHA'
version = '2.0.14.RELEASE'

description = 'blade-mvc'

Expand Down Expand Up @@ -44,6 +44,8 @@ dependencies {
testCompile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
testCompile group: 'org.webjars', name: 'bootstrap', version: '4.1.0'
testCompile group: 'junit', name: 'junit', version: junitVersion
testCompile group: 'org.projectlombok', name: 'lombok', version: '1.16.22'

compileOnly group: 'junit', name: 'junit', version: junitVersion
compileOnly group: 'io.netty', name: 'netty-transport-native-epoll', version: nettyVersion
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.bladejava</groupId>
<artifactId>blade-mvc</artifactId>
<version>2.0.12.BETA</version>
<version>2.0.14.RELEASE</version>
<packaging>jar</packaging>

<name>blade</name>
Expand Down
44 changes: 9 additions & 35 deletions src/main/java/com/blade/Blade.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public class Blade {
*/
private ExceptionHandler exceptionHandler = new DefaultExceptionHandler();

private CorsMiddleware corsMiddleware;

/**
* Used to identify whether the web server has started
*/
Expand All @@ -171,11 +173,6 @@ public class Blade {
*/
private Class<? extends Session> sessionImplType = HttpSession.class;

/**
* WebSocket path
*/
private String webSocketPath;

/**
* Blade app start banner, default is Const.BANNER
*/
Expand All @@ -186,11 +183,6 @@ public class Blade {
*/
private String threadName;

/**
* WebSocket Handler
*/
private WebSocketHandler webSocketHandler;

/**
* Give your blade instance, from then on will get the energy
*
Expand Down Expand Up @@ -548,11 +540,15 @@ public Blade enableCors(boolean enableCors) {
public Blade enableCors(boolean enableCors, CorsConfiger corsConfig) {
this.environment.set(ENV_KEY_CORS_ENABLE, enableCors);
if (enableCors) {
this.use(new CorsMiddleware(corsConfig));
this.corsMiddleware = new CorsMiddleware(corsConfig);
}
return this;
}

public CorsMiddleware corsMiddleware() {
return corsMiddleware;
}

/**
* Get blade statics list.
* e.g: "/favicon.ico", "/robots.txt", "/static/", "/upload/", "/webjars/"
Expand Down Expand Up @@ -957,24 +953,10 @@ public void stop() {
* @return return blade instance
*/
public Blade webSocket(@NonNull String path, @NonNull WebSocketHandler handler) {
if (null != this.webSocketHandler) {
throw new BladeException(500, "There is already a WebSocket path.");
}
this.webSocketPath = path;
this.webSocketHandler = handler;
this.routeMatcher.addWebSocket(path);
this.routeMatcher.addWebSocket(path,handler);
return this;
}

/**
* Get webSocket path
*
* @return return websocket path
*/
public String webSocketPath() {
return this.webSocketPath;
}

/**
* Set blade start banner text
*
Expand Down Expand Up @@ -1031,15 +1013,6 @@ public Blade contextPath(String contextPath) {
return this;
}

/**
* Get WebSocket Handler
*
* @return return websocket handler
*/
public WebSocketHandler webSocketHandler() {
return this.webSocketHandler;
}

/**
* Load application environment configuration
*
Expand Down Expand Up @@ -1103,4 +1076,5 @@ private void loadConfig(String[] args) {
}

}

}
1 change: 1 addition & 0 deletions src/main/java/com/blade/ioc/annotation/Bean.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

String value() default "";

@Deprecated
boolean singleton() default true;

}
2 changes: 0 additions & 2 deletions src/main/java/com/blade/ioc/annotation/Inject.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@

String value() default "";

boolean singleton() default true;

}
2 changes: 1 addition & 1 deletion src/main/java/com/blade/kit/BladeKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static <T> void notNullThen(T value, Consumer<T> consumer) {
}
}

public static boolean isInJar() {
public static boolean runtimeIsJAR() {
return Const.CLASSPATH.endsWith(".jar");
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/blade/kit/IOKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ public static String readToString(String file) throws IOException {
}

public static String readToString(BufferedReader bufferedReader) {
return bufferedReader.lines().collect(Collectors.joining());
return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}

public static String readToString(Path path) throws IOException {
BufferedReader bufferedReader = Files.newBufferedReader(path);
return bufferedReader.lines().collect(Collectors.joining());
return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}

public static String readToString(InputStream input) throws IOException {
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input, "UTF-8"))) {
return buffer.lines().collect(Collectors.joining("\n"));
return buffer.lines().collect(Collectors.joining(System.lineSeparator()));
}
}

Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/blade/kit/IocKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@

import com.blade.Environment;
import com.blade.ioc.Ioc;
import com.blade.ioc.annotation.Bean;
import com.blade.ioc.annotation.Inject;
import com.blade.ioc.annotation.InjectWith;
import com.blade.ioc.annotation.Value;
import com.blade.ioc.bean.BeanDefine;
import com.blade.ioc.bean.ClassDefine;
import com.blade.ioc.bean.FieldInjector;
import com.blade.ioc.bean.ValueInjector;
import com.blade.mvc.WebContext;
import com.blade.mvc.annotation.Path;
import lombok.experimental.UtilityClass;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -132,18 +129,6 @@ public static void injectionValue(Environment environment, BeanDefine beanDefine
}

public static boolean isSingleton(Class<?> type) {
Bean bean = type.getAnnotation(Bean.class);
if (null != bean) {
return bean.singleton();
}
Path path = type.getAnnotation(Path.class);
if (null != path) {
return path.singleton();
}
Inject inject = type.getAnnotation(Inject.class);
if (null != inject) {
return inject.singleton();
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/blade/mvc/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface Const {
int DEFAULT_SERVER_PORT = 9000;
String DEFAULT_SERVER_ADDRESS = "0.0.0.0";
String LOCAL_IP_ADDRESS = "127.0.0.1";
String VERSION = "2.0.12.BETA";
String VERSION = "2.0.14.RELEASE";
String WEB_JARS = "/webjars/";
String CLASSPATH = BladeKit.getCurrentClassPath();
String CONTENT_TYPE_HTML = "text/html; charset=UTF-8";
Expand Down
Loading

0 comments on commit 2a4c96c

Please sign in to comment.