Search in sources :

Example 16 with FatalBeanException

use of org.springframework.beans.FatalBeanException in project chassis by Kixeye.

the class WebSocketMessageMappingRegistry method registerWebSocketActions.

@PostConstruct
public void registerWebSocketActions() throws BeansException {
    String[] controllerBeanNames = beanFactory.getBeanNamesForAnnotation(WebSocketController.class);
    if (controllerBeanNames != null && controllerBeanNames.length > 0) {
        try {
            for (String beanName : controllerBeanNames) {
                BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
                Class<?> beanClass = Class.forName(beanDef.getBeanClassName());
                for (Method method : beanClass.getMethods()) {
                    ActionMapping mapping = method.getAnnotation(ActionMapping.class);
                    if (mapping != null) {
                        if (mapping.value() != null && mapping.value().length > 0) {
                            Map<String, String> requirements = new HashMap<>();
                            if (mapping.propertyRequirements() != null) {
                                for (ActionPropertyRequirement requirement : mapping.propertyRequirements()) {
                                    requirements.put(requirement.name(), requirement.value());
                                }
                            }
                            for (String action : mapping.value()) {
                                logger.info("Registering destination [{}] with handler [{}].", action, method.toString());
                                Map<String, WebSocketActionArgumentResolver> argumentResolverBeans = beanFactory.getBeansOfType(WebSocketActionArgumentResolver.class);
                                if (argumentResolverBeans != null && !argumentResolverBeans.isEmpty()) {
                                    logger.info("Registering WebSocketActionArgumentResolver beans {} with action {}", Joiner.on(",").join(argumentResolverBeans.keySet(), action));
                                }
                                actions.put(action, new WebSocketAction(method, requirements, argumentResolverBeans == null ? null : argumentResolverBeans.values().toArray(new WebSocketActionArgumentResolver[argumentResolverBeans.size()])));
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new FatalBeanException("Unable to configure bean", e);
        }
    } else {
        logger.warn("No WebSocketController beans defined.");
    }
}
Also used : HashMap(java.util.HashMap) Method(java.lang.reflect.Method) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) FatalBeanException(org.springframework.beans.FatalBeanException) BeansException(org.springframework.beans.BeansException) FatalBeanException(org.springframework.beans.FatalBeanException) PostConstruct(javax.annotation.PostConstruct)

Example 17 with FatalBeanException

use of org.springframework.beans.FatalBeanException in project hevelian-activemq by Hevelian.

the class WebXBeanBrokerFactory method createApplicationContext.

@Override
protected ApplicationContext createApplicationContext(String uri) throws MalformedURLException {
    Resource resource = Utils.resourceFromString(uri);
    LOG.debug("Using " + resource + " from " + uri);
    try {
        return new ResourceXmlApplicationContext(resource) {

            @Override
            protected ConfigurableEnvironment createEnvironment() {
                return new ReversePropertySourcesStandardServletEnvironment();
            }

            @Override
            protected void initPropertySources() {
                WebApplicationContextUtils.initServletPropertySources(getEnvironment().getPropertySources(), ServletContextHolder.getServletContext());
            }
        };
    } catch (FatalBeanException errorToLog) {
        LOG.error("Failed to load: " + resource + ", reason: " + errorToLog.getLocalizedMessage(), errorToLog);
        throw errorToLog;
    }
}
Also used : ReversePropertySourcesStandardServletEnvironment(com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment) Resource(org.springframework.core.io.Resource) FatalBeanException(org.springframework.beans.FatalBeanException) ResourceXmlApplicationContext(org.apache.xbean.spring.context.ResourceXmlApplicationContext)

Aggregations

FatalBeanException (org.springframework.beans.FatalBeanException)17 Test (org.junit.Test)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 BeansException (org.springframework.beans.BeansException)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ReversePropertySourcesStandardServletEnvironment (com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment)1 ConfigObject (groovy.util.ConfigObject)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 ResourceXmlApplicationContext (org.apache.xbean.spring.context.ResourceXmlApplicationContext)1 BeanInstantiationException (org.springframework.beans.BeanInstantiationException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)1