Skip to content

Commit b68e4f4

Browse files
committed
Server: 解决 APIJSONFinal 缺 libs 目录及相关 jar 包;同步 APIJSONBoot 的代码到 APIJSONFinal
1 parent 0d42fef commit b68e4f4

File tree

6 files changed

+39
-41
lines changed

6 files changed

+39
-41
lines changed

APIJSON-Java-Server/APIJSONFinal/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ plan.txt
2727

2828
*.class
2929

30-
# Package Files #
31-
*.jar
3230

3331

3432
*.bak
265 KB
Binary file not shown.
796 KB
Binary file not shown.

APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoFunction.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@
4545
public class DemoFunction extends RemoteFunction {
4646
private static final String TAG = "DemoFunction";
4747

48-
private final RequestMethod method;
4948
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);
5251
this.session = session;
5352
}
5453

@@ -78,11 +77,11 @@ public static void test() throws Exception {
7877
request.put("object", object);
7978

8079

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));
8685

8786
}
8887

@@ -112,7 +111,7 @@ public static JSONObject init(boolean shutdownWhenServerError) throws ServerExce
112111
request.putAll(functionItem.toArray(0, 0, FUNCTION_));
113112
} //Function[]>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
114113

115-
114+
116115
JSONObject response = new DemoParser(RequestMethod.GET, true).parseResponse(request);
117116
if (JSONResponse.isSuccess(response) == false) {
118117
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
135134
if (demo == null) {
136135
onServerError("字段 demo 的值必须为合法且非 null 的 JSONObejct 字符串!", shutdownWhenServerError);
137136
}
137+
String name = item.getString("name");
138138
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")));
140140
}
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);
142154

143-
JSONObject r = new DemoParser(RequestMethod.GET, true).parseResponse(demo);
144155
if (JSONResponse.isSuccess(r) == false) {
145156
onServerError(JSONResponse.getMsg(r), shutdownWhenServerError);
146157
}
158+
147159
}
148160

149161
return response;
@@ -223,10 +235,6 @@ public Object verifyURLList(@NotNull JSONObject request, @NotNull String urlList
223235
* @throws Exception
224236
*/
225237
public int deleteCommentOfMoment(@NotNull JSONObject rq, @NotNull String momentId) throws Exception {
226-
if (method != RequestMethod.DELETE) {
227-
throw new UnsupportedOperationException("远程函数 deleteCommentOfMoment 只支持 DELETE 方法!");
228-
}
229-
230238
long mid = rq.getLongValue(momentId);
231239
if (mid <= 0 || rq.getIntValue(JSONResponse.KEY_COUNT) <= 0) {
232240
return 0;
@@ -254,10 +262,6 @@ public int deleteCommentOfMoment(@NotNull JSONObject rq, @NotNull String momentI
254262
* @return
255263
*/
256264
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-
261265
long tid = rq.getLongValue(toId);
262266
if (tid <= 0 || rq.getIntValue(JSONResponse.KEY_COUNT) <= 0) {
263267
return 0;
@@ -324,10 +328,10 @@ private JSONArray getChildCommentIdList(long tid) {
324328
* @return
325329
* @throws ServerException
326330
*/
327-
public JSONObject getFunctionDemo(@NotNull JSONObject request) throws ServerException {
331+
public JSONObject getFunctionDemo(@NotNull JSONObject request) {
328332
JSONObject demo = JSON.parseObject(request.getString("demo"));
329333
if (demo == null) {
330-
throw new ServerException("服务器内部错误,字段 demo 的值必须为合法且非 null 的 JSONObejct 字符串!");
334+
demo = new JSONObject();
331335
}
332336
if (demo.containsKey("result()") == false) {
333337
demo.put("result()", getFunctionCall(request.getString("name"), request.getString("arguments")));
@@ -349,15 +353,15 @@ public String getFunctionDetail(@NotNull JSONObject request) {
349353
* @return
350354
*/
351355
private static String getFunctionCall(String name, String arguments) {
352-
return name + "(" + arguments + ")";
356+
return name + "(" + StringUtil.getTrimedString(arguments) + ")";
353357
}
354358

355359
/**TODO 仅用来测试 "key-()":"getIdList()" 和 "key()":"getIdList()"
356360
* @param request
357361
* @return JSONArray 只能用JSONArray,用long[]会在SQLConfig解析崩溃
358362
* @throws Exception
359363
*/
360-
public JSONArray getIdList(@NotNull JSONObject request) throws Exception {
364+
public JSONArray getIdList(@NotNull JSONObject request) {
361365
return new JSONArray(new ArrayList<Object>(Arrays.asList(12, 15, 301, 82001, 82002, 38710)));
362366
}
363367

APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoObjectParser.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package apijson.demo.server;
1616

17+
import java.util.List;
18+
1719
import javax.servlet.http.HttpSession;
1820

1921
import com.alibaba.fastjson.JSONObject;
@@ -22,14 +24,15 @@
2224
import zuo.biao.apijson.RequestMethod;
2325
import zuo.biao.apijson.StringUtil;
2426
import zuo.biao.apijson.server.AbstractObjectParser;
27+
import zuo.biao.apijson.server.Join;
2528
import zuo.biao.apijson.server.Parser;
2629
import zuo.biao.apijson.server.SQLConfig;
2730

2831

2932
/**简化Parser,getObject和getArray(getArrayConfig)都能用
3033
* @author Lemon
3134
*/
32-
public abstract class DemoObjectParser extends AbstractObjectParser {
35+
public class DemoObjectParser extends AbstractObjectParser {
3336

3437
static {
3538
COMPILE_MAP.put("phone", StringUtil.PATTERN_PHONE);
@@ -38,7 +41,7 @@ public abstract class DemoObjectParser extends AbstractObjectParser {
3841
}
3942

4043

41-
44+
4245
/**for single object
4346
* @param parentPath
4447
* @param request
@@ -48,7 +51,7 @@ public abstract class DemoObjectParser extends AbstractObjectParser {
4851
public DemoObjectParser(HttpSession session, @NotNull JSONObject request, String parentPath, String name, SQLConfig arrayConfig, boolean isSubquery) throws Exception {
4952
super(request, parentPath, name, arrayConfig, isSubquery);
5053
}
51-
54+
5255
@Override
5356
public DemoObjectParser setMethod(RequestMethod method) {
5457
super.setMethod(method);
@@ -61,9 +64,10 @@ public DemoObjectParser setParser(Parser<?> parser) {
6164
return this;
6265
}
6366

67+
6468
@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);
6771
}
6872

6973

APIJSON-Java-Server/APIJSONFinal/src/main/java/apijson/demo/server/DemoParser.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public JSONObject parseResponse(JSONObject request) {
9494
@Override
9595
public Object onFunctionParse(JSONObject json, String fun) throws Exception {
9696
if (function == null) {
97-
function = new DemoFunction(requestMethod, session);
97+
function = new DemoFunction(requestMethod, tag, version, session);
9898
}
9999
return function.invoke(fun, json);
100100
}
@@ -106,15 +106,7 @@ public DemoObjectParser createObjectParser(JSONObject request, String parentPath
106106
return new DemoObjectParser(session, request, parentPath, name, arrayConfig, isSubquery) {
107107

108108
//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+
118110

119111

120112
// @Override

0 commit comments

Comments
 (0)