Search in sources :

Example 26 with BeansException

use of org.springframework.beans.BeansException in project Asqatasun by Asqatasun.

the class AsqatasunCrawlJob method startContext.

/**
     * Start the context, catching and reporting any BeansExceptions.
     */
private void startContext(CrawlJob crawlJob) {
    LOGGER.debug("Starting context");
    PathSharingContext ac = crawlJob.getJobContext();
    ac.addApplicationListener(this);
    try {
        ac.start();
    } catch (BeansException be) {
        LOGGER.warn(be.getMessage());
        ac.close();
    } catch (Exception e) {
        LOGGER.warn(e.getMessage());
        try {
            ac.close();
        } catch (Exception e2) {
            e2.printStackTrace(System.err);
        } finally {
        }
    }
    LOGGER.debug("Context started");
}
Also used : PathSharingContext(org.archive.spring.PathSharingContext) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) CrawlerException(org.asqatasun.crawler.exception.CrawlerException) BeansException(org.springframework.beans.BeansException)

Example 27 with BeansException

use of org.springframework.beans.BeansException in project ignite by apache.

the class GridAbstractTest method loadConfiguration.

/**
     * Loads configuration from the given Spring XML file.
     *
     * @param springCfgPath Path to file.
     * @return Grid configuration.
     * @throws IgniteCheckedException If load failed.
     */
@SuppressWarnings("deprecation")
protected IgniteConfiguration loadConfiguration(String springCfgPath) throws IgniteCheckedException {
    URL cfgLocation = U.resolveIgniteUrl(springCfgPath);
    if (cfgLocation == null)
        cfgLocation = U.resolveIgniteUrl(springCfgPath, false);
    assert cfgLocation != null;
    ApplicationContext springCtx;
    try {
        springCtx = new FileSystemXmlApplicationContext(cfgLocation.toString());
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate Spring XML application context.", e);
    }
    Map cfgMap;
    try {
        // Note: Spring is not generics-friendly.
        cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
    }
    if (cfgMap == null)
        throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + springCfgPath);
    if (cfgMap.isEmpty())
        throw new IgniteCheckedException("Can't find grid factory configuration in: " + springCfgPath);
    else if (cfgMap.size() > 1)
        throw new IgniteCheckedException("More than one configuration provided for cache load test: " + cfgMap.values());
    IgniteConfiguration cfg = (IgniteConfiguration) cfgMap.values().iterator().next();
    cfg.setNodeId(UUID.randomUUID());
    return cfg;
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) URL(java.net.URL) BeansException(org.springframework.beans.BeansException)

Example 28 with BeansException

use of org.springframework.beans.BeansException in project ignite by apache.

the class GridVmNodesStarter method getConfigurations.

/**
     * Initializes configurations.
     *
     *
     * @param springCfgPath Configuration file path.
     * @return List of configurations.
     * @throws IgniteCheckedException If an error occurs.
     */
@SuppressWarnings("unchecked")
private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath) throws IgniteCheckedException {
    File path = GridTestUtils.resolveIgnitePath(springCfgPath);
    if (path == null)
        throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
    if (!path.isFile())
        throw new IgniteCheckedException("Provided file path is not a file: " + path);
    // Add no-op logger to remove no-appender warning.
    Appender app = new NullAppender();
    Logger.getRootLogger().addAppender(app);
    ApplicationContext springCtx;
    try {
        springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
    } catch (BeansException | MalformedURLException e) {
        throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
    }
    Map cfgMap;
    try {
        // Note: Spring is not generics-friendly.
        cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
    }
    if (cfgMap == null)
        throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
    // Remove previously added no-op logger.
    Logger.getRootLogger().removeAppender(app);
    if (cfgMap.isEmpty())
        throw new IgniteCheckedException("Can't find grid factory configuration in: " + path);
    Collection<IgniteConfiguration> res = new ArrayList<>();
    for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>) cfgMap.values()) {
        res.add(cfg);
        cfg.setIgniteInstanceName(IGNITE_INSTANCE_NAME_PREF + gridCnt.incrementAndGet());
    }
    return res;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) MalformedURLException(java.net.MalformedURLException) NullAppender(org.apache.log4j.varia.NullAppender) ArrayList(java.util.ArrayList) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Collection(java.util.Collection) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException)

Example 29 with BeansException

use of org.springframework.beans.BeansException in project ignite by apache.

the class GridRandomCommandLineLoader method getConfiguration.

/**
     * Initializes configurations.
     *
     * @param springCfgPath Configuration file path.
     * @param logCfgPath Log file name.
     * @return List of configurations.
     * @throws IgniteCheckedException If an error occurs.
     */
@SuppressWarnings("unchecked")
private static IgniteConfiguration getConfiguration(String springCfgPath, @Nullable String logCfgPath) throws IgniteCheckedException {
    assert springCfgPath != null;
    File path = GridTestUtils.resolveIgnitePath(springCfgPath);
    if (path == null)
        throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
    if (!path.isFile())
        throw new IgniteCheckedException("Provided file path is not a file: " + path);
    // Add no-op logger to remove no-appender warning.
    Appender app = new NullAppender();
    Logger.getRootLogger().addAppender(app);
    ApplicationContext springCtx;
    try {
        springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
    } catch (BeansException | MalformedURLException e) {
        throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
    }
    Map cfgMap;
    try {
        // Note: Spring is not generics-friendly.
        cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
    }
    if (cfgMap == null)
        throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
    // Remove previously added no-op logger.
    Logger.getRootLogger().removeAppender(app);
    if (cfgMap.size() != 1)
        throw new IgniteCheckedException("Spring configuration file should contain exactly 1 grid configuration: " + path);
    IgniteConfiguration cfg = (IgniteConfiguration) F.first(cfgMap.values());
    assert cfg != null;
    if (logCfgPath != null)
        cfg.setGridLogger(new GridTestLog4jLogger(U.resolveIgniteUrl(logCfgPath)));
    return cfg;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MalformedURLException(java.net.MalformedURLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) NullAppender(org.apache.log4j.varia.NullAppender) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)

Example 30 with BeansException

use of org.springframework.beans.BeansException in project ignite by apache.

the class GridSingleExecutionTest method getConfigurations.

/**
     * Initializes configurations.
     *
     * @param springCfgPath Configuration file path.
     * @param log Log file name.
     * @return List of configurations.
     * @throws IgniteCheckedException If failed..
     */
@SuppressWarnings("unchecked")
private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath, String log) throws IgniteCheckedException {
    File path = GridTestUtils.resolveIgnitePath(springCfgPath);
    if (path == null) {
        throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME.");
    }
    if (!path.isFile())
        throw new IgniteCheckedException("Provided file path is not a file: " + path);
    // Add no-op logger to remove no-appender warning.
    Appender app = new NullAppender();
    Logger.getRootLogger().addAppender(app);
    ApplicationContext springCtx;
    try {
        springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString());
    } catch (BeansException | MalformedURLException e) {
        throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e);
    }
    Map cfgMap;
    try {
        // Note: Spring is not generics-friendly.
        cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class);
    } catch (BeansException e) {
        throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + e.getMessage() + ']', e);
    }
    if (cfgMap == null)
        throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path);
    // Remove previously added no-op logger.
    Logger.getRootLogger().removeAppender(app);
    if (cfgMap.isEmpty())
        throw new IgniteCheckedException("Can't find grid factory configuration in: " + path);
    Collection<IgniteConfiguration> res = new ArrayList<>();
    for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>) cfgMap.values()) {
        UUID nodeId = UUID.randomUUID();
        cfg.setNodeId(nodeId);
        cfg.setGridLogger(initLogger(log));
        res.add(cfg);
    }
    return res;
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) RollingFileAppender(org.apache.log4j.RollingFileAppender) MalformedURLException(java.net.MalformedURLException) NullAppender(org.apache.log4j.varia.NullAppender) ArrayList(java.util.ArrayList) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Collection(java.util.Collection) UUID(java.util.UUID) File(java.io.File) Map(java.util.Map) BeansException(org.springframework.beans.BeansException)

Aggregations

BeansException (org.springframework.beans.BeansException)64 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)14 BeanWrapper (org.springframework.beans.BeanWrapper)11 Test (org.junit.Test)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)9 BeanCreationException (org.springframework.beans.factory.BeanCreationException)8 MalformedURLException (java.net.MalformedURLException)7 ArrayList (java.util.ArrayList)7 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)7 ApplicationContext (org.springframework.context.ApplicationContext)7 Map (java.util.Map)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5 IOException (java.io.IOException)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)4 UrlResource (org.springframework.core.io.UrlResource)4 File (java.io.File)3 HashMap (java.util.HashMap)3