/** * Load/use a bean factory, as specified by a factory key which is a JNDI * address, of the form {@code java:comp/env/ejb/BeanFactoryPath}. The * contents of this JNDI location must be a string containing one or more * classpath resource names (separated by any of the delimiters '{@code ,; \t\n}' * if there is more than one. The resulting BeanFactory (or ApplicationContext) * will be created from the combined resources. * @see #createBeanFactory */ @Override public BeanFactoryReference useBeanFactory(String factoryKey) throws BeansException { try { String beanFactoryPath = lookup(factoryKey, String.class); if (logger.isTraceEnabled()) { logger.trace("Bean factory path from JNDI environment variable [" + factoryKey + "] is: " + beanFactoryPath); } String[] paths = StringUtils.tokenizeToStringArray(beanFactoryPath, BEAN_FACTORY_PATH_DELIMITERS); return createBeanFactory(paths); } catch (NamingException ex) { throw new BootstrapException("Define an environment variable [" + factoryKey + "] containing " + "the class path locations of XML bean definition files", ex); } }
/** * Load/use a bean factory, as specified by a factory key which is a JNDI * address, of the form {@code java:comp/env/ejb/BeanFactoryPath}. The * contents of this JNDI location must be a string containing one or more * classpath resource names (separated by any of the delimiters '{@code ,; \t\n}' * if there is more than one. The resulting BeanFactory (or ApplicationContext) * will be created from the combined resources. * @see #createBeanFactory */ public BeanFactoryReference useBeanFactory(String factoryKey) throws BeansException { try { String beanFactoryPath = lookup(factoryKey, String.class); if (logger.isTraceEnabled()) { logger.trace("Bean factory path from JNDI environment variable [" + factoryKey + "] is: " + beanFactoryPath); } String[] paths = StringUtils.tokenizeToStringArray(beanFactoryPath, BEAN_FACTORY_PATH_DELIMITERS); return createBeanFactory(paths); } catch (NamingException ex) { throw new BootstrapException("Define an environment variable [" + factoryKey + "] containing " + "the class path locations of XML bean definition files", ex); } }
@Test public void beanFactoryPathRequiredFromJndiEnvironment() throws Exception { // Set up initial context but don't bind anything SimpleNamingContextBuilder.emptyActivatedContextBuilder(); ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator(); try { jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY); fail(); } catch (BootstrapException ex) { // Check for helpful JNDI message assertTrue(ex.getMessage().indexOf(BEAN_FACTORY_PATH_ENVIRONMENT_KEY) != -1); } }
private String getRequiredInitParameter(String parameterName) { String value = servletContext.getInitParameter(parameterName); if (value == null) { throw new BootstrapException("Required servlet context initialization parameter " + parameterName + " is not defined"); } return value; }
/** * Test the filter. * * @throws Exception * in case the test fails */ @Test(groups = { "allowAnonymous" }) public void testDoFilterAllowAccess() throws Exception { try { // filter.doFilter(request, response, chain); } catch (BootstrapException e) { // Okay. Method was called, but Service is not available at the moment. return; } Assert.fail("Something went wrong."); }
public void testBeanFactoryPathRequiredFromJndiEnvironment() throws Exception { // Set up initial context but don't bind anything SimpleNamingContextBuilder.emptyActivatedContextBuilder(); ContextJndiBeanFactoryLocator jbfl = new ContextJndiBeanFactoryLocator(); try { jbfl.useBeanFactory(BEAN_FACTORY_PATH_ENVIRONMENT_KEY); fail(); } catch (BootstrapException ex) { // Check for helpful JNDI message assertTrue(ex.getMessage().indexOf(BEAN_FACTORY_PATH_ENVIRONMENT_KEY) != -1); } }