List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:org.drools.server.CamelServerApp.java
public String send(String msg) { ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext( "classpath:/src/main/filtered-resoures/camel-client.xml"); String batch = ""; batch += "<batch-execution lookup=\"ksession1\">\n"; batch += " <insert out-identifier=\"message\">\n"; batch += " <org.drools.server.Message>\n"; batch += " <text>" + msg + "</text>\n"; batch += " </org.drools.server.Message>\n"; batch += " </insert>\n"; batch += "</batch-execution>\n"; CamelServerApp test = new CamelServerApp(); String response = test.execute(batch, (CamelContext) springContext.getBean("camel")); return response; }
From source file:br.com.pense.produto.controller.AbstractSemanticEngineTest.java
@Override protected void setUp() throws Exception { super.setUp(); if (engImoveis == null) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "applicationContext-semantic.xml"); engImoveis = (SemanticEngineImoveis) context.getBean("engineSemantica"); }/*w ww. j a v a 2 s .co m*/ }
From source file:org.atomserver.core.dbstore.utils.SeederDBSTest.java
public void testSeedDB() throws Exception { if (hasRun) { return;//from w ww . jav a 2s. c om } String[] configs = { "/org/atomserver/spring/propertyConfigurerBeans.xml", "/org/atomserver/spring/logBeans.xml", "/org/atomserver/spring/storageBeans.xml", "/org/atomserver/spring/databaseBeans.xml" }; ClassPathXmlApplicationContext springFactory = new ClassPathXmlApplicationContext(configs, false); springFactory.setClassLoader(new ConfigurationAwareClassLoader(springFactory.getClassLoader())); springFactory.refresh(); try { DBSeeder.getInstance(springFactory).seedEntriesClearingFirst(); } catch (Exception ee) { ee.printStackTrace(); } hasRun = true; // We should now get an ordered List back // SORTED -- From the beginning of time EntriesDAO widgetsDAOiBatis = (EntriesDAO) springFactory.getBean("org.atomserver-entriesDAO"); List sortedList = widgetsDAOiBatis .selectEntriesByLastModifiedSeqNum(new BaseFeedDescriptor("widgets", null), ZERO_DATE); log.debug("List= " + sortedList); Date lastVal = ZERO_DATE; long seqNum = 0; for (Object obj : sortedList) { EntryMetaData widget = (EntryMetaData) obj; assertTrue(lastVal.compareTo(widget.getUpdatedDate()) <= 0); lastVal = widget.getUpdatedDate(); assertTrue("expected " + seqNum + " < " + widget.getUpdateTimestamp() + " for " + widget, seqNum < widget.getUpdateTimestamp()); seqNum = widget.getUpdateTimestamp(); } }
From source file:org.ff4j.cli.FF4jCliProcessor.java
/** * Parse Spring context.//from w w w. j a v a 2 s .co m */ @SuppressWarnings("unchecked") public void parseSpringContext(String fileName) { try { logInfo("Loading configurations from classpath file [" + fileName + "]"); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(fileName); this.envs = ctx.getBeansOfType(FF4j.class); if (ctx.containsBean("AUTHORIZED_USERS")) { this.users = (Map<String, String>) ctx.getBean("AUTHORIZED_USERS"); } ctx.close(); } catch (RuntimeException fne) { error(fne, "Cannot parse Spring context"); } }
From source file:org.activiti.crystalball.simulator.TwoEnginesWithoutProcessTest.java
@Test public void test() throws Exception { String tempDir = "target"; FileUtils.copyFile(/* ww w. j ava 2 s .c o m*/ FileUtils.getFile( new String[] { (new StringBuilder()).append(LIVE_DB).append(".h2.db").toString() }), FileUtils.getFile( new String[] { (new StringBuilder()).append(tempDir).append("/simulationRunDB-aaa-") .append(Thread.currentThread().getId()).append(".h2.db").toString() })); System.setProperty("_SIM_DB_PATH", (new StringBuilder()).append(tempDir).append("/simulationRunDB-aaa-") .append(Thread.currentThread().getId()).toString()); ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "/org/activiti/crystalball/simulator/SimRun-h2-context.xml"); PropertyPlaceholderConfigurer propConfig = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); properties.put("simulationRunId", "simulationRunDB-aaa-" + Thread.currentThread().getId()); propConfig.setProperties(properties); appContext.addBeanFactoryPostProcessor(propConfig); appContext.refresh(); SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); String userId = "user1"; TaskService taskService = (TaskService) appContext.getBean("taskService"); TaskService simTaskService = (TaskService) appContext.getBean("simTaskService"); List<Task> liveTaskList = ((TaskQuery) taskService.createTaskQuery().taskCandidateUser(userId) .orderByTaskPriority().desc()).listPage(0, 1); List<Task> execTaskList = ((TaskQuery) simTaskService.createTaskQuery().taskCandidateUser(userId) .orderByTaskPriority().desc()).listPage(0, 1); Assert.assertTrue(liveTaskList.size() == execTaskList.size()); IdentityService identityService = (IdentityService) appContext.getBean("identityService"); IdentityService simIdentityService = (IdentityService) appContext.getBean("simIdentityService"); List<User> users = identityService.createUserQuery().list(); List<User> simUsers = simIdentityService.createUserQuery().list(); Assert.assertTrue(users.size() == simUsers.size()); simRun.execute(new Date(), null); appContext.close(); }
From source file:com.bt.aloha.batchtest.BatchTest.java
protected void assignNewCollectionsToBeans(ClassPathXmlApplicationContext ac, DialogCollectionImplWithStats _dialogCollection, CallCollectionImplWithStats _callCollection, ConferenceCollectionImplWithStats _conferenceCollection) { ((DialogJainSipListener) ac.getBean("dialogSipListener")).setDialogCollection(_dialogCollection); ((OutboundCallLegBeanImpl) ac.getBean("outboundCallLegBean")).setDialogCollection(_dialogCollection); ((InboundCallLegBeanImpl) ac.getBean("inboundCallLegBean")).setDialogCollection(_dialogCollection); ((CallBeanImpl) ac.getBean("callBean")).setDialogCollection(_dialogCollection); ((MediaCallLegBeanImpl) ac.getBean("mediaCallLegBean")).setDialogCollection(_dialogCollection); ((CallBeanImpl) ac.getBean("callBean")).setCallCollection(_callCollection); ((MediaCallBeanImpl) ac.getBean("mediaCallBean")).setCallCollection(_callCollection); ((ConferenceBeanImpl) ac.getBean("conferenceBean")).setConferenceCollection(_conferenceCollection); }
From source file:org.activiti.crystalball.simulator.impl.simulationexecutor.SimulationRunExecuteJobHandler.java
public void execute(JobEntity job, String configuration, SimulationInstanceEntity simulationInstance, CommandContext commandContext) { log.log(Level.INFO, "Starting simulation experiment [" + simulationInstance + "] configuration [" + configuration + "]"); SimulationRunEntity simulationRun = commandContext.getSimulationRunManager() .findSimulationRunWithReferencesById(configuration); SimulationContext.setSimulationRun(simulationRun); //initializeSimulationRun ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( simulationRun.getSimulation().getSimulationConfigUrl()); PropertyPlaceholderConfigurer propConfig = new PropertyPlaceholderConfigurer(); Properties properties = new Properties(); properties.put("simulationRunId", configuration); propConfig.setProperties(properties); appContext.addBeanFactoryPostProcessor(propConfig); appContext.refresh();// www. j av a 2 s . c om SimulationRunHelper runHelper = new NoopSimulationRunHelper(); if (appContext.containsBean("simulationRunHelper")) runHelper = (SimulationRunHelper) appContext.getBean("simulationRunHelper"); try { runHelper.before(configuration); SimulationRun simRun = (SimulationRun) appContext.getBean("simulationRun"); simRun.execute(simulationRun); } catch (Exception e) { log.log(Level.SEVERE, "SimulationRun handling error" + simulationRun, e); } finally { runHelper.after(configuration); appContext.close(); } job.delete(); SimulationContext.removeSimulationRun(); // check whether all jobs for given simulationInstance were already executed. simulationInstance.checkActivity(); log.log(Level.INFO, "finished simulation experiment [" + simulationInstance + "] configuration [" + configuration + "]"); }
From source file:com.nokia.dempsy.mpcluster.zookeeper.TestFullApp.java
@Test public void testSeparateClustersInOneVm() throws Throwable { // now start each cluster ctx[0] = "fullApp/Dempsy-FullUp.xml"; Map<ClusterId, DempsyHolder> dempsys = new HashMap<ClusterId, DempsyHolder>(); try {/*from w w w . jav a 2s .c o m*/ ApplicationDefinition ad = new FullApplication().getTopology(); ad.initialize(); List<ClusterDefinition> clusters = ad.getClusterDefinitions(); for (int i = clusters.size() - 1; i >= 0; i--) { ClusterDefinition cluster = clusters.get(i); CheckCluster.toCheckAgainst = cluster.getClusterId(); DempsyHolder cur = new DempsyHolder(); cur.clusterid = cluster.getClusterId(); cur.actx = new ClassPathXmlApplicationContext(ctx); cur.actx.registerShutdownHook(); cur.dempsy = (Dempsy) cur.actx.getBean("dempsy"); cur.dempsy.start(); dempsys.put(cluster.getClusterId(), cur); } // get the last FullApplication in the processing chain. ClassPathXmlApplicationContext actx = dempsys .get(new ClusterId(FullApplication.class.getSimpleName(), MyRankMp.class.getSimpleName())).actx; final FullApplication app = (FullApplication) actx.getBean("app"); // this checks that the throughput works. assertTrue(poll(baseTimeoutMillis * 5, app, new Condition<Object>() { @Override public boolean conditionMet(Object o) { return app.finalMessageCount.get() > 100; } })); } finally { ctx[0] = dempsyConfig; for (DempsyHolder cur : dempsys.values()) { cur.dempsy.stop(); cur.actx.close(); } } }
From source file:com.nokia.dempsy.TestDempsy.java
public void runAllCombinations(String applicationContext, Checker checker) throws Throwable { int runCount = 0; for (String clusterManager : clusterManagers) { for (String[] alternatingTransports : transports) { // select one of the alternatingTransports String transport = alternatingTransports[runCount % alternatingTransports.length]; // alternate the dempsy configs String dempsyConfig = dempsyConfigs[runCount % dempsyConfigs.length]; if (!badCombos.contains(new ClusterId(clusterManager, transport))) { try { logger.debug("*****************************************************************"); logger.debug(" test: " + (checker == null ? "none" : checker) + " using " + dempsyConfig + "," + clusterManager + "," + transport); logger.debug("*****************************************************************"); DefaultRoutingStrategy.resetOutboundsChecking(); String[] ctx = new String[4]; ctx[0] = dempsyConfig; ctx[1] = clusterManager; ctx[2] = transport;//from w ww . j a v a 2 s.co m ctx[3] = "testDempsy/" + applicationContext; logger.debug("Starting up the appliction context ..."); ClassPathXmlApplicationContext actx = new ClassPathXmlApplicationContext(ctx); actx.registerShutdownHook(); Dempsy dempsy = (Dempsy) actx.getBean("dempsy"); assertTrue(TestUtils.waitForClustersToBeInitialized(baseTimeoutMillis, 20, dempsy)); WaitForShutdown waitingForShutdown = new WaitForShutdown(dempsy); Thread waitingForShutdownThread = new Thread(waitingForShutdown, "Waiting For Shutdown"); waitingForShutdownThread.start(); Thread.yield(); logger.debug("Running test ..."); if (checker != null) checker.check(actx); logger.debug("Done with test, stopping the application context ..."); actx.stop(); actx.destroy(); assertTrue(waitingForShutdown.waitForShutdownDoneLatch.await(baseTimeoutMillis, TimeUnit.MILLISECONDS)); assertTrue(waitingForShutdown.shutdown); logger.debug("Finished this pass."); } catch (AssertionError re) { logger.error("***************** FAILED ON: " + clusterManager + ", " + transport); throw re; } runCount++; } } } }
From source file:net.dfs.remote.main.ClientServicesStarter.java
public final void loadNode() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setProperties(props);/*from w w w . j a va2s .c o m*/ context.addBeanFactoryPostProcessor(configurer); context.setConfigLocation("net\\dfs\\remote\\filestorage\\spring-client.xml"); context.refresh(); context.start(); /* FileLocationTrackerImpl hash = new FileLocationTrackerImpl(); hash.removeAll(); */ log.info("Client Started"); FileReceiverSupport receiveFile = (FileReceiverSupport) context.getBean("receiveFile"); receiveFile.connectJavaSpace(); receiveFile.retrieveFile(); }