Example usage for org.springframework.beans.factory BeanDefinitionStoreException getCause

List of usage examples for org.springframework.beans.factory BeanDefinitionStoreException getCause

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanDefinitionStoreException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:edu.vt.middleware.cas.ldap.LoadDriver.java

public static void main(final String[] args) {
    if (args.length < 4) {
        System.out.println("USAGE: LoadDriver sample_count thread_count "
                + "path/to/credentials.csv path/to/spring-context.xml");
        return;//  w  w w .  j  av  a 2s .c  o  m
    }
    final int samples = Integer.parseInt(args[0]);
    final int threads = Integer.parseInt(args[1]);
    final File credentials = new File(args[2]);
    if (!credentials.exists()) {
        throw new IllegalArgumentException(credentials + " does not exist.");
    }
    ApplicationContext context;
    try {
        context = new ClassPathXmlApplicationContext(args[3]);
    } catch (BeanDefinitionStoreException e) {
        if (e.getCause() instanceof FileNotFoundException) {
            // Try treating path as filesystem path
            context = new FileSystemXmlApplicationContext(args[3]);
        } else {
            throw e;
        }
    }
    final LoadDriver driver = new LoadDriver(samples, threads, credentials, context);
    System.err.println("Load test configuration:");
    System.err.println("\tthreads: " + threads);
    System.err.println("\tsamples: " + samples);
    System.err.println("\tcredentials: " + credentials);
    driver.start();
    while (driver.getState().hasWorkRemaining()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
    }
    driver.stop();
}

From source file:it.uniud.ailab.dcore.DistillerFactory.java

/**
 * Instantiates a Distiller object using the default evaluation
 * configuration./* w ww . j  a v  a2s.co m*/
 *
 * @return a Distiller ready to work.
 */
public static Distiller getDefaultEval() {

    try {
        ApplicationContext context = new ClassPathXmlApplicationContext("eval.xml");
        return (Distiller) context.getBean("distiller");
    } catch (BeanDefinitionStoreException bsde) {
        try {
            throw bsde.getCause();
        } catch (IOException ioe) {
            // the configuration file does not exist or is not accessible:
            throw new RuntimeException("FATAL: Impossible to load the default evaluation pipeline.", ioe);
        } catch (Throwable te) {
            throw bsde;
        }
    }
}

From source file:it.uniud.ailab.dcore.DistillerFactory.java

/**
 * Instantiates a Distiller object using the default XML configuration; if
 * it's not available, uses the safer (but less precise) code configuration,
 * which excludes TagMe and inference from the distillation process.
 *
 * @return a Distiller ready to work.// w  w w  .  ja  v a 2  s.co m
 */
public static Distiller getDefault() {

    // While the code under this comment may be ugly, it works.
    //
    // It tries to load the default XML config. If the load fails, throws
    // the cause of the failure and immediately catches it.
    //
    // If the config file is not accessible (due to permission, 
    // non-existance, or whatever), the exception is caught and the default
    // code configuration runs.
    //
    // Otherwise, the exception is re-thrown, so that the developer can
    // handle the errors in the config file, which are the other most likely
    // cause of failure of configuration loading falure.
    try {
        return getDefaultXML();
    } catch (BeanDefinitionStoreException bsde) {
        try {
            throw bsde.getCause();
        } catch (IOException ioe) {
            // the configuration file does not exist or is not accessible:
            // load the fallback configuration
            System.out.println("Distiller config file not found: using fallback configuration");
            return getDefaultCode();
        } catch (Throwable te) {
            throw bsde;
        }
    }
}

From source file:com.brienwheeler.lib.spring.beans.SmartXmlBeanDefinitionReaderTest.java

@Test
public void testFileNotFound() {
    try {/*from  www.  j  a  v  a2s. c om*/
        SmartXmlBeanDefinitionReader reader = new SmartXmlBeanDefinitionReader(
                new DefaultListableBeanFactory());
        reader.loadBeanDefinitions("classpath:this/is/bad.xml");
        Assert.fail();
    } catch (BeanDefinitionStoreException e) {
        Assert.assertEquals(FileNotFoundException.class, e.getCause().getClass());
    }
}

From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java

@Test
public void testFrameworkServletWithDefaultLocation() throws Exception {
    ContribDispatcherPortlet portlet = new ContribDispatcherPortlet();
    portlet.setContextClass(ContribXmlPortletApplicationContext.class);
    try {/*w  w  w.  j  av a  2 s  .c  o  m*/
        portlet.init(new MockPortletConfig(new MockPortletContext(""), "test"));
        fail("Should have thrown BeanDefinitionStoreException");
    } catch (BeanDefinitionStoreException ex) {
        // expected
        assertTrue(ex.getCause() instanceof IOException);
        assertTrue(ex.getCause().getMessage().contains("/WEB-INF/test-portlet.xml"));
    }
}

From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java

@Test
public void testContextLoaderWithDefaultLocation() throws Exception {
    MockServletContext sc = new MockServletContext("");
    ServletContextListener listener = new PortletContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);// w  w  w  .j av  a  2s . com
    try {
        //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create
        //the portlet app context due to lack of PortletContext reference
        MockPortletContext pc = new MockPortletContext(sc);
        PortletApplicationContextUtils2.getPortletApplicationContext(pc);
        fail("Should have thrown BeanDefinitionStoreException");
    } catch (BeanDefinitionStoreException ex) {
        // expected
        assertTrue(ex.getCause() instanceof IOException);
        assertTrue(ex.getCause().getMessage().contains("/WEB-INF/portletApplicationContext.xml"));
    }
}

From source file:org.jasig.springframework.web.portlet.context.PortletContextLoaderTests.java

@Test
public void testContextLoaderWithInvalidLocation() throws Exception {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(PortletContextLoader.CONFIG_LOCATION_PARAM, "/WEB-INF/myContext.xml");
    ServletContextListener listener = new PortletContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);/*from  w  w w  .  j  av  a  2 s. c  o  m*/
    try {
        //initialize the portlet application context, needed because PortletContextLoaderListener.contextInitialized doesn't actually create
        //the portlet app context due to lack of PortletContext reference
        MockPortletContext pc = new MockPortletContext(sc);
        PortletApplicationContextUtils2.getPortletApplicationContext(pc);

        fail("Should have thrown BeanDefinitionStoreException");
    } catch (BeanDefinitionStoreException ex) {
        // expected
        assertTrue(ex.getCause() instanceof FileNotFoundException);
    }
}

From source file:org.openadaptor.spring.SpringAdaptor.java

private ListableBeanFactory createBeanFactory() {
    if (configUrls.isEmpty() && !ignoreConfigUrls) {
        throw new RuntimeException("no config urls specified");
    }// w  w  w  . j  a v  a2  s .c  om
    GenericApplicationContext context = getInternalContext();
    //Changed to make failure to load OPENADAPTOR_SPRING_CONFIG non-fatal.
    try {
        loadBeanDefinitions("classpath:" + ResourceUtil.getResourcePath(this, "", OPENADAPTOR_SPRING_CONFIG),
                context);
    } catch (BeanDefinitionStoreException bdse) {
        Throwable cause = bdse.getCause();
        log.warn("Resource " + OPENADAPTOR_SPRING_CONFIG + " was not loaded. Reason: "
                + cause.getClass().getName());
    }
    for (Iterator iter = configUrls.iterator(); iter.hasNext();) {
        String configUrl = (String) iter.next();
        loadBeanDefinitions(configUrl, context);
    }

    configureProperties(context, propsUrls);

    context.refresh();
    setComponentIds(context);
    configureMBeanServer(context);
    return context;
}

From source file:org.springframework.beans.factory.xml.XmlBeanFactoryTests.java

/**
 * Check that a prototype can't inherit from a bogus parent.
 * If a singleton does this the factory will fail to load.
 *//*from ww w . ja  v a2  s .  co m*/
@Test
public void testBogusParentageFromParentFactory() throws Exception {
    DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
    DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
    new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
    try {
        child.getBean("bogusParent", TestBean.class);
        fail();
    } catch (BeanDefinitionStoreException ex) {
        // check exception message contains the name
        assertTrue(ex.getMessage().indexOf("bogusParent") != -1);
        assertTrue(ex.getCause() instanceof NoSuchBeanDefinitionException);
    }
}