示例#1
0
 public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
   String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
   if (ConfigUtils.isNotEmpty(token)) {
     Class<?> serviceType = invoker.getInterface();
     Map<String, String> attachments = inv.getAttachments();
     String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
     if (!token.equals(remoteToken)) {
       throw new RpcException(
           "Invalid token! Forbid invoke remote service "
               + serviceType
               + " method "
               + inv.getMethodName()
               + "() from consumer "
               + RpcContext.getContext().getRemoteHost()
               + " to provider "
               + RpcContext.getContext().getLocalHost());
     }
   }
   return invoker.invoke(inv);
 }