1616
1717import com .alibaba .fastjson .JSONObject ;
1818
19- import zuo .biao .apijson .Log ;
2019import zuo .biao .apijson .StringUtil ;
2120
2221/**可远程调用的函数类
2322 * @author Lemon
2423 */
2524public 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+ + "\n function必须符合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+ + "\n function必须符合Java函数命名,key是用于在request内取值的键!"
99+ + "\n 调用时不要有空格!" );
100+ }
101+ throw e ;
102+ }
103+
86104 }
87105 /**反射调用
88106 * @param methodName
0 commit comments