Search in sources :

Example 36 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-integration by spring-projects.

the class DslScriptExecutingMessageProcessor method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    if (StringUtils.hasText(this.location)) {
        this.script = this.applicationContext.getResource(this.location);
    }
    ScriptSource scriptSource = new RefreshableResourceScriptSource(this.script, this.refreshCheckDelay);
    if (!StringUtils.hasText(this.lang)) {
        String filename = this.script.getFilename();
        int index = filename.lastIndexOf(".") + 1;
        if (index < 1) {
            throw new BeanCreationException("'lang' isn't provided and there is 'file extension' for script " + "resource: " + this.script);
        }
        this.lang = filename.substring(index);
    }
    if (this.applicationContext.containsBean(ScriptExecutingProcessorFactory.BEAN_NAME)) {
        ScriptExecutingProcessorFactory processorFactory = this.applicationContext.getBean(ScriptExecutingProcessorFactory.BEAN_NAME, ScriptExecutingProcessorFactory.class);
        this.delegate = processorFactory.createMessageProcessor(this.lang, scriptSource, this.variableGenerator);
    } else {
        this.delegate = new ScriptExecutingMessageProcessor(scriptSource, this.variableGenerator, ScriptExecutorFactory.getScriptExecutor(this.lang));
    }
    this.delegate.setBeanFactory(this.applicationContext);
    this.delegate.setBeanClassLoader(this.applicationContext.getClassLoader());
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) RefreshableResourceScriptSource(org.springframework.integration.scripting.RefreshableResourceScriptSource) ScriptExecutingProcessorFactory(org.springframework.integration.scripting.config.ScriptExecutingProcessorFactory) ScriptSource(org.springframework.scripting.ScriptSource) RefreshableResourceScriptSource(org.springframework.integration.scripting.RefreshableResourceScriptSource) AbstractScriptExecutingMessageProcessor(org.springframework.integration.scripting.AbstractScriptExecutingMessageProcessor) ScriptExecutingMessageProcessor(org.springframework.integration.scripting.jsr223.ScriptExecutingMessageProcessor)

Example 37 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-integration by spring-projects.

the class ConsoleOutboundChannelAdapterParserTests method stdoutAdapterWithInvalidCharset.

@Test
public void stdoutAdapterWithInvalidCharset() {
    BeanCreationException beanCreationException = null;
    try {
        new ClassPathXmlApplicationContext("invalidConsoleOutboundChannelAdapterParserTests.xml", ConsoleOutboundChannelAdapterParserTests.class).close();
    } catch (BeanCreationException e) {
        beanCreationException = e;
    }
    Throwable rootCause = beanCreationException.getRootCause();
    assertEquals(UnsupportedEncodingException.class, rootCause.getClass());
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 38 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-integration by spring-projects.

the class ConsoleInboundChannelAdapterParserTests method testConsoleSourceWithInvalidCharset.

@Test
public void testConsoleSourceWithInvalidCharset() {
    BeanCreationException beanCreationException = null;
    try {
        new ClassPathXmlApplicationContext("invalidConsoleInboundChannelAdapterParserTests.xml", ConsoleInboundChannelAdapterParserTests.class).close();
    } catch (BeanCreationException e) {
        beanCreationException = e;
    }
    Throwable rootCause = beanCreationException.getRootCause();
    assertEquals(UnsupportedEncodingException.class, rootCause.getClass());
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 39 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-integration by spring-projects.

the class SyslogReceivingChannelAdapterParserTests method testUdpChildWithTcp.

@Test
public void testUdpChildWithTcp() {
    try {
        new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail3-context.xml", this.getClass()).close();
        fail("Expected exception");
    } catch (BeanCreationException e) {
        e.printStackTrace();
        assertEquals("Cannot specify 'udp-attributes' when the protocol is 'tcp'", e.getCause().getMessage());
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 40 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-integration by spring-projects.

the class DefaultSftpSessionFactory method initJschSession.

private com.jcraft.jsch.Session initJschSession() throws Exception {
    if (this.port <= 0) {
        this.port = 22;
    }
    if (StringUtils.hasText(this.knownHosts)) {
        this.jsch.setKnownHosts(this.knownHosts);
    }
    // private key
    if (this.privateKey != null) {
        byte[] keyByteArray = StreamUtils.copyToByteArray(this.privateKey.getInputStream());
        String passphrase = this.userInfoWrapper.getPassphrase();
        if (StringUtils.hasText(passphrase)) {
            this.jsch.addIdentity(this.user, keyByteArray, null, passphrase.getBytes());
        } else {
            this.jsch.addIdentity(this.user, keyByteArray, null, null);
        }
    }
    com.jcraft.jsch.Session jschSession = this.jsch.getSession(this.user, this.host, this.port);
    if (this.sessionConfig != null) {
        jschSession.setConfig(this.sessionConfig);
    }
    String password = this.userInfoWrapper.getPassword();
    if (StringUtils.hasText(password)) {
        jschSession.setPassword(password);
    }
    jschSession.setUserInfo(this.userInfoWrapper);
    try {
        if (this.proxy != null) {
            jschSession.setProxy(this.proxy);
        }
        if (this.socketFactory != null) {
            jschSession.setSocketFactory(this.socketFactory);
        }
        if (this.timeout != null) {
            jschSession.setTimeout(this.timeout);
        }
        if (StringUtils.hasText(this.clientVersion)) {
            jschSession.setClientVersion(this.clientVersion);
        }
        if (StringUtils.hasText(this.hostKeyAlias)) {
            jschSession.setHostKeyAlias(this.hostKeyAlias);
        }
        if (this.serverAliveInterval != null) {
            jschSession.setServerAliveInterval(this.serverAliveInterval);
        }
        if (this.serverAliveCountMax != null) {
            jschSession.setServerAliveCountMax(this.serverAliveCountMax);
        }
        if (this.enableDaemonThread != null) {
            jschSession.setDaemonThread(this.enableDaemonThread);
        }
    } catch (Exception e) {
        throw new BeanCreationException("Attempt to set additional properties of " + "the com.jcraft.jsch.Session resulted in error: " + e.getMessage(), e);
    }
    return jschSession;
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) JSchException(com.jcraft.jsch.JSchException)

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