@Test public void testBusinessActionContext() throws NoSuchMethodException { Method prepareMethod = TccAction.class.getDeclaredMethod("prepare", BusinessActionContext.class, int.class, List.class, TccParam.class); List list = new ArrayList(); list.add("b"); TccParam tccParam = new TccParam (1, "abc@ali.com"); Map<String, Object> paramContext = actionInterceptorHandler.fetchActionRequestContext(prepareMethod, new Object[]{null, 10, list, tccParam}); System.out.println(paramContext); Assertions.assertEquals(10, paramContext.get("a")); Assertions.assertEquals("b", paramContext.get("b")); Assertions.assertEquals("abc@ali.com", paramContext.get("email")); }
protected Map<String, Object> fetchActionRequestContext(Method method, Object[] arguments) { Map<String, Object> context = new HashMap<String, Object>(8); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { for (int j = 0; j < parameterAnnotations[i].length; j++) { if (parameterAnnotations[i][j] instanceof BusinessActionContextParameter) { BusinessActionContextParameter param = (BusinessActionContextParameter)parameterAnnotations[i][j]; if (null == arguments[i]) { throw new IllegalArgumentException("@BusinessActionContextParameter 's params can not null"); } Object paramObject = arguments[i]; int index = param.index(); if (index >= 0) { Object targetParam = ((List<Object>)paramObject).get(index); if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(targetParam)); } else { context.put(param.paramName(), targetParam); } } else { if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(paramObject)); } else { context.put(param.paramName(), paramObject); } } } } } return context; }
ActionInterceptorHandler { protected Map<String, Object> fetchActionRequestContext(Method method, Object[] arguments) { Map<String, Object> context = new HashMap<String, Object>(8); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { for (int j = 0; j < parameterAnnotations[i].length; j++) { if (parameterAnnotations[i][j] instanceof BusinessActionContextParameter) { BusinessActionContextParameter param = (BusinessActionContextParameter)parameterAnnotations[i][j]; if (null == arguments[i]) { throw new IllegalArgumentException("@BusinessActionContextParameter 's params can not null"); } Object paramObject = arguments[i]; int index = param.index(); if (index >= 0) { Object targetParam = ((List<Object>)paramObject).get(index); if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(targetParam)); } else { context.put(param.paramName(), targetParam); } } else { if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(paramObject)); } else { context.put(param.paramName(), paramObject); } } } } } return context; } }
ActionInterceptorHandler { protected Map<String, Object> fetchActionRequestContext(Method method, Object[] arguments) { Map<String, Object> context = new HashMap<String, Object>(8); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { for (int j = 0; j < parameterAnnotations[i].length; j++) { if (parameterAnnotations[i][j] instanceof BusinessActionContextParameter) { BusinessActionContextParameter param = (BusinessActionContextParameter)parameterAnnotations[i][j]; if (null == arguments[i]) { throw new IllegalArgumentException("@BusinessActionContextParameter 's params can not null"); } Object paramObject = arguments[i]; int index = param.index(); if (index >= 0) { Object targetParam = ((List<Object>)paramObject).get(index); if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(targetParam)); } else { context.put(param.paramName(), targetParam); } } else { if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(paramObject)); } else { context.put(param.paramName(), paramObject); } } } } } return context; }  }
ActionInterceptorHandler { protected Map<String, Object> fetchActionRequestContext(Method method, Object[] arguments) { Map<String, Object> context = new HashMap<String, Object>(8); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { for (int j = 0; j < parameterAnnotations[i].length; j++) { if (parameterAnnotations[i][j] instanceof BusinessActionContextParameter) { BusinessActionContextParameter param = (BusinessActionContextParameter)parameterAnnotations[i][j]; if (null == arguments[i]) { throw new IllegalArgumentException("@BusinessActionContextParameter 's params can not null"); } Object paramObject = arguments[i]; int index = param.index(); if (index >= 0) { Object targetParam = ((List<Object>)paramObject).get(index); if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(targetParam)); } else { context.put(param.paramName(), targetParam); } } else { if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(paramObject)); } else { context.put(param.paramName(), paramObject); } } } } } return context; }  Map<String, Object> proceed(Method method, Object[] arguments, String xid, TwoPhaseBusinessAction businessAction,
                                       Callback<Object> targetCallback); }
ActionInterceptorHandler { protected Map<String, Object> fetchActionRequestContext(Method method, Object[] arguments) { Map<String, Object> context = new HashMap<String, Object>(8); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { for (int j = 0; j < parameterAnnotations[i].length; j++) { if (parameterAnnotations[i][j] instanceof BusinessActionContextParameter) { BusinessActionContextParameter param = (BusinessActionContextParameter)parameterAnnotations[i][j]; if (null == arguments[i]) { throw new IllegalArgumentException("@BusinessActionContextParameter 's params can not null"); } Object paramObject = arguments[i]; int index = param.index(); if (index >= 0) { Object targetParam = ((List<Object>)paramObject).get(index); if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(targetParam)); } else { context.put(param.paramName(), targetParam); } } else { if (param.isParamInProperty()) { context.putAll(ActionContextUtil.fetchContextFromObject(paramObject)); } else { context.put(param.paramName(), paramObject); } } } } } return context; }  Map<String, Object> proceed(Method method, Object[] arguments, String xid, TwoPhaseBusinessAction businessAction,
                                       Callback<Object> targetCallback);  }