| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0d42fef commit b68e4f4
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,8 +27,6 @@ plan.txt | |||
| 27 | 27 | ||
| 28 | 28 | *.class | |
| 29 | 29 | ||
| 30 | - # Package Files # | ||
| 31 | - *.jar | ||
| 32 | 30 | ||
| 33 | 31 | ||
| 34 | 32 | *.bak | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,10 +45,9 @@ | |||
| 45 | 45 | public class DemoFunction extends RemoteFunction { | |
| 46 | 46 | private static final String TAG = "DemoFunction"; | |
| 47 | 47 | ||
| 48 | - private final RequestMethod method; | ||
| 49 | 48 | private final HttpSession session; | |
| 50 | - public DemoFunction(RequestMethod method, HttpSession session) { | ||
| 51 | - this.method = method; | ||
| 49 | + public DemoFunction(RequestMethod method, String tag, int version, HttpSession session) { | ||
| 50 | + super(method, tag, version); | ||
| 52 | 51 | this.session = session; | |
| 53 | 52 | } | |
| 54 | 53 | ||
@@ -78,11 +77,11 @@ public static void test() throws Exception { | |||
| 78 | 77 | request.put("object", object); | |
| 79 | 78 | ||
| 80 | 79 | ||
| 81 | - Log.i(TAG, "plus(1,-2) = " + new DemoFunction(null, null).invoke("plus(i0,i1)", request)); | ||
| 82 | - Log.i(TAG, "count([1,2,4,10]) = " + new DemoFunction(null, null).invoke("countArray(array)", request)); | ||
| 83 | - Log.i(TAG, "isContain([1,2,4,10], 10) = " + new DemoFunction(null, null).invoke("isContain(array,id)", request)); | ||
| 84 | - Log.i(TAG, "getFromArray([1,2,4,10], 0) = " + new DemoFunction(null, null).invoke("getFromArray(array,@position)", request)); | ||
| 85 | - Log.i(TAG, "getFromObject({key:true}, key) = " + new DemoFunction(null, null).invoke("getFromObject(object,key)", request)); | ||
| 80 | + Log.i(TAG, "plus(1,-2) = " + new DemoFunction(null, null, 1, null).invoke("plus(i0,i1)", request)); | ||
| 81 | + Log.i(TAG, "count([1,2,4,10]) = " + new DemoFunction(null, null, 1, null).invoke("countArray(array)", request)); | ||
| 82 | + Log.i(TAG, "isContain([1,2,4,10], 10) = " + new DemoFunction(null, null, 1, null).invoke("isContain(array,id)", request)); | ||
| 83 | + Log.i(TAG, "getFromArray([1,2,4,10], 0) = " + new DemoFunction(null, null, 1, null).invoke("getFromArray(array,@position)", request)); | ||
| 84 | + Log.i(TAG, "getFromObject({key:true}, key) = " + new DemoFunction(null, null, 1, null).invoke("getFromObject(object,key)", request)); | ||
| 86 | 85 | ||
| 87 | 86 | } | |
| 88 | 87 | ||
@@ -112,7 +111,7 @@ public static JSONObject init(boolean shutdownWhenServerError) throws ServerExce | |||
| 112 | 111 | request.putAll(functionItem.toArray(0, 0, FUNCTION_)); | |
| 113 | 112 | } //Function[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | |
| 114 | 113 | ||
| 115 | - | ||
| 114 | + | ||
| 116 | 115 | JSONObject response = new DemoParser(RequestMethod.GET, true).parseResponse(request); | |
| 117 | 116 | if (JSONResponse.isSuccess(response) == false) { | |
| 118 | 117 | onServerError("\n\n\n\n\n !!!! 查询远程函数异常 !!!\n" + response.getString(JSONResponse.KEY_MSG) + "\n\n\n\n\n", shutdownWhenServerError); | |
@@ -135,15 +134,28 @@ public static JSONObject init(boolean shutdownWhenServerError) throws ServerExce | |||
| 135 | 134 | if (demo == null) { | |
| 136 | 135 | onServerError("字段 demo 的值必须为合法且非 null 的 JSONObejct 字符串!", shutdownWhenServerError); | |
| 137 | 136 | } | |
| 137 | + String name = item.getString("name"); | ||
| 138 | 138 | if (demo.containsKey("result()") == false) { | |
| 139 | - demo.put("result()", getFunctionCall(item.getString("name"), item.getString("arguments"))); | ||
| 139 | + demo.put("result()", getFunctionCall(name, item.getString("arguments"))); | ||
| 140 | 140 | } | |
| 141 | - demo.put(JSONRequest.KEY_COLUMN, "id,name,arguments,demo"); | ||
| 141 | + // demo.put(JSONRequest.KEY_TAG, item.getString(JSONRequest.KEY_TAG)); | ||
| 142 | + // demo.put(JSONRequest.KEY_VERSION, item.getInteger(JSONRequest.KEY_VERSION)); | ||
| 143 | + | ||
| 144 | + FUNCTION_MAP.put(name, item); //必须在测试 invoke 前! | ||
| 145 | + | ||
| 146 | + String[] methods = StringUtil.split(item.getString("methods")); | ||
| 147 | + JSONObject r = new DemoParser( | ||
| 148 | + methods == null || methods.length <= 0 ? RequestMethod.GET : RequestMethod.valueOf(methods[0]) | ||
| 149 | + , true | ||
| 150 | + ) | ||
| 151 | + .setTag(item.getString(JSONRequest.KEY_TAG)) | ||
| 152 | + .setVersion(item.getIntValue(JSONRequest.KEY_VERSION)) | ||
| 153 | + .parseResponse(demo); | ||
| 142 | 154 | ||
| 143 | - JSONObject r = new DemoParser(RequestMethod.GET, true).parseResponse(demo); | ||
| 144 | 155 | if (JSONResponse.isSuccess(r) == false) { | |
| 145 | 156 | onServerError(JSONResponse.getMsg(r), shutdownWhenServerError); | |
| 146 | 157 | } | |
| 158 | + | ||
| 147 | 159 | } | |
| 148 | 160 | ||
| 149 | 161 | return response; | |
@@ -223,10 +235,6 @@ public Object verifyURLList(@NotNull JSONObject request, @NotNull String urlList | |||
| 223 | 235 | * @throws Exception | |
| 224 | 236 | */ | |
| 225 | 237 | public int deleteCommentOfMoment(@NotNull JSONObject rq, @NotNull String momentId) throws Exception { | |
| 226 | - if (method != RequestMethod.DELETE) { | ||
| 227 | - throw new UnsupportedOperationException("远程函数 deleteCommentOfMoment 只支持 DELETE 方法!"); | ||
| 228 | - } | ||
| 229 | - | ||
| 230 | 238 | long mid = rq.getLongValue(momentId); | |
| 231 | 239 | if (mid <= 0 || rq.getIntValue(JSONResponse.KEY_COUNT) <= 0) { | |
| 232 | 240 | return 0; | |
@@ -254,10 +262,6 @@ public int deleteCommentOfMoment(@NotNull JSONObject rq, @NotNull String momentI | |||
| 254 | 262 | * @return | |
| 255 | 263 | */ | |
| 256 | 264 | public int deleteChildComment(@NotNull JSONObject rq, @NotNull String toId) throws Exception { | |
| 257 | - if (method != RequestMethod.DELETE) { //TODO 如果这样的判断太多,可以把 DemoFunction 分成对应不同 RequestMethod 的 GetFunciton 等,创建时根据 method 判断用哪个 | ||
| 258 | - throw new UnsupportedOperationException("远程函数 deleteChildComment 只支持 DELETE 方法!"); | ||
| 259 | - } | ||
| 260 | - | ||
| 261 | 265 | long tid = rq.getLongValue(toId); | |
| 262 | 266 | if (tid <= 0 || rq.getIntValue(JSONResponse.KEY_COUNT) <= 0) { | |
| 263 | 267 | return 0; | |
@@ -324,10 +328,10 @@ private JSONArray getChildCommentIdList(long tid) { | |||
| 324 | 328 | * @return | |
| 325 | 329 | * @throws ServerException | |
| 326 | 330 | */ | |
| 327 | - public JSONObject getFunctionDemo(@NotNull JSONObject request) throws ServerException { | ||
| 331 | + public JSONObject getFunctionDemo(@NotNull JSONObject request) { | ||
| 328 | 332 | JSONObject demo = JSON.parseObject(request.getString("demo")); | |
| 329 | 333 | if (demo == null) { | |
| 330 | - throw new ServerException("服务器内部错误,字段 demo 的值必须为合法且非 null 的 JSONObejct 字符串!"); | ||
| 334 | + demo = new JSONObject(); | ||
| 331 | 335 | } | |
| 332 | 336 | if (demo.containsKey("result()") == false) { | |
| 333 | 337 | demo.put("result()", getFunctionCall(request.getString("name"), request.getString("arguments"))); | |
@@ -349,15 +353,15 @@ public String getFunctionDetail(@NotNull JSONObject request) { | |||
| 349 | 353 | * @return | |
| 350 | 354 | */ | |
| 351 | 355 | private static String getFunctionCall(String name, String arguments) { | |
| 352 | - return name + "(" + arguments + ")"; | ||
| 356 | + return name + "(" + StringUtil.getTrimedString(arguments) + ")"; | ||
| 353 | 357 | } | |
| 354 | 358 | ||
| 355 | 359 | /**TODO 仅用来测试 "key-()":"getIdList()" 和 "key()":"getIdList()" | |
| 356 | 360 | * @param request | |
| 357 | 361 | * @return JSONArray 只能用JSONArray,用long[]会在SQLConfig解析崩溃 | |
| 358 | 362 | * @throws Exception | |
| 359 | 363 | */ | |
| 360 | - public JSONArray getIdList(@NotNull JSONObject request) throws Exception { | ||
| 364 | + public JSONArray getIdList(@NotNull JSONObject request) { | ||
| 361 | 365 | return new JSONArray(new ArrayList<Object>(Arrays.asList(12, 15, 301, 82001, 82002, 38710))); | |
| 362 | 366 | } | |
| 363 | 367 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,8 @@ | |||
| 14 | 14 | ||
| 15 | 15 | package apijson.demo.server; | |
| 16 | 16 | ||
| 17 | + import java.util.List; | ||
| 18 | + | ||
| 17 | 19 | import javax.servlet.http.HttpSession; | |
| 18 | 20 | ||
| 19 | 21 | import com.alibaba.fastjson.JSONObject; | |
@@ -22,14 +24,15 @@ | |||
| 22 | 24 | import zuo.biao.apijson.RequestMethod; | |
| 23 | 25 | import zuo.biao.apijson.StringUtil; | |
| 24 | 26 | import zuo.biao.apijson.server.AbstractObjectParser; | |
| 27 | + import zuo.biao.apijson.server.Join; | ||
| 25 | 28 | import zuo.biao.apijson.server.Parser; | |
| 26 | 29 | import zuo.biao.apijson.server.SQLConfig; | |
| 27 | 30 | ||
| 28 | 31 | ||
| 29 | 32 | /**简化Parser,getObject和getArray(getArrayConfig)都能用 | |
| 30 | 33 | * @author Lemon | |
| 31 | 34 | */ | |
| 32 | - public abstract class DemoObjectParser extends AbstractObjectParser { | ||
| 35 | + public class DemoObjectParser extends AbstractObjectParser { | ||
| 33 | 36 | ||
| 34 | 37 | static { | |
| 35 | 38 | COMPILE_MAP.put("phone", StringUtil.PATTERN_PHONE); | |
@@ -38,7 +41,7 @@ public abstract class DemoObjectParser extends AbstractObjectParser { | |||
| 38 | 41 | } | |
| 39 | 42 | ||
| 40 | 43 | ||
| 41 | - | ||
| 44 | + | ||
| 42 | 45 | /**for single object | |
| 43 | 46 | * @param parentPath | |
| 44 | 47 | * @param request | |
@@ -48,7 +51,7 @@ public abstract class DemoObjectParser extends AbstractObjectParser { | |||
| 48 | 51 | public DemoObjectParser(HttpSession session, @NotNull JSONObject request, String parentPath, String name, SQLConfig arrayConfig, boolean isSubquery) throws Exception { | |
| 49 | 52 | super(request, parentPath, name, arrayConfig, isSubquery); | |
| 50 | 53 | } | |
| 51 | - | ||
| 54 | + | ||
| 52 | 55 | @Override | |
| 53 | 56 | public DemoObjectParser setMethod(RequestMethod method) { | |
| 54 | 57 | super.setMethod(method); | |
@@ -61,9 +64,10 @@ public DemoObjectParser setParser(Parser<?> parser) { | |||
| 61 | 64 | return this; | |
| 62 | 65 | } | |
| 63 | 66 | ||
| 67 | + | ||
| 64 | 68 | @Override | |
| 65 | - public SQLConfig newSQLConfig(boolean isProcedure) throws Exception { | ||
| 66 | - return DemoSQLConfig.newSQLConfig(method, table, alias, sqlRequest, joinList, isProcedure); | ||
| 69 | + public SQLConfig newSQLConfig(RequestMethod method, String table, String alias, JSONObject request, List<Join> joinList, boolean isProcedure) throws Exception { | ||
| 70 | + return DemoSQLConfig.newSQLConfig(method, table, alias, request, joinList, isProcedure); | ||
| 67 | 71 | } | |
| 68 | 72 | ||
| 69 | 73 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,7 +94,7 @@ public JSONObject parseResponse(JSONObject request) { | |||
| 94 | 94 | @Override | |
| 95 | 95 | public Object onFunctionParse(JSONObject json, String fun) throws Exception { | |
| 96 | 96 | if (function == null) { | |
| 97 | - function = new DemoFunction(requestMethod, session); | ||
| 97 | + function = new DemoFunction(requestMethod, tag, version, session); | ||
| 98 | 98 | } | |
| 99 | 99 | return function.invoke(fun, json); | |
| 100 | 100 | } | |
@@ -106,15 +106,7 @@ public DemoObjectParser createObjectParser(JSONObject request, String parentPath | |||
| 106 | 106 | return new DemoObjectParser(session, request, parentPath, name, arrayConfig, isSubquery) { | |
| 107 | 107 | ||
| 108 | 108 | //TODO 删除,onPUTArrayParse改用MySQL函数JSON_ADD, JSON_REMOVE等 | |
| 109 | - @Override | ||
| 110 | - public JSONObject parseResponse(JSONRequest request) throws Exception { | ||
| 111 | - DemoParser demoParser = new DemoParser(RequestMethod.GET); | ||
| 112 | - demoParser.setSession(session); | ||
| 113 | - // parser.setNoVerifyRequest(noVerifyRequest) | ||
| 114 | - demoParser.setNoVerifyLogin(noVerifyLogin); | ||
| 115 | - demoParser.setNoVerifyRole(noVerifyRole); | ||
| 116 | - return demoParser.parseResponse(request); | ||
| 117 | - } | ||
| 109 | + | ||
| 118 | 110 | ||
| 119 | 111 | ||
| 120 | 112 | // @Override | |
| Back | FazBrowse Home | New Git URL |
0 commit comments