Skip to content

Commit a890621

Browse files
committed
新增 javax 来兼容 JDK 1.8~16 及 SpringBoot 1.4~2.7 等
1 parent 432f162 commit a890621

17 files changed

+2797
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
HELP.md
22
.gradle
33
build/
4+
target/
5+
46
!gradle/wrapper/gradle-wrapper.jar
57
!**/src/main/**/build/
68
!**/src/test/**/build/

pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>apijson.framework</groupId>
77
<artifactId>apijson-framework</artifactId>
8-
<version>7.1.0</version>
8+
<version>7.1.5</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONFramework</name>
@@ -21,13 +21,21 @@
2121
</properties>
2222

2323
<dependencies>
24+
<!-- JDK 17+, SpringBoot 3.0+ -->
2425
<dependency>
2526
<groupId>jakarta.servlet</groupId>
2627
<artifactId>jakarta.servlet-api</artifactId>
2728
<version>6.0.0</version>
2829
<scope>provided</scope>
2930
</dependency>
3031

32+
<!-- JDK 1.8~16, SpringBoot 1.4~2.7 -->
33+
<dependency>
34+
<groupId>javax.servlet</groupId>
35+
<artifactId>javax.servlet-api</artifactId>
36+
<version>4.0.1</version>
37+
</dependency>
38+
3139
<dependency>
3240
<groupId>com.alibaba</groupId>
3341
<artifactId>fastjson</artifactId>

src/main/java/apijson/framework/APIJSONCreator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public Parser<T> createParser() {
3535
}
3636

3737
@Override
38-
public FunctionParser createFunctionParser() {
39-
return new APIJSONFunctionParser();
38+
public FunctionParser<T> createFunctionParser() {
39+
return new APIJSONFunctionParser<>();
4040
}
4141

4242
@Override
@@ -45,13 +45,13 @@ public Verifier<T> createVerifier() {
4545
}
4646

4747
@Override
48-
public SQLConfig createSQLConfig() {
49-
return new APIJSONSQLConfig();
48+
public SQLConfig<T> createSQLConfig() {
49+
return new APIJSONSQLConfig<>();
5050
}
5151

5252
@Override
53-
public SQLExecutor createSQLExecutor() {
54-
return new APIJSONSQLExecutor();
53+
public SQLExecutor<T> createSQLExecutor() {
54+
return new APIJSONSQLExecutor<>();
5555
}
5656

5757
}

src/main/java/apijson/framework/APIJSONSQLConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public class APIJSONSQLConfig<T extends Object> extends AbstractSQLConfig<T> {
5656

5757
APIJSON_CREATOR = new APIJSONCreator<>();
5858

59-
SIMPLE_CALLBACK = new SimpleCallback<Object>() {
59+
SIMPLE_CALLBACK = new SimpleCallback<>() {
6060

6161
@Override
6262
public SQLConfig<Object> getSQLConfig(RequestMethod method, String database, String schema,String datasource, String table) {
63-
SQLConfig<Object> config = APIJSON_CREATOR.createSQLConfig();
63+
SQLConfig<Object> config = (SQLConfig<Object>) APIJSON_CREATOR.createSQLConfig();
6464
config.setMethod(method);
6565
config.setDatabase(database);
6666
config.setDatasource(datasource);
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package apijson.framework.javax;
16+
17+
import apijson.Log;
18+
import apijson.NotNull;
19+
import apijson.orm.AbstractFunctionParser;
20+
import apijson.orm.script.ScriptExecutor;
21+
22+
import java.rmi.ServerException;
23+
24+
25+
/**启动入口 Application
26+
* 右键这个类 > Run As > Java Application
27+
* @author Lemon
28+
*/
29+
public class APIJSONApplication {
30+
public static final String TAG = "APIJSONApplication";
31+
32+
@NotNull
33+
public static APIJSONCreator<? extends Object> DEFAULT_APIJSON_CREATOR;
34+
static {
35+
DEFAULT_APIJSON_CREATOR = new APIJSONCreator<>();
36+
}
37+
38+
39+
/**初始化,加载所有配置并校验
40+
* @return
41+
* @throws Exception
42+
*/
43+
public static void init() throws Exception {
44+
init(true, DEFAULT_APIJSON_CREATOR);
45+
}
46+
/**初始化,加载所有配置并校验
47+
* @param shutdownWhenServerError
48+
* @return
49+
* @throws Exception
50+
*/
51+
public static void init(boolean shutdownWhenServerError) throws Exception {
52+
init(shutdownWhenServerError, DEFAULT_APIJSON_CREATOR);
53+
}
54+
/**初始化,加载所有配置并校验
55+
* @param creator
56+
* @return
57+
* @throws Exception
58+
*/
59+
public static <T extends Object> void init(@NotNull APIJSONCreator<T> creator) throws Exception {
60+
init(true, creator);
61+
}
62+
/**初始化,加载所有配置并校验
63+
* @param shutdownWhenServerError
64+
* @param creator
65+
* @return
66+
* @throws Exception
67+
*/
68+
public static <T extends Object> void init(boolean shutdownWhenServerError, @NotNull APIJSONCreator<T> creator) throws Exception {
69+
System.out.println("\n\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 开始启动 >>>>>>>>>>>>>>>>>>>>>>>>\n");
70+
DEFAULT_APIJSON_CREATOR = creator;
71+
72+
// 统一用同一个 creator
73+
APIJSONSQLConfig.APIJSON_CREATOR = creator;
74+
APIJSONParser.APIJSON_CREATOR = creator;
75+
APIJSONController.APIJSON_CREATOR = creator;
76+
77+
78+
if (APIJSONVerifier.ENABLE_VERIFY_ROLE) {
79+
System.out.println("\n\n\n开始初始化: Access 权限校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
80+
try {
81+
APIJSONVerifier.initAccess(shutdownWhenServerError, creator);
82+
} catch (Throwable e) {
83+
e.printStackTrace();
84+
if (shutdownWhenServerError) {
85+
onServerError("Access 权限校验配置 初始化失败!", shutdownWhenServerError);
86+
}
87+
}
88+
System.out.println("\n完成初始化: Access 权限校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
89+
}
90+
91+
92+
if (APIJSONFunctionParser.ENABLE_REMOTE_FUNCTION) {
93+
System.out.println("\n\n\n开始初始化: Function 远程函数配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
94+
try {
95+
APIJSONFunctionParser.init(shutdownWhenServerError, creator);
96+
} catch (Throwable e) {
97+
e.printStackTrace();
98+
if (shutdownWhenServerError) {
99+
onServerError("Function 远程函数配置 初始化失败!", shutdownWhenServerError);
100+
}
101+
}
102+
System.out.println("\n完成初始化: Function 远程函数配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
103+
104+
System.out.println("开始测试: Function 远程函数 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
105+
try {
106+
APIJSONFunctionParser.test();
107+
} catch (Throwable e) {
108+
e.printStackTrace();
109+
if (shutdownWhenServerError) {
110+
onServerError("Function 远程函数配置 测试失败!", shutdownWhenServerError);
111+
}
112+
}
113+
System.out.println("\n完成测试: Function 远程函数 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
114+
}
115+
116+
117+
if (APIJSONVerifier.ENABLE_VERIFY_CONTENT) {
118+
System.out.println("\n\n\n开始初始化: Request 请求参数校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
119+
try {
120+
APIJSONVerifier.initRequest(shutdownWhenServerError, creator);
121+
} catch (Throwable e) {
122+
e.printStackTrace();
123+
if (shutdownWhenServerError) {
124+
onServerError("Request 请求参数校验配置 初始化失败!", shutdownWhenServerError);
125+
}
126+
}
127+
System.out.println("\n完成初始化: Request 请求参数校验校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
128+
129+
System.out.println("\n\n\n开始测试: Request 请求参数校验 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
130+
try {
131+
APIJSONVerifier.testStructure();
132+
} catch (Throwable e) {
133+
e.printStackTrace();
134+
if (shutdownWhenServerError) {
135+
onServerError("Request 请求参数校验 测试失败!", shutdownWhenServerError);
136+
}
137+
}
138+
System.out.println("\n完成测试: Request 请求参数校验 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
139+
}
140+
141+
142+
143+
System.out.println("官方网站: http://apijson.cn");
144+
System.out.println("设计规范: https://github.com/Tencent/APIJSON/blob/master/Document.md#3");
145+
System.out.println("测试链接: http://apijson.cn/api?type=JSON&url=http://localhost:8080/get");
146+
System.out.println("\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 启动完成,试试调用零代码万能通用 API 吧 ^_^ >>>>>>>>>>>>>>>>>>>>>>>>\n");
147+
}
148+
149+
protected static void onServerError(String msg, boolean shutdown) throws ServerException {
150+
Log.e(TAG, "\n启动时自检测试未通过!原因:\n" + msg);
151+
152+
if (shutdown) {
153+
System.exit(1);
154+
} else {
155+
throw new ServerException(msg);
156+
}
157+
}
158+
159+
public static void addScriptExecutor(String language, ScriptExecutor scriptExecutor) {
160+
scriptExecutor.init();
161+
AbstractFunctionParser.SCRIPT_EXECUTOR_MAP.put(language, scriptExecutor);
162+
}
163+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.*/
14+
15+
package apijson.framework.javax;
16+
17+
/**APIJSON 常量类
18+
* @author Lemon
19+
*/
20+
public class APIJSONConstant extends apijson.framework.APIJSONConstant {}

0 commit comments

Comments
 (0)