List of usage examples for org.springframework.web.context.support XmlWebApplicationContext setConfigLocations
public void setConfigLocations(@Nullable String... locations)
From source file:jp.classmethod.aws.petrucci.SpringInitializer.java
@Override @SuppressWarnings("unused") public void onStartup(ServletContext container) throws ServletException { XmlWebApplicationContext rootContext = new XmlWebApplicationContext(); rootContext.setConfigLocations(new String[] { "classpath*:applicationContext.xml" }); container.addListener(new ContextLoaderListener(rootContext)); }
From source file:org.guanxi.idp.persistence.AttributePersistenceTest.java
@Test public void test() { XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocations(persistenceConfigFiles); ctx.setServletContext(servletContext); ctx.refresh();/*from w ww . ja v a 2 s. c o m*/ PersistenceEngine engine = (PersistenceEngine) ctx.getBean("idpPersistenceEngine"); assertFalse(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME)); assertTrue( engine.persistAttribute(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME, TEST_ATTRIBUTE_VALUE)); assertTrue(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME)); assertEquals(engine.getAttributeValue(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME), TEST_ATTRIBUTE_VALUE); assertTrue(engine.unpersistAttribute(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME)); assertFalse(engine.attributeExists(principal, TEST_RELYING_PARTY, TEST_ATTRIBUTE_NAME)); }
From source file:org.alfresco.bm.web.WebApp.java
@Override public void onStartup(ServletContext container) { // Grab the server capabilities, otherwise just use the java version String javaVersion = System.getProperty("java.version"); String systemCapabilities = System.getProperty(PROP_SYSTEM_CAPABILITIES, javaVersion); String appDir = new File(".").getAbsolutePath(); String appContext = container.getContextPath(); String appName = container.getContextPath().replace(SEPARATOR, ""); // Create an application context (don't start, yet) XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocations(new String[] { "classpath:config/spring/app-context.xml" }); // Pass our properties to the new context Properties ctxProperties = new Properties(); {// w w w. j a va2 s .co m ctxProperties.put(PROP_SYSTEM_CAPABILITIES, systemCapabilities); ctxProperties.put(PROP_APP_CONTEXT_PATH, appContext); ctxProperties.put(PROP_APP_DIR, appDir); } ConfigurableEnvironment ctxEnv = ctx.getEnvironment(); ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource(appName, ctxProperties)); // Override all properties with system properties ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource("system", System.getProperties())); // Bind to shutdown ctx.registerShutdownHook(); ContextLoaderListener ctxLoaderListener = new ContextLoaderListener(ctx); container.addListener(ctxLoaderListener); ServletRegistration.Dynamic jerseyServlet = container.addServlet("jersey-serlvet", SpringServlet.class); jerseyServlet.setInitParameter("com.sun.jersey.config.property.packages", "org.alfresco.bm.rest"); jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true"); jerseyServlet.addMapping("/api/*"); }
From source file:org.parancoe.plugin.configuration.TestContextListener.java
@Override protected void loadApplicationContext() { List<String> config = new ArrayList<String>(); // generici//from w w w . j av a 2 s . com config.add("classpath:org/lambico/spring/dao/hibernate/genericDao.xml"); config.add("classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml"); config.add("classpath:org/parancoe/web/parancoeBase.xml"); config.add("classpath:database-test-server.xml"); config.add("classpath:applicationContext-test.xml"); config.add("classpath*:parancoe-plugin.xml"); config.add("classpath*:applicationContext-plugin.xml"); config.add("classpath:org/parancoe/plugin/configuration/restful-services.xml"); XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setServletContext(servletContext); ctx.setConfigLocations(config.toArray(new String[config.size()])); ctx.refresh(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); applicationContext = ctx; populateDaoMap(ctx); }
From source file:org.parancoe.web.test.PluginTest.java
@Override protected ConfigurableApplicationContext createApplicationContext(String[] locations) { FileSystemResourceLoader rl = new FileSystemResourceLoader(); ServletContext servletContext = new MockServletContext(rl); XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setServletContext(servletContext); context.setConfigLocations(locations); context.refresh();//ww w . jav a2 s. com return context; }
From source file:org.parancoe.web.ContextListener.java
/** * load the ApplicationContext mixing the base parancoe files and the application specific * configuration//w w w . jav a2 s . c om */ protected void loadApplicationContext() { List<String> config = new ArrayList<String>(); // generici config.add("classpath:org/lambico/spring/dao/hibernate/genericDao.xml"); config.add("classpath:org/lambico/spring/dao/hibernate/applicationContextBase.xml"); config.add("classpath:org/parancoe/core/applicationContextBase.xml"); config.add("WEB-INF/database.xml"); // load all plugin configurations at once config.add("classpath*:applicationContext-plugin.xml"); config.add("WEB-INF/applicationContext.xml"); XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setServletContext(servletContext); ctx.setConfigLocations(config.toArray(new String[config.size()])); ctx.refresh(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ctx); applicationContext = ctx; populateDaoMap(ctx); }
From source file:com.agiletec.ConfigTestUtils.java
/** * Crea e restituisce il Contesto dell'Applicazione. * @param srvCtx Il Contesto della Servlet. * @return Il Contesto dell'Applicazione. *///w w w . j av a2s . com public ApplicationContext createApplicationContext(ServletContext srvCtx) { this.createNamingContext(); XmlWebApplicationContext applicationContext = new XmlWebApplicationContext(); applicationContext.setConfigLocations(this.getSpringConfigFilePaths()); applicationContext.setServletContext(srvCtx); applicationContext.refresh(); return applicationContext; }
From source file:ar.com.zauber.commons.web.uri.assets.AssetsTest.java
/** test */ @Test/*ww w. j a v a2s.c o m*/ public final void testAssetsUriFactory() throws Exception { // Creado el servlet final XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocations(new String[] { "classpath:ar/com/zauber/commons/web/uri/assets/" + profile + "-assets-spring.xml", }); ctx.setServletContext(new MockServletContext()); ctx.refresh(); for (int i = 0; i < 2; i++) { // Armo el request final PageContext pageCtx = createPageContext(ctx); // <assets:javascript key="/_js/lib/jquery-1.4.2.js"/> JavascriptTag js = new JavascriptTag(); js.setPageContext(pageCtx); js.setKey("/_js/lib/jquery-1.4.2.js"); js.doStartTag(); js.doEndTag(); // <assets:javascript key="/_js/model/foo.js"/> js = new JavascriptTag(); js.setPageContext(pageCtx); js.setKey("/_js/model/foo.js"); js.setCharset("utf-8"); js.doStartTag(); js.doEndTag(); // <assets:css key="/stylesheet.css"/> final CssTag t = new CssTag(); t.setPageContext(pageCtx); t.setCharset("utf-8"); t.setKey("/stylesheet.css"); t.doStartTag(); t.doEndTag(); // <assets:css key="/stylesheet.css"/> final ImageTag image = new ImageTag(); image.setPageContext(pageCtx); image.setKey("/1.gif"); image.doStartTag(); image.doEndTag(); // <assets:print/> final PrintTag printTag = new PrintTag(); printTag.setPageContext(pageCtx); printTag.doStartTag(); printTag.doEndTag(); // Validaciones final MockHttpServletResponse response = (MockHttpServletResponse) pageCtx.getResponse(); final String result = new String(response.getContentAsByteArray(), "utf8"); final InputStream is = getClass().getResourceAsStream(profile + "-expected.txt"); try { Assert.assertEquals(IOUtils.toString(is), result); } finally { is.close(); } } }
From source file:org.red5.server.tomcat.TomcatVHostLoader.java
/** * Starts a web application and its red5 (spring) component. This is basically a stripped down * version of init().//from w w w . j a v a 2s . com * * @return true on success */ @SuppressWarnings("cast") public boolean startWebApplication(String applicationName) { boolean result = false; log.info("Starting Tomcat virtual host - Web application"); log.info("Virtual host root: {}", webappRoot); log.info("Virtual host context id: {}", defaultApplicationContextId); // application directory String contextName = '/' + applicationName; Container cont = null; //check if the context already exists for the host if ((cont = host.findChild(contextName)) == null) { log.debug("Context did not exist in host"); String webappContextDir = FileUtil.formatPath(webappRoot, applicationName); //prepend slash Context ctx = addContext(contextName, webappContextDir); //set the newly created context as the current container cont = ctx; } else { log.debug("Context already exists in host"); } try { ServletContext servletContext = ((Context) cont).getServletContext(); log.debug("Context initialized: {}", servletContext.getContextPath()); String prefix = servletContext.getRealPath("/"); log.debug("Path: {}", prefix); Loader cldr = cont.getLoader(); log.debug("Loader type: {}", cldr.getClass().getName()); ClassLoader webClassLoader = cldr.getClassLoader(); log.debug("Webapp classloader: {}", webClassLoader); //create a spring web application context XmlWebApplicationContext appctx = new XmlWebApplicationContext(); appctx.setClassLoader(webClassLoader); appctx.setConfigLocations(new String[] { "/WEB-INF/red5-*.xml" }); //check for red5 context bean if (applicationContext.containsBean(defaultApplicationContextId)) { appctx.setParent((ApplicationContext) applicationContext.getBean(defaultApplicationContextId)); } else { log.warn("{} bean was not found in context: {}", defaultApplicationContextId, applicationContext.getDisplayName()); //lookup context loader and attempt to get what we need from it if (applicationContext.containsBean("context.loader")) { ContextLoader contextLoader = (ContextLoader) applicationContext.getBean("context.loader"); appctx.setParent(contextLoader.getContext(defaultApplicationContextId)); } else { log.debug("Context loader was not found, trying JMX"); MBeanServer mbs = JMXFactory.getMBeanServer(); //get the ContextLoader from jmx ObjectName oName = JMXFactory.createObjectName("type", "ContextLoader"); ContextLoaderMBean proxy = null; if (mbs.isRegistered(oName)) { proxy = (ContextLoaderMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, oName, ContextLoaderMBean.class, true); log.debug("Context loader was found"); appctx.setParent(proxy.getContext(defaultApplicationContextId)); } else { log.warn("Context loader was not found"); } } } if (log.isDebugEnabled()) { if (appctx.getParent() != null) { log.debug("Parent application context: {}", appctx.getParent().getDisplayName()); } } // appctx.setServletContext(servletContext); //set the root webapp ctx attr on the each servlet context so spring can find it later servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appctx); appctx.refresh(); result = true; } catch (Throwable t) { log.error("Error setting up context: {}", applicationName, t); if (log.isDebugEnabled()) { t.printStackTrace(); } } return result; }
From source file:org.red5.server.tomcat.TomcatVHostLoader.java
/** * Initialization.//from w w w . j av a 2s.com */ @SuppressWarnings("cast") public void init() { log.info("Loading tomcat virtual host"); if (webappFolder != null) { //check for match with base webapp root if (webappFolder.equals(webappRoot)) { log.error("Web application root cannot be the same as base"); return; } } ClassLoader classloader = Thread.currentThread().getContextClassLoader(); //ensure we have a host if (host == null) { host = createHost(); } host.setParentClassLoader(classloader); String propertyPrefix = name; if (domain != null) { propertyPrefix += '_' + domain.replace('.', '_'); } log.debug("Generating name (for props) {}", propertyPrefix); System.setProperty(propertyPrefix + ".webapp.root", webappRoot); log.info("Virtual host root: {}", webappRoot); log.info("Virtual host context id: {}", defaultApplicationContextId); // Root applications directory File appDirBase = new File(webappRoot); // Subdirs of root apps dir File[] dirs = appDirBase.listFiles(new TomcatLoader.DirectoryFilter()); // Search for additional context files for (File dir : dirs) { String dirName = '/' + dir.getName(); // check to see if the directory is already mapped if (null == host.findChild(dirName)) { String webappContextDir = FileUtil.formatPath(appDirBase.getAbsolutePath(), dirName); Context ctx = null; if ("/root".equals(dirName) || "/root".equalsIgnoreCase(dirName)) { log.debug("Adding ROOT context"); ctx = addContext("/", webappContextDir); } else { log.debug("Adding context from directory scan: {}", dirName); ctx = addContext(dirName, webappContextDir); } log.debug("Context: {}", ctx); webappContextDir = null; } } appDirBase = null; dirs = null; // Dump context list if (log.isDebugEnabled()) { for (Container cont : host.findChildren()) { log.debug("Context child name: {}", cont.getName()); } } engine.addChild(host); // Start server try { log.info("Starting Tomcat virtual host"); //may not have to do this step for every host LoaderBase.setApplicationLoader(new TomcatApplicationLoader(embedded, host, applicationContext)); for (Container cont : host.findChildren()) { if (cont instanceof StandardContext) { StandardContext ctx = (StandardContext) cont; ServletContext servletContext = ctx.getServletContext(); log.debug("Context initialized: {}", servletContext.getContextPath()); //set the hosts id servletContext.setAttribute("red5.host.id", getHostId()); String prefix = servletContext.getRealPath("/"); log.debug("Path: {}", prefix); try { Loader cldr = ctx.getLoader(); log.debug("Loader type: {}", cldr.getClass().getName()); ClassLoader webClassLoader = cldr.getClassLoader(); log.debug("Webapp classloader: {}", webClassLoader); //create a spring web application context XmlWebApplicationContext appctx = new XmlWebApplicationContext(); appctx.setClassLoader(webClassLoader); appctx.setConfigLocations(new String[] { "/WEB-INF/red5-*.xml" }); //check for red5 context bean if (applicationContext.containsBean(defaultApplicationContextId)) { appctx.setParent( (ApplicationContext) applicationContext.getBean(defaultApplicationContextId)); } else { log.warn("{} bean was not found in context: {}", defaultApplicationContextId, applicationContext.getDisplayName()); //lookup context loader and attempt to get what we need from it if (applicationContext.containsBean("context.loader")) { ContextLoader contextLoader = (ContextLoader) applicationContext .getBean("context.loader"); appctx.setParent(contextLoader.getContext(defaultApplicationContextId)); } else { log.debug("Context loader was not found, trying JMX"); MBeanServer mbs = JMXFactory.getMBeanServer(); //get the ContextLoader from jmx ObjectName oName = JMXFactory.createObjectName("type", "ContextLoader"); ContextLoaderMBean proxy = null; if (mbs.isRegistered(oName)) { proxy = (ContextLoaderMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, oName, ContextLoaderMBean.class, true); log.debug("Context loader was found"); appctx.setParent(proxy.getContext(defaultApplicationContextId)); } else { log.warn("Context loader was not found"); } } } if (log.isDebugEnabled()) { if (appctx.getParent() != null) { log.debug("Parent application context: {}", appctx.getParent().getDisplayName()); } } // appctx.setServletContext(servletContext); //set the root webapp ctx attr on the each servlet context so spring can find it later servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appctx); appctx.refresh(); } catch (Throwable t) { log.error("Error setting up context: {}", servletContext.getContextPath(), t); if (log.isDebugEnabled()) { t.printStackTrace(); } } } } } catch (Exception e) { log.error("Error loading Tomcat virtual host", e); } }