List of usage examples for org.springframework.context ConfigurableApplicationContext getBean
<T> T getBean(String name, Class<T> requiredType) throws BeansException;
From source file:demo.HttpIntegrationApplication.java
public static void main(String[] args) throws Exception { ConfigurableApplicationContext ctx = SpringApplication.run(HttpIntegrationApplication.class); Thread.sleep(2000);/* ww w . j a v a 2s . c o m*/ MessageChannel channel = ctx.getBean("input", MessageChannel.class); channel.send(MessageBuilder .withPayload("{\"userId\": \"invalid@mail.com\",\"password\": \"wrongpassword\"}").build()); }
From source file:org.spring.data.gemfire.app.main.LocatorApp.java
public static void main(final String... args) { ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext( LOCATOR_CONFIGURATION_FILE); applicationContext.registerShutdownHook(); LocatorLauncher locator = applicationContext.getBean("locator", LocatorLauncher.class); locator.start();/*from w w w . j a va 2 s .co m*/ System.out.printf("Starting Locator (%1$s) on port (%2$d)...%n", locator.getMember(), locator.getPort()); locator.waitOnLocator(); System.out.printf("Locator stopping..."); }
From source file:com.aeg.ims.transfer.protocol.ftp.OutboundChannelAdapter.java
public void runDemo() throws Exception { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "classpath:partners/CRH/OutboundChannelAdapter.xml"); MessageChannel ftpChannel = ctx.getBean("ftpChannel", MessageChannel.class); baseFolder.mkdirs();/* w w w .j ava 2 s .c o m*/ final File fileToSendA = new File(baseFolder, "a.txt"); final File fileToSendB = new File(baseFolder, "b.txt"); final InputStream inputStreamA = OutboundChannelAdapter.class.getResourceAsStream("/test-files/a.txt"); final InputStream inputStreamB = OutboundChannelAdapter.class.getResourceAsStream("/test-files/b.txt"); FileUtils.copyInputStreamToFile(inputStreamA, fileToSendA); FileUtils.copyInputStreamToFile(inputStreamB, fileToSendB); //assertTrue(fileToSendA.exists()); //assertTrue(fileToSendB.exists()); final Message<File> messageA = MessageBuilder.withPayload(fileToSendA).build(); final Message<File> messageB = MessageBuilder.withPayload(fileToSendB).build(); ftpChannel.send(messageA); ftpChannel.send(messageB); Thread.sleep(2000); //assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "a.txt").exists()); //assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "b.txt").exists()); ctx.close(); }
From source file:org.kew.rmf.reconciliation.configurations.MatchConfigurationTestingStepdefs.java
private LuceneMatcher getConfiguration(String config) throws Throwable { logger.debug("Considering initialising match controller with configuration {}", config); // Load up the matchers from the specified files if (!matchers.containsKey(config)) { String configurationFile = "/META-INF/spring/reconciliation-service/" + config + ".xml"; logger.debug("Loading configuration {} from {}", config, configurationFile); ConfigurableApplicationContext context = new GenericXmlApplicationContext(configurationFile); LuceneMatcher matcher = context.getBean("engine", LuceneMatcher.class); matcher.loadData();//from w ww . j a va 2 s . c o m logger.debug("Loaded data for configuration {}", config); matchers.put(config, matcher); logger.debug("Stored matcher with name {} from configuration {}", matcher.getConfig().getName(), config); } return matchers.get(config); }
From source file:com.github.exper0.efilecopier.ftp.FtpOutboundChannelAdapterSample.java
@Test public void runDemo1() throws Exception { // ConfigurableApplicationContext ctx = // new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml"); ///*from www.java2 s . c o m*/ // MessageChannel ftpChannel = ctx.getBean("ftpChannel", MessageChannel.class); ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( "META-INF/spring/integration/DynamicFtpOutboundChannelAdapterSample-context.xml"); MessageChannel ftpChannel = ctx.getBean("toDynRouter", MessageChannel.class); baseFolder.mkdirs(); final File fileToSendA = new File(baseFolder, "a.txt"); final File fileToSendB = new File(baseFolder, "b.txt"); final InputStream inputStreamA = FtpOutboundChannelAdapterSample.class .getResourceAsStream("/test-files/a.txt"); final InputStream inputStreamB = FtpOutboundChannelAdapterSample.class .getResourceAsStream("/test-files/b.txt"); FileUtils.copyInputStreamToFile(inputStreamA, fileToSendA); FileUtils.copyInputStreamToFile(inputStreamB, fileToSendB); assertTrue(fileToSendA.exists()); assertTrue(fileToSendB.exists()); final Message<File> messageA = MessageBuilder.withPayload(fileToSendA).setHeader("customer", "cust1") .build(); final Message<File> messageB = MessageBuilder.withPayload(fileToSendB).setHeader("customer", "cust1") .build(); ftpChannel.send(messageA); ftpChannel.send(messageB); Thread.sleep(2000); assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "a.txt").exists()); assertTrue(new File(TestSuite.FTP_ROOT_DIR + File.separator + "b.txt").exists()); LOGGER.info("Successfully transfered file 'a.txt' and 'b.txt' to a remote FTP location."); ctx.close(); }
From source file:com.rllc.batch.webcast.DynamicFtpChannelResolver.java
private synchronized MessageChannel createNewFileChannel(String fileName) { MessageChannel channel = this.channels.get(fileName); if (channel == null) { ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "dynamic-ftp-outbound-adapter-context.xml" }, false); this.setEnvironmentForFile(ctx, fileName); ctx.refresh();//from ww w.ja v a 2 s. c o m channel = ctx.getBean("toFtpChannel", MessageChannel.class); this.channels.put(fileName, channel); // Will works as the same reference is presented always this.contexts.put(channel, ctx); } return channel; }
From source file:demo.vmware.commands.CommandGetCounts.java
@Override public CommandResult run(ConfigurableApplicationContext mainContext, List<String> parameters) { // This will list all of the root regions. Not that it does not use templates like CommandGetAllRegions so this // may list more regions // we use the template API in CommandGetAllRegions so this may show regions we can't query GemFireCache foo = mainContext.getBean("cache", GemFireCache.class); Set<Region<?, ?>> allRegions = foo.rootRegions(); List<String> regionMessages = new ArrayList<String>(); for (Region oneRegion : allRegions) { regionMessages.add("Region: " + oneRegion.getName() + " contains " + oneRegion.size() + " elements"); }//from www . j a va2s . c o m return new CommandResult(null, regionMessages); }
From source file:com.github.exper0.efilecopier.ftp.DynamicFtpChannelResolver.java
private synchronized MessageChannel createNewCustomerChannel(String customer) { MessageChannel channel = this.channels.get(customer); if (channel == null) { ReportSettings settings = new FtpReportSettings(); settings.setPassword("demo"); settings.setUser("demo"); settings.setHost("localhost"); settings.setPort(4444);// w w w . j av a 2 s. co m ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "/META-INF/spring/integration/dynamic-ftp-outbound-adapter-context.xml" }, false, getContext(settings)); this.setEnvironmentForCustomer(ctx, customer); ctx.refresh(); channel = ctx.getBean("toFtpChannel", MessageChannel.class); this.channels.put(customer, channel); //Will works as the same reference is presented always this.contexts.put(channel, ctx); } return channel; }
From source file:com.aeg.ims.ftp.SftpInboundReceiveSample.java
public void runDemo() { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "classpath:/META-INF/spring/integration/SftpInboundReceiveSample-context.xml"); RemoteFileTemplate<LsEntry> template = null; String file1 = "a.txt"; String file2 = "b.txt"; String file3 = "c.bar"; new File("local-dir", file1).delete(); new File("local-dir", file2).delete(); try {/*from ww w. jav a 2 s .c o m*/ PollableChannel localFileChannel = context.getBean("receiveChannel", PollableChannel.class); @SuppressWarnings("unchecked") SessionFactory<LsEntry> sessionFactory = context.getBean(CachingSessionFactory.class); template = new RemoteFileTemplate<LsEntry>(sessionFactory); SftpTestUtils.createTestFiles(template, file1, file2, file3); SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class); adapter.start(); Message<?> received = localFileChannel.receive(); assertNotNull("Expected file", received); System.out.println("Received first file message: " + received); received = localFileChannel.receive(); assertNotNull("Expected file", received); System.out.println("Received second file message: " + received); received = localFileChannel.receive(1000); assertNull("Expected null", received); System.out.println("No third file was received as expected"); } finally { SftpTestUtils.cleanUp(template, file1, file2, file3); context.close(); assertTrue("Could note delete retrieved file", new File("local-dir", file1).delete()); assertTrue("Could note delete retrieved file", new File("local-dir", file2).delete()); } }
From source file:org.kew.rmf.reconciliation.service.ReconciliationService.java
/** * Loads a single configuration.//from w w w . j a v a 2 s.c om */ private void loadConfiguration(String configFileName) throws ReconciliationServiceException { synchronized (configurationStatuses) { ConfigurationStatus status = configurationStatuses.get(configFileName); assert (status == ConfigurationStatus.LOADING); } StopWatch sw = new Slf4JStopWatch(timingLogger); String configurationFile = CONFIG_BASE + configFileName; logger.info("{}: Loading configuration from file {}", configFileName, configurationFile); ConfigurableApplicationContext context = new GenericXmlApplicationContext(configurationFile); context.registerShutdownHook(); LuceneMatcher matcher = context.getBean("engine", LuceneMatcher.class); String configName = matcher.getConfig().getName(); contexts.put(configFileName, context); matchers.put(configName, matcher); try { matcher.loadData(); totals.put(configName, matcher.getIndexReader().numDocs()); logger.debug("{}: Loaded data", configName); // Append " (environment)" to Metadata name, to help with interactive testing Metadata metadata = getMetadata(configName); if (metadata != null) { if (!"prod".equals(environment)) { metadata.setName(metadata.getName() + " (" + environment + ")"); } } synchronized (configurationStatuses) { ConfigurationStatus status = configurationStatuses.get(configFileName); if (status != ConfigurationStatus.LOADING) { logger.error( "Unexpected configuration status '" + status + "' after loading " + configFileName); } configurationStatuses.put(configFileName, ConfigurationStatus.LOADED); } } catch (Exception e) { logger.error("Problem loading configuration " + configFileName, e); context.close(); totals.remove(configName); matchers.remove(configName); contexts.remove(configFileName); synchronized (configurationStatuses) { ConfigurationStatus status = configurationStatuses.get(configFileName); if (status != ConfigurationStatus.LOADING) { logger.error( "Unexpected configuration status '" + status + "' after loading " + configFileName); } configurationStatuses.remove(configFileName); } sw.stop("LoadConfiguration:" + configFileName + ".failure"); throw new ReconciliationServiceException("Problem loading configuration " + configFileName, e); } sw.stop("LoadConfiguration:" + configFileName + ".success"); }