Exemple #1
0
 public static Object[] getArguments(Invocation invocation) {
   if (Constants.$INVOKE.equals(invocation.getMethodName())
       && invocation.getArguments() != null
       && invocation.getArguments().length > 2
       && invocation.getArguments()[2] instanceof Object[]) {
     return (Object[]) invocation.getArguments()[2];
   }
   return invocation.getArguments();
 }
Exemple #2
0
 public static String getMethodName(Invocation invocation) {
   if (Constants.$INVOKE.equals(invocation.getMethodName())
       && invocation.getArguments() != null
       && invocation.getArguments().length > 0
       && invocation.getArguments()[0] instanceof String) {
     return (String) invocation.getArguments()[0];
   }
   return invocation.getMethodName();
 }
Exemple #3
0
 public static Class<?>[] getParameterTypes(Invocation invocation) {
   if (Constants.$INVOKE.equals(invocation.getMethodName())
       && invocation.getArguments() != null
       && invocation.getArguments().length > 1
       && invocation.getArguments()[1] instanceof String[]) {
     String[] types = (String[]) invocation.getArguments()[1];
     if (types == null) {
       return new Class<?>[0];
     }
     Class<?>[] parameterTypes = new Class<?>[types.length];
     for (int i = 0; i < types.length; i++) {
       parameterTypes[i] = ReflectUtils.forName(types[0]);
     }
     return parameterTypes;
   }
   return invocation.getParameterTypes();
 }
Exemple #4
0
 public static boolean isOneway(URL url, Invocation inv) {
   boolean isOneway;
   // 如果Java代码中设置优先.
   if (Boolean.FALSE.toString().equals(inv.getAttachment(Constants.RETURN_KEY))) {
     isOneway = true;
   } else {
     isOneway = !url.getMethodParameter(getMethodName(inv), Constants.RETURN_KEY, true);
   }
   return isOneway;
 }
Exemple #5
0
 public static boolean isAsync(URL url, Invocation inv) {
   boolean isAsync;
   // 如果Java代码中设置优先.
   if (Boolean.TRUE.toString().equals(inv.getAttachment(Constants.ASYNC_KEY))) {
     isAsync = true;
   } else {
     isAsync = url.getMethodParameter(getMethodName(inv), Constants.ASYNC_KEY, false);
   }
   return isAsync;
 }
Exemple #6
0
 public static Type[] getReturnTypes(Invocation invocation) {
   try {
     if (invocation != null
         && invocation.getInvoker() != null
         && invocation.getInvoker().getUrl() != null
         && !invocation.getMethodName().startsWith("$")) {
       String service = invocation.getInvoker().getUrl().getServiceInterface();
       if (service != null && service.length() > 0) {
         Class<?> cls = ReflectUtils.forName(service);
         Method method = cls.getMethod(invocation.getMethodName(), invocation.getParameterTypes());
         if (method.getReturnType() == void.class) {
           return null;
         }
         return new Type[] {method.getReturnType(), method.getGenericReturnType()};
       }
     }
   } catch (Throwable t) {
     logger.warn(t.getMessage(), t);
   }
   return null;
 }
Exemple #7
0
 private static boolean isAttachInvocationId(URL url, Invocation invocation) {
   String value =
       url.getMethodParameter(invocation.getMethodName(), Constants.AUTO_ATTACH_INVOCATIONID_KEY);
   if (value == null) {
     // 异步操作默认添加invocationid
     return isAsync(url, invocation);
   } else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
     // 设置为添加,则一定添加
     return true;
   } else {
     // value为false时,不添加
     return false;
   }
 }
Exemple #8
0
 public static Long getInvocationId(Invocation inv) {
   String id = inv.getAttachment(Constants.ID_KEY);
   return id == null ? null : new Long(id);
 }