Ejemplo n.º 1
0
 private Object getIvnokeParams(Class<?> paramClass, Annotation[] paramAnno) {
   for (Annotation pAnno : paramAnno) {
     if (pAnno instanceof AttributeParam)
       return this.getAttributeParam(paramClass, (AttributeParam) pAnno);
     else if (pAnno instanceof CookieParam)
       return this.getCookieParam(paramClass, (CookieParam) pAnno);
     else if (pAnno instanceof HeaderParam)
       return this.getHeaderParam(paramClass, (HeaderParam) pAnno);
     else if (pAnno instanceof QueryParam)
       return this.getQueryParam(paramClass, (QueryParam) pAnno);
     else if (pAnno instanceof PathParam) return this.getPathParam(paramClass, (PathParam) pAnno);
   }
   return BeanUtils.getDefaultValue(paramClass);
 }
Ejemplo n.º 2
0
 private Object[] getParams(
     HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
   Class<?>[] targetParamClass = this.targetMethod.getParameterTypes();
   Annotation[][] targetParamAnno = this.targetMethod.getParameterAnnotations();
   targetParamClass = (targetParamClass == null) ? new Class<?>[0] : targetParamClass;
   targetParamAnno = (targetParamAnno == null) ? new Annotation[0][0] : targetParamAnno;
   ArrayList<Object> paramsArray = new ArrayList<Object>();
   /*准备参数*/
   for (int i = 0; i < targetParamClass.length; i++) {
     Class<?> paramClass = targetParamClass[i];
     Object paramObject = this.getIvnokeParams(paramClass, targetParamAnno[i]); // 获取参数
     /*获取到的参数需要做一个类型转换,以防止method.invoke时发生异常。*/
     if (paramObject == null) paramObject = BeanUtils.getDefaultValue(paramClass);
     else paramObject = ConverterUtils.convert(paramClass, paramObject);
     paramsArray.add(paramObject);
   }
   Object[] invokeParams = paramsArray.toArray();
   return invokeParams;
 }
Ejemplo n.º 3
0
 /** 准备参数 */
 public Object[] prepareParams() throws Throwable {
   Method targetMethod = this.define.getTargetMethod();
   Class<?>[] targetParamClass = targetMethod.getParameterTypes();
   Annotation[][] targetParamAnno = targetMethod.getParameterAnnotations();
   targetParamClass = (targetParamClass == null) ? new Class<?>[0] : targetParamClass;
   targetParamAnno = (targetParamAnno == null) ? new Annotation[0][0] : targetParamAnno;
   ArrayList<Object> paramsArray = new ArrayList<Object>();
   /*准备参数*/
   for (int i = 0; i < targetParamClass.length; i++) {
     Class<?> paramClass = targetParamClass[i];
     Object paramObject = this.getIvnokeParams(paramClass, targetParamAnno[i]); // 获取参数
     /*获取到的参数需要做一个类型转换,以防止method.invoke时发生异常。*/
     if (paramObject == null) paramObject = BeanUtils.getDefaultValue(paramClass);
     else paramObject = ConverterUtils.convert(paramClass, paramObject);
     paramsArray.add(paramObject);
   }
   Object[] invokeParams = paramsArray.toArray();
   return invokeParams;
 }