1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| protected Object doInvoke(ApiParam param, HttpServletRequest request, HttpServletResponse response) throws Throwable { ApiDefinition apiDefinition = this.getApiDefinition(param); ApiContext.setApiMeta(apiDefinition); if (!apiDefinition.isIgnoreJWT()) { this.initJwtInfo(request, param); } Object methodArgu = null; Object invokeResult = null; Validator validator = ApiContext.getApiConfig().getValidator(); param.setIgnoreSign(apiDefinition.isIgnoreSign()); param.setIgnoreValidate(apiDefinition.isIgnoreValidate()); validator.validate(param); String busiJsonData = ApiContext.getApiConfig().getDataDecoder().decode(param); Class<?> arguClass = apiDefinition.getMethodArguClass(); boolean isSingleParameter = apiDefinition.isSingleParameter(); Object singleParamProxy = null; int interceptorIndex = 0; try { if (arguClass != null) { if(arguClass == JSONObject.class) { methodArgu = JSON.parseObject(busiJsonData); } else if(arguClass == Map.class) { methodArgu = new HashMap<String,Object>(JSON.parseObject(busiJsonData)); } else if(isSingleParameter) { SingleParameterContext.SingleParameterContextValue value = SingleParameterContext.get(param.fatchName(), param.fatchVersion()); if (value != null) { JSONObject jsonObj = JSON.parseObject(busiJsonData); methodArgu = jsonObj.getObject(value.getParamName(), arguClass); singleParamProxy = jsonObj.toJavaObject(value.getWrapClass()); } } else { methodArgu = JSON.parseObject(busiJsonData, arguClass); } this.bindUploadFile(methodArgu); } ApiInterceptor[] interceptors = ApiContext.getApiConfig().getInterceptors(); if(interceptors == null) { interceptors = EMPTY_INTERCEPTOR_ARRAY; } for (int i = 0; i < interceptors.length; i++) { ApiInterceptor interceptor = interceptors[i]; if (interceptor.match(apiDefinition) && !interceptor.preHandle(request, response, apiDefinition.getHandler(),methodArgu)) { triggerAfterCompletion(apiDefinition, interceptorIndex, request, response, methodArgu, null,null); return null; } interceptorIndex = i; } this.validateBizArgu(validator, methodArgu, singleParamProxy); MethodCaller methodCaller = apiDefinition.getMethodCaller(); if (methodCaller != null) { invokeResult = methodCaller.call(new ApiInvocation(apiDefinition, methodArgu)); } else { invokeResult = Callers.call(apiDefinition, methodArgu); } for (int i = interceptors.length - 1; i >= 0; i--) { ApiInterceptor interceptor = interceptors[i]; if(interceptor.match(apiDefinition)) { interceptor.postHandle(request, response, apiDefinition.getHandler(), methodArgu, invokeResult); } } if(invokeResult == null) { invokeResult = EMPTY_OBJECT; } Object finalReturn = this.wrapResult(apiDefinition, invokeResult); setMsg(finalReturn); triggerAfterCompletion(apiDefinition, interceptorIndex, request, response, methodArgu, finalReturn, null); return finalReturn; } catch (Exception e) { this.triggerAfterCompletion(apiDefinition, interceptorIndex, request, response, methodArgu, invokeResult, e); throw e; } }
|