Search in sources :

Example 1 with StandardServletEnvironment

use of org.springframework.web.context.support.StandardServletEnvironment in project spring-framework by spring-projects.

the class DispatcherServletTests method environmentOperations.

@Test
public void environmentOperations() {
    DispatcherServlet servlet = new DispatcherServlet();
    ConfigurableEnvironment defaultEnv = servlet.getEnvironment();
    assertThat(defaultEnv, notNullValue());
    ConfigurableEnvironment env1 = new StandardServletEnvironment();
    // should succeed
    servlet.setEnvironment(env1);
    assertThat(servlet.getEnvironment(), sameInstance(env1));
    try {
        servlet.setEnvironment(new DummyEnvironment());
        fail("expected IllegalArgumentException for non-configurable Environment");
    } catch (IllegalArgumentException ex) {
    }
    class CustomServletEnvironment extends StandardServletEnvironment {
    }
    @SuppressWarnings("serial") DispatcherServlet custom = new DispatcherServlet() {

        @Override
        protected ConfigurableWebEnvironment createEnvironment() {
            return new CustomServletEnvironment();
        }
    };
    assertThat(custom.getEnvironment(), instanceOf(CustomServletEnvironment.class));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) DummyEnvironment(org.springframework.core.env.DummyEnvironment) StandardServletEnvironment(org.springframework.web.context.support.StandardServletEnvironment) Test(org.junit.Test)

Example 2 with StandardServletEnvironment

use of org.springframework.web.context.support.StandardServletEnvironment 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)

Aggregations

StandardServletEnvironment (org.springframework.web.context.support.StandardServletEnvironment)2 ReversePropertySourcesStandardServletEnvironment (com.hevelian.activemq.support.ReversePropertySourcesStandardServletEnvironment)1 URI (java.net.URI)1 Test (org.junit.Test)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 DummyEnvironment (org.springframework.core.env.DummyEnvironment)1