Example usage for org.springframework.web.context ContextLoader CONFIG_LOCATION_PARAM

List of usage examples for org.springframework.web.context ContextLoader CONFIG_LOCATION_PARAM

Introduction

In this page you can find the example usage for org.springframework.web.context ContextLoader CONFIG_LOCATION_PARAM.

Prototype

String CONFIG_LOCATION_PARAM

To view the source code for org.springframework.web.context ContextLoader CONFIG_LOCATION_PARAM.

Click Source Link

Document

Name of servlet context parameter (i.e., ) that can specify the config location for the root context, falling back to the implementation's default otherwise.

Usage

From source file:org.springside.modules.test.spring.SpringWebTestHelper.java

/**
 * ServletContext?Spring WebApplicationContext.
 * //from  ww w.  j  av  a 2 s.c  o  m
 * @param configLocations application context.
 */
public static void initWebApplicationContext(MockServletContext servletContext, String... configLocations) {
    String configLocationsString = StringUtils.join(configLocations, ",");
    servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, configLocationsString);
    new ContextLoader().initWebApplicationContext(servletContext);
}

From source file:org.openmrs.contrib.metadatarepository.webapp.listener.StartupListenerTest.java

protected void setUp() throws Exception {
    super.setUp();
    sc = new MockServletContext("");
    sc.addInitParameter(Constants.CSS_THEME, "simplicity");

    // initialize Spring
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext-dao.xml, "
            + "classpath:/applicationContext-service.xml, " + "classpath:/applicationContext-resources.xml");

    springListener = new ContextLoaderListener();
    springListener.contextInitialized(new ServletContextEvent(sc));
    listener = new StartupListener();
}

From source file:org.cometd.websocket.SpringFrameworkConfigurationTest.java

@Test
public void testXMLSpringConfigurationWithWebSocket() throws Exception {
    prepareServer(0, null, false);// w  w  w.  j  a va 2s  . co  m
    // Add Spring listener
    context.addEventListener(new ContextLoaderListener());
    String config = WEBSOCKET_JSR_356.equals(wsTransportType) ? "applicationContext-javax-websocket.xml"
            : "applicationContext-jetty-websocket.xml";
    context.getInitParams().put(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/" + config);
    startServer();

    prepareClient();
    startClient();

    WebApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(context.getServletContext());
    Assert.assertNotNull(applicationContext);

    BayeuxServerImpl bayeuxServer = (BayeuxServerImpl) applicationContext.getBean("bayeux");
    Assert.assertNotNull(bayeuxServer);
    Assert.assertTrue(bayeuxServer.isStarted());

    Assert.assertSame(bayeuxServer, bayeux);

    ServerTransport transport = bayeuxServer.getTransport("websocket");
    Assert.assertNotNull(transport);

    final BayeuxClient client = newBayeuxClient();
    client.handshake();
    Assert.assertTrue(client.waitFor(5000, BayeuxClient.State.CONNECTED));

    // Wait for connect to establish
    Thread.sleep(1000);

    ClientTransport clientTransport = client.getTransport();
    Assert.assertEquals("websocket", clientTransport.getName());

    disconnectBayeuxClient(client);
}

From source file:org.cometd.server.SpringFrameworkConfigurationTest.java

@Test
public void testXMLSpringConfiguration() throws Exception {
    int port = this.port;
    server.stop();//from   ww w  . j a  v  a  2  s.  c  om
    // Add Spring listener
    context.addEventListener(new ContextLoaderListener());
    context.getInitParams().put(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext.xml");
    connector.setPort(port);
    server.start();

    WebApplicationContext applicationContext = WebApplicationContextUtils
            .getRequiredWebApplicationContext(context.getServletContext());
    assertNotNull(applicationContext);

    int sweepPeriod = (Integer) applicationContext.getBean("sweepPeriod");

    BayeuxServerImpl bayeuxServer = (BayeuxServerImpl) applicationContext.getBean("bayeux");
    assertNotNull(bayeuxServer);
    assertTrue(bayeuxServer.isStarted());
    assertEquals(sweepPeriod, bayeuxServer.getOption("sweepPeriod"));

    assertSame(bayeuxServer, cometdServlet.getBayeux());

    Request handshake = newBayeuxRequest("" + "[{" + "\"channel\": \"/meta/handshake\","
            + "\"version\": \"1.0\"," + "\"minimumVersion\": \"1.0\","
            + "\"supportedConnectionTypes\": [\"long-polling\"]" + "}]");
    ContentResponse response = handshake.send();
    assertEquals(200, response.getStatus());
}

From source file:org.apache.wink.test.mock.SpringAwareTestCase.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    ContextLoader contextLoader = new ContextLoader();
    servletContext = new MockServletContext();
    servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, getApplicationContextPath());
    applicationContext = contextLoader.initWebApplicationContext(servletContext);
}

From source file:org.cometd.oort.spring.OortSpringAnnotationTest.java

@Test
public void testSpringWiringOfOort() throws Exception {
    Server server = new Server();
    ServletContextHandler context = new ServletContextHandler(server, "/");
    WebSocketServerContainerInitializer.configureContext(context);
    context.addEventListener(new ContextLoaderListener());
    context.getInitParams().put(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext.xml");
    server.start();/*from  w  w w .  j  a  v  a2s.co m*/

    ApplicationContext applicationContext = WebApplicationContextUtils
            .getWebApplicationContext(context.getServletContext());

    String beanName = Introspector.decapitalize(OortService.class.getSimpleName());

    String[] beanNames = applicationContext.getBeanDefinitionNames();
    assertTrue(Arrays.asList(beanNames).contains(beanName));

    OortService service = (OortService) applicationContext.getBean(beanName);
    assertNotNull(service);
    Seti seti = service.seti;
    assertNotNull(seti);
    Oort oort = seti.getOort();
    assertNotNull(oort);
    BayeuxServer bayeux = oort.getBayeuxServer();
    assertNotNull(bayeux);

    SecurityPolicy policy = bayeux.getSecurityPolicy();
    assertNotNull(policy);
    assertTrue(policy instanceof OortSecurityPolicy);

    server.stop();
}

From source file:com.bekk.boss.pluto.embedded.jetty.util.OverrideContextLoaderListener.java

public void contextInitialized(ServletContextEvent sce) {
    SContext servletContext = (SContext) sce.getServletContext();
    ContextHandler contextHandler = servletContext.getContextHandler();
    Map initParams = contextHandler.getInitParams();
    String configLocations = (String) initParams.get(ContextLoader.CONFIG_LOCATION_PARAM);
    if (configLocations != null) {
        configLocations = configLocations + " " + PLUTO_SERVICE_CONFIG_LOCATION;
        initParams.put(ContextLoader.CONFIG_LOCATION_PARAM, configLocations);
    } else {/*  w w  w. j a v a2s .c  o  m*/
        initParams.put(ContextLoader.CONFIG_LOCATION_PARAM, PLUTO_SERVICE_CONFIG_LOCATION);
    }
    // Traverse listeners to see if there's a configured
    // ContextLoaderListener
    EventListener[] listeners = contextHandler.getEventListeners();
    if (listeners != null) {
        List newListenerList = new ArrayList();
        for (int i = 0; i < listeners.length; i++) {
            EventListener listener = listeners[i];
            if (!(listener instanceof ContextLoaderListener)) {
                newListenerList.add(listener);
            }
        }
        contextHandler.setEventListeners(
                (EventListener[]) newListenerList.toArray(new EventListener[newListenerList.size()]));
    }
    contextLoaderListener.contextInitialized(sce);
}

From source file:com.bekk.boss.pluto.embedded.util.PortalStartupListener.java

public void contextInitialized(ServletContextEvent sce) {
    Context.SContext servletContext = (Context.SContext) sce.getServletContext();
    ContextHandler contextHandler = servletContext.getContextHandler();
    Map initParams = contextHandler.getInitParams();
    String configLocations = (String) initParams.get(ContextLoader.CONFIG_LOCATION_PARAM);
    if (configLocations != null) {
        configLocations = configLocations + " " + PLUTO_SERVICE_CONFIG_LOCATION;
        initParams.put(ContextLoader.CONFIG_LOCATION_PARAM, configLocations);
    } else {/*from  w  ww  .  j  a  v  a  2  s.co  m*/
        initParams.put(ContextLoader.CONFIG_LOCATION_PARAM, PLUTO_SERVICE_CONFIG_LOCATION);
    }
    // Traverse listeners to see if there's a configured
    // ContextLoaderListener
    EventListener[] listeners = contextHandler.getEventListeners();
    if (listeners != null) {
        List newListenerList = new ArrayList();
        for (int i = 0; i < listeners.length; i++) {
            EventListener listener = listeners[i];
            if (!(listener instanceof ContextLoaderListener)) {
                newListenerList.add(listener);
            }
        }
        contextHandler.setEventListeners(
                (EventListener[]) newListenerList.toArray(new EventListener[newListenerList.size()]));
    }
    ServletContext wrapped = new WrappedServletContext(sce.getServletContext());
    realStartupListener.contextInitialized(new ServletContextEvent(wrapped));
}

From source file:alpha.portal.webapp.listener.StartupListenerTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    this.sc = new MockServletContext("");
    this.sc.addInitParameter(Constants.CSS_THEME, "simplicity");

    // initialize Spring
    this.sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "classpath:/applicationContext-dao.xml, "
            + "classpath:/applicationContext-service.xml, " + "classpath:/applicationContext-resources.xml");

    this.springListener = new ContextLoaderListener();
    this.springListener.contextInitialized(new ServletContextEvent(this.sc));
    this.listener = new StartupListener();
}

From source file:org.red5.server.war.SubContextLoaderServlet.java

/**
 * Main entry point for the Red5 Server as a war
 *//*from   w ww. j a va2  s .c om*/
// Notification that the web application is ready to process requests
@Override
public void contextInitialized(ServletContextEvent sce) {
    if (null != servletContext) {
        return;
    }
    System.setProperty("red5.deployment.type", "war");

    servletContext = sce.getServletContext();
    String prefix = servletContext.getRealPath("/");

    initRegistry(servletContext);

    long time = System.currentTimeMillis();

    logger.info("RED5 Server subcontext loader");
    logger.debug("Path: " + prefix);

    try {
        String[] configArray = servletContext.getInitParameter(ContextLoader.CONFIG_LOCATION_PARAM)
                .split("[,\\s]");
        logger.debug("Config location files: " + configArray.length);

        WebSettings settings = new WebSettings();
        settings.setPath(prefix);
        // prefix the config file paths so they can be found later
        String[] subConfigs = new String[configArray.length];
        for (int s = 0; s < configArray.length; s++) {
            String cfg = "file:/" + prefix + configArray[s];
            logger.debug("Sub config location: " + cfg);
            subConfigs[s] = cfg;
        }
        settings.setConfigs(subConfigs);
        settings.setWebAppKey(servletContext.getInitParameter("webAppRootKey"));

        // store this contexts settings in the registry
        IRemotableList remote = null;
        boolean firstReg = false;
        try {
            remote = (IRemotableList) Naming.lookup("rmi://localhost:" + rmiPort + "/subContextList");
        } catch (Exception e) {
            logger.warn("Lookup failed: " + e.getMessage());
        }
        if (remote == null) {
            remote = new RemotableList();
            firstReg = true;
        }
        logger.debug("Adding child web settings");
        remote.addChild(settings);
        logger.debug("Remote list size: " + remote.numChildren());
        if (firstReg) {
            Naming.bind("rmi://localhost:" + rmiPort + "/subContextList", remote);
        } else {
            Naming.rebind("rmi://localhost:" + rmiPort + "/subContextList", remote);
        }

    } catch (Throwable t) {
        logger.error(t);
    }

    long startupIn = System.currentTimeMillis() - time;
    logger.info("Startup done in: " + startupIn + " ms");

}