+ "\n "
+ HORIZONTAL_LINE );
}
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
final ConfigurableEnvironment environment = context.getEnvironment();
System.out.println("What would you like to do?");
System.out.println("\t1. Upload a file to Amazon S3");
System.out.println("\t2. Poll files from Amazon S3");
System.out.println("\tq. Quit the application");
System.out.print(" > ");
String filePath;
while (true) {
final String input = scanner.nextLine();
if("1".equals(input.trim())) {
System.out.println("Uploading to Amazon S3...");
environment.setActiveProfiles("upload-to-s3");
setupCredentials(environment, scanner);
setupS3info(environment, scanner);
context.load("classpath:META-INF/spring/integration/*-context.xml");
context.registerShutdownHook();
context.refresh();
System.out.print("\nPlease enter the path to the file you want to upload: ");
filePath = scanner.nextLine();
final MessageChannel messageChannel = context.getBean("s3channel", MessageChannel.class);
messageChannel.send(MessageBuilder.withPayload(new File(filePath)).build());
break;
}
else if("2".equals(input.trim())) {
System.out.println("Polling files from Amazon S3...");
environment.setActiveProfiles("poll-s3");
setupCredentials(environment, scanner);
setupS3info(environment, scanner);
context.load("classpath:META-INF/spring/integration/*-context.xml");
context.registerShutdownHook();