Example #1
0
  public void injectSpringToContainer() {
    Map<String, Object> consumers = applicationContext.getBeansWithAnnotation(Consumer.class);
    Map<String, Object> components = applicationContext.getBeansWithAnnotation(Component.class);
    Map<String, Object> services = applicationContext.getBeansWithAnnotation(Service.class);

    if (null != consumers) {
      for (Object consumer : consumers.values()) {
        Consumer consumerAnnotation = consumer.getClass().getAnnotation(Consumer.class);
        containerWrapper.registerConsumer(
            consumerAnnotation.value(), consumer.getClass().getName());
        containerWrapper.registerOriginal(consumer.getClass().getName(), consumer);
      }
    }

    if (null != components) {
      for (Object component : components.values()) {
        Method[] methods = component.getClass().getDeclaredMethods();
        for (Method method : methods) {
          if (method.isAnnotationPresent(OnEvent.class)) {
            OnEvent onEvent = method.getAnnotation(OnEvent.class);
            containerWrapper.registerOriginal(component.getClass().getName(), component);

            ConsumerMethodHolder consumerMethodHolder =
                new ConsumerMethodHolder(component.getClass().getName(), method);
            containerWrapper.registerOnEventConsumer(onEvent.value(), consumerMethodHolder);
          }
        }
      }
    }

    if (null != services) {
      for (Object service : services.values()) {
        Method[] methods = service.getClass().getDeclaredMethods();
        for (Method method : methods) {
          if (method.isAnnotationPresent(OnEvent.class)) {
            OnEvent onEvent = method.getAnnotation(OnEvent.class);
            containerWrapper.registerOriginal(service.getClass().getName(), service);

            ConsumerMethodHolder consumerMethodHolder =
                new ConsumerMethodHolder(service.getClass().getName(), method);
            containerWrapper.registerOnEventConsumer(onEvent.value(), consumerMethodHolder);
          }
        }
      }
    }
  }
 @Autowired
 public void setApplicationContext(final ApplicationContext applicationContext) {
   final Map<String, Object> controllerBeans =
       applicationContext.getBeansWithAnnotation(Controller.class);
   controllerTypes = new HashSet<Class<?>>();
   for (Object o : controllerBeans.values()) {
     controllerTypes.add(o.getClass());
   }
   LOG.info("Found {} controllers in application context", controllerTypes.size());
 }
Example #3
0
 /*
  * 得到application context,在其中获得加了RpcProvider注解的beans,beans上加的注解value值为interfaceName
  */
 public void setApplicationContext(ApplicationContext ctx) throws BeansException {
   Map<String, Object> beanMap = ctx.getBeansWithAnnotation(RpcProvider.class);
   if (!beanMap.isEmpty()) {
     for (Object bean : beanMap.values()) {
       String interfaceName = bean.getClass().getAnnotation(RpcProvider.class).value().getName();
       System.out.println("interfaceName: " + interfaceName);
       exportClassMap.put(interfaceName, bean);
     }
   }
 }
Example #4
0
  public void start() {

    ResteasyDeployment dp = new ResteasyDeployment();

    Collection<Object> providers = ac.getBeansWithAnnotation(Provider.class).values();
    Collection<Object> controllers = ac.getBeansWithAnnotation(Controller.class).values();

    Assert.notEmpty(controllers);

    // extract providers
    if (providers != null) {
      dp.getProviders().addAll(providers);
    }
    // extract only controller annotated beans
    dp.getResources().addAll(controllers);

    netty = new ConfigurableNettyJaxrsServer();
    netty.initBootstrap().setOption("reuseAddress", true);
    netty.setDeployment(dp);
    netty.setPort(port);
    netty.setRootResourcePath(rootResourcePath);
    netty.setSecurityDomain(null);
    netty.start();
  }
Example #5
0
  public void scanAndPopulate(ApiActionHolder holder) throws ApiException {
    Map<String, Object> beans = context.getBeansWithAnnotation(ApiController.class);

    for (Object bean : beans.values()) {
      ApiController annotation = bean.getClass().getAnnotation(ApiController.class);
      final String controllerName = annotation.value();

      if (StringUtils.isEmpty(controllerName)) {
        throw new ApiException("Controller name not found on bean " + bean.getClass().getName());
      }

      final List<Method> actions = extractActions(bean);
      if (actions.size() > 0) {
        buildAndAddActions(bean, controllerName, actions, holder);
      }
    }
  }
Example #6
0
 public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> arg0)
     throws BeansException {
   return applicationContext.getBeansWithAnnotation(arg0);
 }
 @Override
 public Set<String> getServices() {
   return applicationContext.getBeansWithAnnotation(ServiceActor.class).keySet();
 }