Search in sources :

Example 1 with ReversePropertySourcesStandardServletEnvironment

use of com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment in project hevelian-activemq by Hevelian.

the class WebBrokerInitializerImpl method createBroker.

@Override
protected // TODO throw corresponding exceptions, not just Exception instances.
BrokerService createBroker(ServletContext sc) throws Exception {
    // Initialize Web environment to make Spring resolve external
    // properties.
    StandardServletEnvironment standardServletEnvironment = new ReversePropertySourcesStandardServletEnvironment();
    WebApplicationContextUtils.initServletPropertySources(standardServletEnvironment.getPropertySources(), sc);
    URI configURI = new URI(standardServletEnvironment.getProperty(BROKER_URI_PROP));
    LOG.info("Loading message broker from: " + configURI);
    return BrokerFactory.createBroker(configURI);
}
Also used : ReversePropertySourcesStandardServletEnvironment(com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment) StandardServletEnvironment(org.springframework.web.context.support.StandardServletEnvironment) ReversePropertySourcesStandardServletEnvironment(com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment) URI(java.net.URI)

Example 2 with ReversePropertySourcesStandardServletEnvironment

use of com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment in project hevelian-activemq by Hevelian.

the class WebXBeanBrokerFactory method createApplicationContext.

@Override
protected ApplicationContext createApplicationContext(String uri) throws MalformedURLException {
    Resource resource = Utils.resourceFromString(uri);
    LOG.debug("Using " + resource + " from " + uri);
    try {
        return new ResourceXmlApplicationContext(resource) {

            @Override
            protected ConfigurableEnvironment createEnvironment() {
                return new ReversePropertySourcesStandardServletEnvironment();
            }

            @Override
            protected void initPropertySources() {
                WebApplicationContextUtils.initServletPropertySources(getEnvironment().getPropertySources(), ServletContextHolder.getServletContext());
            }
        };
    } catch (FatalBeanException errorToLog) {
        LOG.error("Failed to load: " + resource + ", reason: " + errorToLog.getLocalizedMessage(), errorToLog);
        throw errorToLog;
    }
}
Also used : ReversePropertySourcesStandardServletEnvironment(com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment) Resource(org.springframework.core.io.Resource) FatalBeanException(org.springframework.beans.FatalBeanException) ResourceXmlApplicationContext(org.apache.xbean.spring.context.ResourceXmlApplicationContext)

Example 3 with ReversePropertySourcesStandardServletEnvironment

use of com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment in project hevelian-activemq by Hevelian.

the class WebXBeanBrokerFactoryTest method createApplicationContext_envInstanceOfReversePropertySourcesStandardServletEnvironment.

@Test
public void createApplicationContext_envInstanceOfReversePropertySourcesStandardServletEnvironment() throws MalformedURLException {
    ServletContextHolder.setServletContext(Mockito.mock(ServletContext.class));
    ApplicationContext c = new WebXBeanBrokerFactory().createApplicationContext("classpath:activemq.xml");
    assertTrue(c instanceof ResourceXmlApplicationContext);
    try (ResourceXmlApplicationContext rc = (ResourceXmlApplicationContext) c) {
        assertTrue(rc.getEnvironment() instanceof ReversePropertySourcesStandardServletEnvironment);
    }
}
Also used : ResourceXmlApplicationContext(org.apache.xbean.spring.context.ResourceXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ReversePropertySourcesStandardServletEnvironment(com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment) ServletContext(javax.servlet.ServletContext) ResourceXmlApplicationContext(org.apache.xbean.spring.context.ResourceXmlApplicationContext) Test(org.junit.Test)

Aggregations

ReversePropertySourcesStandardServletEnvironment (com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment)3 ResourceXmlApplicationContext (org.apache.xbean.spring.context.ResourceXmlApplicationContext)2 URI (java.net.URI)1 ServletContext (javax.servlet.ServletContext)1 Test (org.junit.Test)1 FatalBeanException (org.springframework.beans.FatalBeanException)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Resource (org.springframework.core.io.Resource)1 StandardServletEnvironment (org.springframework.web.context.support.StandardServletEnvironment)1