List of usage examples for org.springframework.context ConfigurableApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:org.wso2.msf4j.spring.MSF4JSpringApplication.java
/** * This will add a given service class to the running instnace with given base path. * * @param configurableApplicationContext ConfigurableApplicationContext of running app * @param serviceClass Service class//from w ww. j a va 2s . com * @param basePath Base path teh servuce get registered */ public void addService(ConfigurableApplicationContext configurableApplicationContext, Class serviceClass, String basePath) { ClassPathBeanDefinitionScanner classPathBeanDefinitionScanner = new ClassPathBeanDefinitionScanner( (BeanDefinitionRegistry) configurableApplicationContext); classPathBeanDefinitionScanner.scan(serviceClass.getPackage().getName()); SpringMicroservicesRunner springMicroservicesRunner = configurableApplicationContext .getBean(SpringMicroservicesRunner.class); springMicroservicesRunner.deploy(basePath, configurableApplicationContext.getBean(serviceClass)); }
From source file:cl.vmetrix.operation.channels.OperationCh.java
@Override public boolean processMessage(String msg) throws VMWebServiceException { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); OperationService operationService = (OperationService) context.getBean("operationService"); logger.debug("Getting object from XML..."); XmlValidator xmlv = new XmlValidator(); try {/*from w w w.j a v a 2 s .com*/ if (xmlv.validateXMLstg(msg)) { try { logger.debug("XML Validation...OK!."); logger.debug("String XML is valid...start process..."); operation = ObjectFromXMLstg.createOperationObj(msg); } catch (JAXBException e) { logger.error("JAXBException in ObjectFromXMLstg.operation", e); logger.error("JAXBException unmarshaller the xml: " + msg); throw new VMWebServiceException("Exception processing this xml: " + msg, e); } catch (Exception e) { logger.error("Exception in ObjectFromXMLstg.operation", e); logger.error("Exception unmarshaller the xml: " + msg); throw new VMWebServiceException("Exception processing this xml: " + msg, e); } logger.debug("Start persistent process...."); origin = operation.getOrigin(); processDate = operation.getProcessDate(); dealNum = operation.getDealNum(); try { if (operation.getCashFlow() != null && operation.getCashFlow().size() > 0) operationService.persistCashflow(mappingCasflow(operation.getCashFlow())); if (operation.getInterest() != null && operation.getInterest().size() > 0) operationService.persistInterest(mappingInterest(operation.getInterest())); operationService.persistEquivCred(mappingEquivCred(operation.getEquivalenteCredito())); operationService.persistPricing(mappingPricing(operation.getPricing())); operationService.persistProfit(mappingProfit(operation.getProfit())); operationService.persistSide(mappingSide(operation.getSide())); operationService.persistTranInfo(mappingTranInfo(operation.getTransactionInfo())); operationService.persistTranSaction(mappingTransaction(operation.getTransaction())); } catch (Exception e) { logger.error("Exception saving operation. Could not process message", e); rollbackDB(operationService, operation); throw new VMWebServiceException("Exception processing this xml: " + msg, e); } return true; } else { logger.debug("XML is not valid...stop process."); throw new VMWebServiceException("XML is not valid...stop process."); } } catch (Exception e) { logger.error("Exception processing the operation. Could not process message", e); throw new VMWebServiceException("Exception processing this xml: " + msg, e); } finally { if (context != null) { logger.debug("Closing context.."); context.close(); } operationService = null; xmlv = null; operation = null; logger.debug("End persistent operation."); } }
From source file:com.payu.ratel.client.standalone.tests.StandaloneClientTest.java
@Before public void setup() { ConfigurableApplicationContext ctx = SpringApplication.run( new Object[] { TestServiceConfiguration.class, ServiceDiscoveryConfig.class, DiscoveryServerMain.class }, new String[] { "--server.port=17070", "--" + JBOSS_BIND_ADDRESS + "=localhost", "--" + JBOSS_BIND_PORT + "=17070", "--spring.jmx.enabled=false", "--" + SERVICE_DISCOVERY_ADDRESS + "=http://localhost:17070" + "/server/discovery" }); final InMemoryDiscoveryServer server = ctx.getBean(InMemoryDiscoveryServer.class); Awaitility.await().atMost(40, TimeUnit.SECONDS).until(new Runnable() { @Override//from ww w. ja v a 2s .co m public void run() { assertThat(server.fetchAllServices()).hasSize(2); } }); this.startedApp = ctx; }
From source file:org.metis.cassandra.CqlComponent.java
/** * Initialize the ClientMappers used by this component. Note that this * initial implementation only supports one mapper. * <p>//from ww w. j a v a 2 s.com */ private void initClientMapper(ConfigurableApplicationContext cassandraContext) throws Exception { ClientMapper clientMapper = null; try { // find the one client mapper clientMapper = cassandraContext.getBean(ClientMapper.class); } catch (NoSuchBeanDefinitionException ignore) { } if (clientMapper != null) { getComponentProfile().setClientMapper(clientMapper); LOG.trace("initClientMapper: using a client mapper"); } else { LOG.trace("initClientMapper: not using a client mapper"); } }
From source file:org.copperengine.core.test.persistent.BasePersistentWorkflowTest.java
public void testQueryAllActive(String dsContext) throws Exception { assumeFalse(skipTests());/*from www .ja v a 2 s .c om*/ final ConfigurableApplicationContext context = createContext(dsContext); cleanDB(context.getBean(DataSource.class)); final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class); try { engine.startup(); // just check, that the underlying SQL statements are ok. assertEquals(0, engine.queryActiveWorkflowInstances(null, 100).size()); assertEquals(0, engine.queryActiveWorkflowInstances("foo.john.Doe", 100).size()); } finally { closeContext(context); } assertEquals(EngineState.STOPPED, engine.getEngineState()); assertEquals(0, engine.getNumberOfWorkflowInstances()); }
From source file:org.copperengine.core.test.persistent.BasePersistentWorkflowTest.java
public void testWaitForEver(String dsContext) throws Exception { assumeFalse(skipTests());// w ww .j a va 2 s . c o m logger.info("running testWaitForEver"); final ConfigurableApplicationContext context = createContext(dsContext); cleanDB(context.getBean(DataSource.class)); final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class); engine.startup(); final BackChannelQueue backChannelQueue = context.getBean(BackChannelQueue.class); try { assertEquals(EngineState.STARTED, engine.getEngineState()); final String uuid = UUID.randomUUID().toString(); engine.run(WaitForEverTestWF_NAME, uuid); WorkflowResult x = backChannelQueue.dequeue(5, TimeUnit.SECONDS); assertNull(x); } finally { closeContext(context); } assertEquals(EngineState.STOPPED, engine.getEngineState()); assertEquals(0, engine.getNumberOfWorkflowInstances()); }
From source file:org.copperengine.core.test.persistent.BasePersistentWorkflowTest.java
public void testFailOnDuplicateInsert(String dsContext) throws Exception { assumeFalse(skipTests());//from www . j av a 2 s . com logger.info("running testFailOnDuplicateInsert"); final String DATA = createTestData(50); final ConfigurableApplicationContext context = createContext(dsContext); cleanDB(context.getBean(DataSource.class)); context.getBean(DatabaseDialect.class).setRemoveWhenFinished(false); final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class); engine.startup(); try { WorkflowInstanceDescr<String> desc = new WorkflowInstanceDescr<String>(PersistentUnitTestWorkflow_NAME, DATA, "DUPLICATE#ID", 1, null); engine.run(desc); engine.run(desc); org.junit.Assert.fail("expected an DuplicateIdException"); } catch (DuplicateIdException e) { // ok } finally { closeContext(context); } assertEquals(EngineState.STOPPED, engine.getEngineState()); assertTrue(engine.getNumberOfWorkflowInstances() <= 1); }
From source file:org.copperengine.core.test.persistent.BasePersistentWorkflowTest.java
public void testMulipleResponsesForSameCidPersistentTestWorkflow(String dsContext) throws Exception { assumeFalse(skipTests());//from w w w. j a v a 2s. co m final ConfigurableApplicationContext context = createContext(dsContext); cleanDB(context.getBean(DataSource.class)); final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class); try { engine.startup(); String cid = "testSingleCID"; try { engine.run("MulipleResponsesForSameCidPersistentTestWorkflow", cid); Thread.sleep(1000); // wait for it to start up for (int i = 1; i <= 9; i++) { manualSend(engine, cid, "Response#" + i); } manualSend(engine, cid, "GG"); Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } } finally { closeContext(context); } assertEquals(EngineState.STOPPED, engine.getEngineState()); assertEquals(0, engine.getNumberOfWorkflowInstances()); }
From source file:org.copperengine.core.test.persistent.BasePersistentWorkflowTest.java
public void testParentChildWorkflow(String dsContext) throws Exception { assumeFalse(skipTests());/* w ww .j a v a 2 s . co m*/ logger.info("running testParentChildWorkflow"); final int NUMB = 20; final ConfigurableApplicationContext context = createContext(dsContext); cleanDB(context.getBean(DataSource.class)); final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class); engine.startup(); final BackChannelQueue backChannelQueue = context.getBean(BackChannelQueue.class); try { assertEquals(EngineState.STARTED, engine.getEngineState()); for (int i = 0; i < NUMB; i++) { engine.run("org.copperengine.core.test.persistent.subworkflow.TestParentWorkflow", null); } for (int i = 0; i < NUMB; i++) { WorkflowResult x = backChannelQueue.dequeue(DEQUEUE_TIMEOUT, TimeUnit.SECONDS); assertNotNull(x); assertNull(x.getResult()); assertNull(x.getException()); } } finally { closeContext(context); } assertEquals(EngineState.STOPPED, engine.getEngineState()); assertEquals(0, engine.getNumberOfWorkflowInstances()); }
From source file:org.copperengine.core.test.persistent.BasePersistentWorkflowTest.java
public void testTimeouts(String dsContext) throws Exception { assumeFalse(skipTests());//from w w w.j ava 2 s. co m logger.info("running testTimeouts"); final int NUMB = 10; final ConfigurableApplicationContext context = createContext(dsContext); cleanDB(context.getBean(DataSource.class)); final PersistentScottyEngine engine = context.getBean(PersistentScottyEngine.class); engine.startup(); final BackChannelQueue backChannelQueue = context.getBean(BackChannelQueue.class); try { assertEquals(EngineState.STARTED, engine.getEngineState()); for (int i = 0; i < NUMB; i++) { engine.run("org.copperengine.core.test.persistent.TimingOutPersistentUnitTestWorkflow", null); } for (int i = 0; i < NUMB; i++) { WorkflowResult x = backChannelQueue.dequeue(DEQUEUE_TIMEOUT, TimeUnit.SECONDS); assertNotNull(x); assertNull(x.getResult()); assertNull(x.getException()); } } finally { closeContext(context); } assertEquals(EngineState.STOPPED, engine.getEngineState()); assertEquals(0, engine.getNumberOfWorkflowInstances()); }