Package org.springframework.context

Examples of org.springframework.context.ConfigurableApplicationContext


@Configuration
@EnableAutoConfiguration
public class Application {

  public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
    System.out.println("Hit 'Enter' to terminate");
    System.in.read();
    ctx.close();
  }
View Full Code Here


*/
public class SftpInboundReceiveSample {

  @Test
  public void runDemo(){
    ConfigurableApplicationContext context =
        new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpInboundReceiveSample-context.xml", this.getClass());
    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 {
      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());
    }
  }
View Full Code Here

*/
public class SftpOutboundGatewaySample {

  @Test
  public void testLsGetRm() throws Exception {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
        "classpath:/META-INF/spring/integration/SftpOutboundGatewaySample-context.xml");
    ToSftpFlowGateway toFtpFlow = ctx.getBean(ToSftpFlowGateway.class);
    RemoteFileTemplate<LsEntry> template = null;
    String file1 = "1.ftptest";
    String file2 = "2.ftptest";
    File tmpDir = new File(System.getProperty("java.io.tmpdir"));

    try {
      // remove the previous output files if necessary
      new File(tmpDir, file1).delete();
      new File(tmpDir, file2).delete();

      @SuppressWarnings("unchecked")
      SessionFactory<LsEntry> sessionFactory = ctx.getBean(CachingSessionFactory.class);
      template = new RemoteFileTemplate<LsEntry>(sessionFactory);
      SftpTestUtils.createTestFiles(template, file1, file2);

      // execute the flow (ls, get, rm, aggregate results)
      List<Boolean> rmResults = toFtpFlow.lsGetAndRmFiles("si.sftp.sample");


      //Check everything went as expected, and clean up
      assertEquals(2, rmResults.size());
      for (Boolean result : rmResults) {
        assertTrue(result);
      }

    }
    finally {
      SftpTestUtils.cleanUp(template, file1, file2);
      ctx.close();
      assertTrue("Could note delete retrieved file", new File(tmpDir, file1).delete());
      assertTrue("Could note delete retrieved file", new File(tmpDir, file2).delete());
    }
  }
View Full Code Here

  private static Logger logger = Logger.getLogger(ControlBusDemoTest.class);

  @Test
  public void demoControlBus(){
    ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext(
        "/META-INF/spring/integration/ControlBusDemo-context.xml");
    MessageChannel controlChannel = ac.getBean("controlChannel", MessageChannel.class);
    PollableChannel adapterOutputChanel = ac.getBean("adapterOutputChanel", PollableChannel.class);
    logger.info("Received before adapter started: " + adapterOutputChanel.receive(1000));
    controlChannel.send(new GenericMessage<String>("@inboundAdapter.start()"));
    logger.info("Received before adapter started: " + adapterOutputChanel.receive(1000));
    controlChannel.send(new GenericMessage<String>("@inboundAdapter.stop()"));
    logger.info("Received after adapter stopped: " + adapterOutputChanel.receive(1000));
    ac.close();
  }
View Full Code Here

  }

  private synchronized MessageChannel createNewCustomerChannel(String customer) {
    MessageChannel channel = this.channels.get(customer);
    if (channel == null) {
      ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
          new String[] { "/META-INF/spring/integration/dynamic-ftp-outbound-adapter-context.xml" },
          false);
      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;
View Full Code Here

public class FeedInboundChannelAdapterSample {

  @SuppressWarnings("unchecked")
  @Test
  public void runDemo(){
    ConfigurableApplicationContext ac =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/FeedInboundChannelAdapterSample-context.xml");
    PollableChannel feedChannel = ac.getBean("feedChannel", PollableChannel.class);
    for (int i = 0; i < 10; i++) {
      Message<SyndEntry> message = (Message<SyndEntry>) feedChannel.receive(1000);
      if (message != null){
        SyndEntry entry = message.getPayload();
        System.out.println(entry.getPublishedDate() + " - " + entry.getTitle());
      }
      else {
        break;
      }
    }
    ac.close();
  }
View Full Code Here

  private final File baseFolder = new File("target" + File.separator + "toSend");

  @Test
  public void runDemo() throws Exception{

    ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpOutboundChannelAdapterSample-context.xml");

    MessageChannel ftpChannel = ctx.getBean("ftpChannel", 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).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());

    LOGGER.info("Successfully transfered file 'a.txt' and 'b.txt' to a remote FTP location.");
    ctx.close();
  }
View Full Code Here

  private static final Logger LOGGER = Logger.getLogger(FtpInboundChannelAdapterSample.class);

  @Test
  public void runDemo() throws Exception{
    ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/FtpInboundChannelAdapterSample-context.xml");

    PollableChannel ftpChannel = ctx.getBean("ftpChannel", PollableChannel.class);

    Message<?> message1 = ftpChannel.receive(2000);
    Message<?> message2 = ftpChannel.receive(2000);
    Message<?> message3 = ftpChannel.receive(1000);

    LOGGER.info(String.format("Received first file message: %s.", message1));
    LOGGER.info(String.format("Received second file message: %s.", message2));
    LOGGER.info(String.format("Received nothing else: %s.", message3));

    assertNotNull(message1);
    assertNotNull(message2);
    assertNull("Was NOT expecting a third message.", message3);

    ctx.close();
  }
View Full Code Here

* @since 3.0
*/
public class Application {

  public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("client-context.xml", Application.class);
    System.in.read();
    ctx.close();
  }
View Full Code Here

public class FtpOutboundGatewaySample {


  @Test
  public void testLsGetRm() throws Exception {
    ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
        "classpath:/META-INF/spring/integration/FtpOutboundGatewaySample-context.xml");

    final ToFtpFlowGateway toFtpFlow = ctx.getBean(ToFtpFlowGateway.class);

    // execute the flow (ls, get, rm, aggregate results)
    List<Boolean> rmResults = toFtpFlow.lsGetAndRmFiles("/");

    //Check everything went as expected, and clean up
    assertEquals("Was expecting the collection 'rmResults' to contain 2 elements.", 2, rmResults.size());

    for (Boolean result : rmResults) {
      assertTrue(result);
    }

    assertTrue("Expected FTP remote directory to be empty"new File(TestSuite.FTP_ROOT_DIR).delete());

    ctx.close();
  }
View Full Code Here

TOP

Related Classes of org.springframework.context.ConfigurableApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.