Search in sources :

Example 26 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project com.revolsys.open by revolsys.

the class ProcessorPipelineTool method processFile.

private void processFile(final File sourceFile, final File targetFile, final File logFile) {
    final long startTime = System.currentTimeMillis();
    if (this.excludePattern != null) {
        try {
            if (sourceFile.getCanonicalPath().matches(this.excludePattern)) {
                return;
            }
        } catch (final IOException e) {
            log.error(e.getMessage(), e);
        }
    }
    final ThreadLocalFileAppender localAppender = ThreadLocalFileAppender.getAppender();
    if (localAppender != null) {
        final File parentFile = logFile.getParentFile();
        if (parentFile != null) {
            parentFile.mkdirs();
        }
        localAppender.setLocalFile(logFile.getAbsolutePath());
    }
    log.info("Processing file '" + sourceFile + "' to '" + targetFile + "'");
    System.out.println("Processing file '" + sourceFile + "' to '" + targetFile + "'");
    System.setProperty("sourceFile", sourceFile.getAbsolutePath());
    System.setProperty("targetFile", targetFile.getAbsolutePath());
    final BeanFactory beans = new FileSystemXmlApplicationContext("file:" + this.scriptFile.getAbsolutePath());
    try {
        final File parentFile = targetFile.getParentFile();
        if (parentFile != null) {
            parentFile.mkdirs();
        }
        final Object bean = beans.getBean("pipeline");
        final ProcessNetwork pipeline = (ProcessNetwork) bean;
        pipeline.startAndWait();
    } catch (final BeanCreationException e) {
        final Throwable cause = getBeanExceptionCause(e);
        cause.printStackTrace();
    }
    final long endTime = System.currentTimeMillis();
    final long time = endTime - startTime;
    long seconds = time / 1000;
    final long minutes = seconds / 60;
    seconds = seconds % 60;
    log.info(minutes + " minutes " + seconds + " seconds");
    System.out.println(minutes + " minutes " + seconds + " seconds");
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) BeanCreationException(org.springframework.beans.factory.BeanCreationException) ThreadLocalFileAppender(com.revolsys.logging.log4j.ThreadLocalFileAppender) ProcessNetwork(com.revolsys.parallel.process.ProcessNetwork) BeanFactory(org.springframework.beans.factory.BeanFactory) IOException(java.io.IOException) File(java.io.File)

Example 27 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project com.revolsys.open by revolsys.

the class ScriptExecutorRunnable method getBeanExceptionCause.

private static Throwable getBeanExceptionCause(final BeanCreationException e) {
    Throwable cause = e.getCause();
    while (cause instanceof BeanCreationException || cause instanceof MethodInvocationException || cause instanceof PropertyAccessException || cause instanceof PropertyBatchUpdateException || cause instanceof InvalidPropertyException) {
        Throwable newCause;
        if (cause instanceof PropertyBatchUpdateException) {
            final PropertyBatchUpdateException batchEx = (PropertyBatchUpdateException) cause;
            newCause = batchEx.getPropertyAccessExceptions()[0];
        } else {
            newCause = cause.getCause();
        }
        if (newCause != null) {
            cause = newCause;
        } else {
            return cause;
        }
    }
    return cause;
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) PropertyBatchUpdateException(org.springframework.beans.PropertyBatchUpdateException) InvalidPropertyException(org.springframework.beans.InvalidPropertyException) PropertyAccessException(org.springframework.beans.PropertyAccessException) MethodInvocationException(org.springframework.beans.MethodInvocationException)

Example 28 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project com.revolsys.open by revolsys.

the class ScriptExecutorRunnable method runDo.

@Override
public void runDo() {
    final long startTime = System.currentTimeMillis();
    try {
        String logPath = null;
        final String logFileName = (String) this.attributes.get("logFile");
        if (logFileName != null && logFileName.trim().length() > 0) {
            final File logFile = new File(logFileName);
            final File parentFile = logFile.getParentFile();
            if (parentFile != null) {
                parentFile.mkdirs();
            }
            logPath = logFile.getAbsolutePath();
            ThreadLocalFileAppender.getAppender().setLocalFile(logPath);
        }
        if (this.logScriptInfo) {
            final StringBuilder message = new StringBuilder("Processing ");
            message.append(" -s ");
            message.append(this.script);
            if (logPath != null) {
                message.append(" -l ");
                message.append(logPath);
            }
            for (final Entry<String, Object> parameter : this.attributes.entrySet()) {
                message.append(" ");
                message.append(parameter.getKey());
                message.append("=");
                message.append(parameter.getValue());
            }
            Logs.info(this, message.toString());
        }
        ThreadSharedProperties.setProperties(this.attributes);
        final GenericApplicationContext applicationContext = new GenericApplicationContext();
        applicationContext.getBeanFactory().addPropertyEditorRegistrar(new ResourceEditorRegistrar());
        for (final Entry<String, Object> entry : this.beans.entrySet()) {
            final String key = entry.getKey();
            if (key.indexOf('.') == -1 && key.indexOf('[') == -1) {
                final Object value = entry.getValue();
                final GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
                beanDefinition.setBeanClass(Parameter.class);
                final MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
                propertyValues.add("type", value.getClass());
                propertyValues.add("value", value);
                applicationContext.registerBeanDefinition(key, beanDefinition);
            }
        }
        final XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(applicationContext);
        if (new File(this.script).exists()) {
            beanReader.loadBeanDefinitions("file:" + this.script);
        } else {
            beanReader.loadBeanDefinitions("classpath:" + this.script);
        }
        applicationContext.refresh();
        try {
            final Object bean = applicationContext.getBean("processNetwork");
            final ProcessNetwork pipeline = (ProcessNetwork) bean;
            pipeline.startAndWait();
        } finally {
            applicationContext.close();
            System.gc();
        }
    } catch (final BeanCreationException e) {
        final Throwable cause = getBeanExceptionCause(e);
        Logs.error(this, cause.getMessage(), cause);
        System.err.println(cause.getMessage());
        System.err.flush();
    } catch (final Throwable t) {
        Logs.error(this, t.getMessage(), t);
    }
    if (this.logScriptInfo) {
        final long endTime = System.currentTimeMillis();
        final long time = endTime - startTime;
        long seconds = time / 1000;
        final long minutes = seconds / 60;
        seconds = seconds % 60;
        Logs.info(this, minutes + " minutes " + seconds + " seconds");
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ResourceEditorRegistrar(com.revolsys.beans.propertyeditor.ResourceEditorRegistrar) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ProcessNetwork(com.revolsys.parallel.process.ProcessNetwork) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) File(java.io.File)

Example 29 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project com.revolsys.open by revolsys.

the class ScriptTool method getBeanExceptionCause.

private static Throwable getBeanExceptionCause(final BeanCreationException e) {
    Throwable cause = e.getCause();
    if (cause == null) {
        return e;
    }
    while (cause instanceof BeanCreationException || cause instanceof MethodInvocationException || cause instanceof PropertyAccessException || cause instanceof PropertyBatchUpdateException || cause instanceof InvalidPropertyException) {
        Throwable newCause;
        if (cause instanceof PropertyBatchUpdateException) {
            final PropertyBatchUpdateException batchEx = (PropertyBatchUpdateException) cause;
            newCause = batchEx.getPropertyAccessExceptions()[0];
        } else {
            newCause = cause.getCause();
        }
        if (newCause != null) {
            cause = newCause;
        } else {
            return cause;
        }
    }
    return cause;
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) PropertyBatchUpdateException(org.springframework.beans.PropertyBatchUpdateException) InvalidPropertyException(org.springframework.beans.InvalidPropertyException) PropertyAccessException(org.springframework.beans.PropertyAccessException) MethodInvocationException(org.springframework.beans.MethodInvocationException)

Example 30 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project nakadi by zalando.

the class PluginsConfig method authorizationService.

@Bean
public AuthorizationService authorizationService(@Value("${nakadi.plugins.authz.factory}") final String factoryName, final SystemProperties systemProperties, final DefaultResourceLoader loader) {
    try {
        LOGGER.info("Initialize per-resource authorization service factory: " + factoryName);
        final Class<AuthorizationServiceFactory> factoryClass = (Class<AuthorizationServiceFactory>) loader.getClassLoader().loadClass(factoryName);
        final AuthorizationServiceFactory factory = factoryClass.newInstance();
        return factory.init(systemProperties);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        throw new BeanCreationException("Can't create AuthorizationService " + factoryName, e);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) AuthorizationServiceFactory(org.zalando.nakadi.plugin.api.authz.AuthorizationServiceFactory) Bean(org.springframework.context.annotation.Bean)

Aggregations

BeanCreationException (org.springframework.beans.factory.BeanCreationException)133 Test (org.junit.Test)30 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)18 BeansException (org.springframework.beans.BeansException)16 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 IOException (java.io.IOException)12 Map (java.util.Map)12 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 Test (org.junit.jupiter.api.Test)11 HashMap (java.util.HashMap)9 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)9 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)8 ArrayList (java.util.ArrayList)7 PostConstruct (javax.annotation.PostConstruct)7 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)7 Bean (org.springframework.context.annotation.Bean)7 HasId (org.apache.camel.spi.HasId)6 BeanCurrentlyInCreationException (org.springframework.beans.factory.BeanCurrentlyInCreationException)6 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)6 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5