params, String request
/**重新加载配置
- * @param request
* @return
* @see
*
- {
- "type": "ALL", //重载对象,ALL, FUNCTION, REQUEST, ACCESS,非必须
- "phone": "13000082001",
- "verify": "1234567" //验证码,对应类型为 Verify.TYPE_RELOAD
- }
+ {
+ "type": "ALL", //重载对象,ALL, FUNCTION, REQUEST, ACCESS,非必须
+ "phone": "13000082001",
+ "verify": "1234567" //验证码,对应类型为 Verify.TYPE_RELOAD
+ }
*
*/
- public JSONObject reload(String type) {
- JSONObject result = APIJSONParser.newSuccessResult();
+ public M reload(String type) {
+ M result = newSuccessResult();
boolean reloadAll = StringUtil.isEmpty(type, true) || "ALL".equals(type);
if (reloadAll || "ACCESS".equals(type)) {
try {
- result.put(ACCESS_, APIJSONVerifier.initAccess());
+ if (reloadAll == false && APIJSONVerifier.ENABLE_VERIFY_ROLE == false) {
+ throw new UnsupportedOperationException("AbstractVerifier.ENABLE_VERIFY_ROLE == false 时不支持校验角色权限!" +
+ "如需支持则设置 AbstractVerifier.ENABLE_VERIFY_ROLE = true !");
+ }
+
+ if (APIJSONVerifier.ENABLE_VERIFY_ROLE) {
+ result.put(ACCESS_, APIJSONVerifier.initAccess());
+ }
} catch (ServerException e) {
e.printStackTrace();
- result.put(ACCESS_, APIJSONParser.newErrorResult(e));
+ result.put(ACCESS_, newErrorResult(e));
}
}
if (reloadAll || "FUNCTION".equals(type)) {
try {
- result.put(FUNCTION_, APIJSONFunctionParser.init());
+ if (reloadAll == false && APIJSONFunctionParser.ENABLE_REMOTE_FUNCTION == false) {
+ throw new UnsupportedOperationException("AbstractFunctionParser.ENABLE_REMOTE_FUNCTION" +
+ " == false 时不支持远程函数!如需支持则设置 AbstractFunctionParser.ENABLE_REMOTE_FUNCTION = true !");
+ }
+
+ if (APIJSONFunctionParser.ENABLE_REMOTE_FUNCTION) {
+ result.put(FUNCTION_, APIJSONFunctionParser.init());
+ }
} catch (ServerException e) {
e.printStackTrace();
- result.put(FUNCTION_, APIJSONParser.newErrorResult(e));
+ result.put(FUNCTION_, newErrorResult(e));
}
}
if (reloadAll || "REQUEST".equals(type)) {
try {
- result.put(REQUEST_, APIJSONVerifier.initRequest());
+ if (reloadAll == false && APIJSONVerifier.ENABLE_VERIFY_CONTENT == false) {
+ throw new UnsupportedOperationException("AbstractVerifier.ENABLE_VERIFY_CONTENT == false 时不支持校验请求传参内容!" +
+ "如需支持则设置 AbstractVerifier.ENABLE_VERIFY_CONTENT = true !");
+ }
+
+ if (APIJSONVerifier.ENABLE_VERIFY_CONTENT) {
+ result.put(REQUEST_, APIJSONVerifier.initRequest());
+ }
} catch (ServerException e) {
e.printStackTrace();
- result.put(REQUEST_, APIJSONParser.newErrorResult(e));
+ result.put(REQUEST_, newErrorResult(e));
}
}
@@ -353,14 +726,14 @@ public JSONObject reload(String type) {
/**用户登录
- * @param session
- * @param visitor
- * @param version
- * @param format
- * @param defaults
+ * @param session
+ * @param visitor
+ * @param version
+ * @param format
+ * @param defaults
* @return 返回类型设置为 Object 是为了子类重写时可以有返回值,避免因为冲突而另写一个有返回值的登录方法
*/
- public Object login(@NotNull HttpSession session, Visitor visitor, Integer version, Boolean format, JSONObject defaults) {
+ public Object login(@NotNull HttpSession session, @NotNull Visitor visitor, Integer version, Boolean format, M defaults) {
//登录状态保存至session
session.setAttribute(VISITOR_ID, visitor.getId()); //用户id
session.setAttribute(VISITOR_, visitor); //用户
@@ -383,62 +756,62 @@ public Object logout(@NotNull HttpSession session) {
- public JSONObject listMethod(String request) {
- if (Log.DEBUG == false) {
- return APIJSONParser.newErrorResult(new IllegalAccessException("非 DEBUG 模式下不允许使用 UnitAuto 单元测试!"));
- }
- return MethodUtil.listMethod(request);
- }
-
- public void invokeMethod(String request, HttpServletRequest servletRequest) {
- AsyncContext asyncContext = servletRequest.startAsync();
-
- final boolean[] called = new boolean[] { false };
- MethodUtil.Listener listener = new MethodUtil.Listener() {
-
- @Override
- public void complete(JSONObject data, Method method, InterfaceProxy proxy, Object... extras) throws Exception {
-
- ServletResponse servletResponse = called[0] ? null : asyncContext.getResponse();
- if (servletResponse == null) { // || servletResponse.isCommitted()) { // isCommitted 在高并发时可能不准,导致写入多次
- Log.w(TAG, "invokeMethod listener.complete servletResponse == null || servletResponse.isCommitted() >> return;");
- return;
- }
- called[0] = true;
-
- servletResponse.setCharacterEncoding(servletRequest.getCharacterEncoding());
- servletResponse.setContentType(servletRequest.getContentType());
- servletResponse.getWriter().println(data);
- asyncContext.complete();
- }
- };
-
- if (Log.DEBUG == false) {
- try {
- listener.complete(MethodUtil.JSON_CALLBACK.newErrorResult(new IllegalAccessException("非 DEBUG 模式下不允许使用 UnitAuto 单元测试!")));
- }
- catch (Exception e1) {
- e1.printStackTrace();
- asyncContext.complete();
- }
-
- return;
- }
-
-
- try {
- MethodUtil.invokeMethod(request, null, listener);
- }
- catch (Exception e) {
- Log.e(TAG, "invokeMethod try { JSONObject req = JSON.parseObject(request); ... } catch (Exception e) { \n" + e.getMessage());
- try {
- listener.complete(MethodUtil.JSON_CALLBACK.newErrorResult(e));
- }
- catch (Exception e1) {
- e1.printStackTrace();
- asyncContext.complete();
- }
- }
- }
+// public JSONMap listMethod(String request) {
+// if (Log.DEBUG == false) {
+// return APIJSONParser.newErrorResult(new IllegalAccessException("非 DEBUG 模式下不允许使用 UnitAuto 单元测试!"));
+// }
+// return MethodUtil.listMethod(request);
+// }
+//
+// public void invokeMethod(String request, HttpServletRequest servletRequest) {
+// AsyncContext asyncContext = servletRequest.startAsync();
+//
+// final boolean[] called = new boolean[] { false };
+// MethodUtil.Listener listener = new MethodUtil.Listener() {
+//
+// @Override
+// public void complete(JSONMap data, Method method, InterfaceProxy proxy, Object... extras) throws Exception {
+//
+// ServletResponse servletResponse = called[0] ? null : asyncContext.getResponse();
+// if (servletResponse == null) { // || servletResponse.isCommitted()) { // isCommitted 在高并发时可能不准,导致写入多次
+// Log.w(TAG, "invokeMethod listener.complete servletResponse == null || servletResponse.isCommitted() >> return;");
+// return;
+// }
+// called[0] = true;
+//
+// servletResponse.setCharacterEncoding(servletRequest.getCharacterEncoding());
+// servletResponse.setContentType(servletRequest.getContentType());
+// servletResponse.getWriter().println(data);
+// asyncContext.complete();
+// }
+// };
+//
+// if (Log.DEBUG == false) {
+// try {
+// listener.complete(MethodUtil.JSON_CALLBACK.newErrorResult(new IllegalAccessException("非 DEBUG 模式下不允许使用 UnitAuto 单元测试!")));
+// }
+// catch (Exception e1) {
+// e1.printStackTrace();
+// asyncContext.complete();
+// }
+//
+// return;
+// }
+//
+//
+// try {
+// MethodUtil.invokeMethod(request, null, listener);
+// }
+// catch (Exception e) {
+// Log.e(TAG, "invokeMethod try { JSONMap req = JSON.parseObject(request); ... } catch (Exception e) { \n" + e.getMessage());
+// try {
+// listener.complete(MethodUtil.JSON_CALLBACK.newErrorResult(e));
+// }
+// catch (Exception e1) {
+// e1.printStackTrace();
+// asyncContext.complete();
+// }
+// }
+// }
}
diff --git a/src/main/java/apijson/framework/APIJSONCreator.java b/src/main/java/apijson/framework/APIJSONCreator.java
index 355a5ba..17e7ed7 100644
--- a/src/main/java/apijson/framework/APIJSONCreator.java
+++ b/src/main/java/apijson/framework/APIJSONCreator.java
@@ -1,4 +1,4 @@
-/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON)
+/*Copyright ©2016 APIJSON(https://github.com/APIJSON)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -14,44 +14,43 @@
package apijson.framework;
-import apijson.orm.FunctionParser;
-import apijson.orm.Parser;
import apijson.orm.ParserCreator;
-import apijson.orm.SQLConfig;
import apijson.orm.SQLCreator;
-import apijson.orm.SQLExecutor;
-import apijson.orm.Verifier;
import apijson.orm.VerifierCreator;
+import java.util.List;
+import java.util.Map;
+
/**APIJSON相关创建器
* @author Lemon
*/
-public class APIJSONCreator implements ParserCreator, VerifierCreator, SQLCreator {
+public class APIJSONCreator, L extends List