Пример #1
0
 @Override
 public void addServiceMethod(
     String methodName, String version, ServiceMethodHandler serviceMethodHandler) {
   serviceMethods.add(methodName);
   serviceHandlerMap.put(
       ServiceMethodHandler.methodWithVersion(methodName, version), serviceMethodHandler);
 }
Пример #2
0
  /**
   * 检查上下文中的BOP服务方法
   *
   * @throws org.springframework.beans.BeansException
   */
  private void registerFromContext(final ApplicationContext context) throws BeansException {
    if (logger.isDebugEnabled()) {
      logger.debug("对Spring上下文中的Bean进行扫描,查找ROP服务方法: " + context);
    }
    String[] beanNames = context.getBeanNamesForType(Object.class);
    for (final String beanName : beanNames) {
      Class<?> handlerType = context.getType(beanName);
      ReflectionUtils.doWithMethods(
          handlerType,
          new ReflectionUtils.MethodCallback() {
            public void doWith(Method method)
                throws IllegalArgumentException, IllegalAccessException {
              ReflectionUtils.makeAccessible(method);

              ServiceMethod serviceMethod = method.getAnnotation(ServiceMethod.class);
              ServiceMethodGroup serviceMethodGroup =
                  method.getDeclaringClass().getAnnotation(ServiceMethodGroup.class);

              ServiceMethodDefinition definition = null;
              if (serviceMethodGroup != null) {
                definition = buildServiceMethodDefinition(serviceMethodGroup, serviceMethod);
              } else {
                definition = buildServiceMethodDefinition(serviceMethod);
              }
              ServiceMethodHandler serviceMethodHandler = new ServiceMethodHandler();
              serviceMethodHandler.setServiceMethodDefinition(definition);

              // 1.set handler
              serviceMethodHandler.setHandler(context.getBean(beanName)); // handler
              serviceMethodHandler.setHandlerMethod(method); // handler'method
              if (method.getParameterTypes().length > 0) { // handler method's parameter
                Class<?> aClass = method.getParameterTypes()[0];
                Assert.isAssignable(RopRequest.class, aClass, "@ServiceMethod方法入参必须是RopRequest");
                serviceMethodHandler.setRequestType((Class<? extends RopRequest>) aClass);
              }

              // 2.set sign fieldNames
              serviceMethodHandler.setIgnoreSignFieldNames(
                  getIgnoreSignFieldNames(serviceMethodHandler.getRequestType()));

              addServiceMethod(
                  serviceMethod.value(), serviceMethod.version(), serviceMethodHandler);

              if (logger.isDebugEnabled()) {
                logger.debug(
                    "注册服务方法:"
                        + method.getDeclaringClass().getCanonicalName()
                        + "#"
                        + method.getName()
                        + "(..)");
              }
            }
          },
          new ReflectionUtils.MethodFilter() {
            public boolean matches(Method method) {
              return AnnotationUtils.findAnnotation(method, ServiceMethod.class) != null;
            }
          });
    }
    if (context.getParent() != null) {
      registerFromContext(context.getParent());
    }
    if (logger.isInfoEnabled()) {
      logger.info("共注册了" + serviceHandlerMap.size() + "个服务方法");
    }
  }
Пример #3
0
 @Override
 public boolean isValidMethodVersion(String methodName, String version) {
   return serviceHandlerMap.containsKey(
       ServiceMethodHandler.methodWithVersion(methodName, version));
 }
Пример #4
0
 @Override
 public ServiceMethodHandler getServiceMethodHandler(String methodName, String version) {
   return serviceHandlerMap.get(ServiceMethodHandler.methodWithVersion(methodName, version));
 }