3131import java .util .List ;
3232import java .util .Map ;
3333
34-
34+ import jakarta . servlet . http . HttpSession ;
3535
3636import com .alibaba .fastjson .JSONArray ;
3737import com .alibaba .fastjson .JSONObject ;
4646import apijson .orm .JSONRequest ;
4747import apijson .orm .script .JavaScriptExecutor ;
4848import apijson .orm .script .ScriptExecutor ;
49- import jakarta .servlet .http .HttpSession ;
5049import unitauto .MethodUtil ;
5150import unitauto .MethodUtil .Argument ;
5251
5352
5453/**可远程调用的函数类
5554 * @author Lemon
5655 */
57- public class APIJSONFunctionParser extends AbstractFunctionParser {
56+ public class APIJSONFunctionParser < T extends Object > extends AbstractFunctionParser < T > {
5857 public static final String TAG = "APIJSONFunctionParser" ;
5958
6059 @ NotNull
@@ -80,23 +79,23 @@ public APIJSONFunctionParser(RequestMethod method, String tag, int version, JSON
8079 public HttpSession getSession () {
8180 return session ;
8281 }
83- public APIJSONFunctionParser setSession (HttpSession session ) {
82+ public APIJSONFunctionParser < T > setSession (HttpSession session ) {
8483 this .session = session ;
8584 return this ;
8685 }
8786
8887 @ Override
89- public APIJSONFunctionParser setMethod (RequestMethod method ) {
88+ public APIJSONFunctionParser < T > setMethod (RequestMethod method ) {
9089 super .setMethod (method );
9190 return this ;
9291 }
9392 @ Override
94- public APIJSONFunctionParser setTag (String tag ) {
93+ public APIJSONFunctionParser < T > setTag (String tag ) {
9594 super .setTag (tag );
9695 return this ;
9796 }
9897 @ Override
99- public APIJSONFunctionParser setVersion (int version ) {
98+ public APIJSONFunctionParser < T > setVersion (int version ) {
10099 super .setVersion (version );
101100 return this ;
102101 }
@@ -284,7 +283,7 @@ public static <T extends Object> JSONObject init(boolean shutdownWhenServerError
284283 if (item .get ("language" ) != null ) {
285284 String language = item .getString ("language" );
286285 if (SCRIPT_EXECUTOR_MAP .get (language ) == null ) {
287- onServerError ("找不到脚本语言 " + language + " 对应的执行引擎!请先依赖相关库并在后端 APIJSONFunctionParser 中注册!" , shutdownWhenServerError );
286+ onServerError ("找不到脚本语言 " + language + " 对应的执行引擎!请先依赖相关库并在后端 APIJSONFunctionParser<T> 中注册!" , shutdownWhenServerError );
288287 }
289288 ScriptExecutor scriptExecutor = SCRIPT_EXECUTOR_MAP .get (language );
290289 scriptExecutor .load (name , scriptMap .get (name ).getString ("script" ));
@@ -297,12 +296,13 @@ public static <T extends Object> JSONObject init(boolean shutdownWhenServerError
297296 methods = ALL_METHODS ;
298297 }
299298
299+ demo .put (JSONRequest .KEY_TAG , item .get (JSONRequest .KEY_TAG ));
300+ demo .put (JSONRequest .KEY_VERSION , item .get (JSONRequest .KEY_VERSION ));
301+
300302 for (String method : methods ) {
301303 JSONObject r = APIJSON_CREATOR .createParser ()
302304 .setMethod (RequestMethod .valueOf (method ))
303305 .setNeedVerify (false )
304- .setTag (item .getString (JSONRequest .KEY_TAG ))
305- .setVersion (item .getIntValue (JSONRequest .KEY_VERSION ))
306306 .parseResponse (demo );
307307
308308 if (JSONResponse .isSuccess (r ) == false ) {
@@ -337,7 +337,7 @@ protected static void onServerError(String msg, boolean shutdown) throws ServerE
337337 public static void test () throws Exception {
338338 test (null );
339339 }
340- public static void test (APIJSONFunctionParser function ) throws Exception {
340+ public static < T extends Object > void test (APIJSONFunctionParser < T > function ) throws Exception {
341341 int i0 = 1 , i1 = -2 ;
342342 JSONObject request = new JSONObject ();
343343 request .put ("id" , 10 );
@@ -710,14 +710,6 @@ public String getMethodArguments(@NotNull JSONObject curObj, String methodArgsKe
710710 }
711711
712712
713- /**改用 getMethodDefinition
714- */
715- @ Deprecated
716- public String getMethodDefination (@ NotNull JSONObject curObj ) throws IllegalArgumentException {
717- // curObj.put("arguments", removeComment(curObj.getString("methodArgs")));
718- return getMethodDefination (curObj , "method" , "arguments" , "genericType" , "genericExceptions" , "Java" );
719- }
720-
721713 /**获取方法的定义
722714 * @param curObj
723715 * @return
@@ -729,13 +721,6 @@ public String getMethodDefinition(@NotNull JSONObject curObj) throws IllegalArgu
729721 // curObj.put("arguments", removeComment(curObj.getString("methodArgs")));
730722 return getMethodDefinition (curObj , "method" , "arguments" , "genericType" , "genericExceptions" , "Java" );
731723 }
732- /**改用 getMethodDefinition
733- */
734- @ Deprecated
735- public String getMethodDefination (@ NotNull JSONObject curObj , String method , String arguments
736- , String type , String exceptions , String language ) throws IllegalArgumentException {
737- return getMethodDefinition (curObj , method , arguments , type , exceptions , language );
738- }
739724 /**获取方法的定义
740725 * @param curObj
741726 * @param method
0 commit comments