Skip to content

Commit 9a4e4ed

Browse files
committed
Server:优化远程函数调用报错
1 parent af62a9d commit 9a4e4ed

File tree

1 file changed

+23
-5
lines changed
  • APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server

1 file changed

+23
-5
lines changed

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/Function.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616

1717
import com.alibaba.fastjson.JSONObject;
1818

19-
import zuo.biao.apijson.Log;
2019
import zuo.biao.apijson.StringUtil;
2120

2221
/**可远程调用的函数类
2322
* @author Lemon
2423
*/
2524
public class Function {
26-
private static final String TAG = "Function";
25+
// private static final String TAG = "Function";
2726

2827
/**反射调用
2928
* @param fun
@@ -37,8 +36,9 @@ public static Object invoke(@NotNull Function fun, @NotNull JSONObject request,
3736
int end = function.lastIndexOf(")");
3837
String method = function.substring(0, start);
3938
if (StringUtil.isEmpty(method, true)) {
40-
Log.i(TAG, "invoke StringUtil.isEmpty(method, true) >> return null;");
41-
return null;
39+
throw new IllegalArgumentException("字符 " + function + " 不合法!远程函数的名称function不能为空,"
40+
+ "且必须为 function(key0,key1,...) 这种单函数格式!"
41+
+ "\nfunction必须符合Java函数命名,key是用于在request内取值的键!");
4242
}
4343

4444
String[] keys = StringUtil.split(function.substring(start + 1, end));
@@ -82,7 +82,25 @@ public static Object invoke(@NotNull Function fun, @NotNull JSONObject request,
8282
// }
8383
// }
8484

85-
return invoke(fun, method, types, values);
85+
try {
86+
return invoke(fun, method, types, values);
87+
} catch (Exception e) {
88+
if (e instanceof NoSuchMethodException) {
89+
String f = method + "(JSONObject request";
90+
for (int i = 0; i < length; i++) {
91+
f += (", String " + keys[i]);
92+
}
93+
f += ")";
94+
95+
throw new IllegalArgumentException("字符 " + function + " 对应的远程函数 " + f + " 不在后端工程的DemoFunction内!"
96+
+ "\n请检查函数名和参数数量是否与已定义的函数一致!"
97+
+ "\n且必须为 function(key0,key1,...) 这种单函数格式!"
98+
+ "\nfunction必须符合Java函数命名,key是用于在request内取值的键!"
99+
+ "\n调用时不要有空格!");
100+
}
101+
throw e;
102+
}
103+
86104
}
87105
/**反射调用
88106
* @param methodName

0 commit comments

Comments
 (0)