diff --git a/README.md b/README.md index eb6b3ef..8a367c4 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ The Spring Integration Extensions project provides extension modules for [Spring * [Splunk][] Support * [Amazon Web Services (AWS)][] Support +## Samples + +Under the `samples` directory, you will find samples for the various modules. Please refer to the documentation of each sample for further details. + ## Getting support Check out the [Spring Integration forums][] and the [spring-integration][spring-integration tag] tag diff --git a/samples/smb/README.md b/samples/smb/README.md new file mode 100644 index 0000000..398d25a --- /dev/null +++ b/samples/smb/README.md @@ -0,0 +1,58 @@ +Spring Integration - SMB Sample +=============================== + +## Introduction + +This samples demonstrate some simple usage of the *Spring Integration* support for [Server Message Block][] (SMB). The sample will poll an SMB remote directory. + +## How to Run the Sample + +You can execute this sample simply via [Maven][]: + + $ mvn clean package exec:java + +The sample will ask you for: + +* SMB Host +* SMB Share and Directory +* SMB Username +* SMB Password + +When running the sample you should see the following screen output: + + 14:19:02.145 INFO [org.springframework.integration.samples.smb.Main.main()][org.springframework.integration.samples.smb.Main] + ========================================================= + + Welcome to the Spring Integration Smb Sample + + For more information please visit: + https://github.com/SpringSource/spring-integration-extensions + + ========================================================= + Please enter the: + - SMB Host + - SMB Share and Directory + - SMB Username + - SMB Password + Host: mySmbHost + Share and Directory (e.g. myFile/path/to/): demoShare/demoPath/ + Username (e.g. guest): guest + Password (can be empty): + 14:19:22.130 INFO [org.springframework.integration.samples.smb.Main.main()][org.springframework.integration.samples.smb.Main] + ========================================================= + + Please press 'q + Enter' to quit the application. + + ========================================================= + Polling from Share: smb://guest@mySmbHost/demoShare/demoPath/ + 14:19:23.044 INFO [task-scheduler-1][org.springframework.integration.samples.smb] File Name: demo.data(597) + +The polled files will be stored under `target/smb-out`. + +-------------------------------------------------------------------------------- + +For help please take a look at the [Spring Integration documentation][] + +[Server Message Block]: http://en.wikipedia.org/wiki/Server_Message_Block +[Maven]: http://maven.apache.org/ +[Spring Integration documentation]: http://www.springsource.org/spring-integration diff --git a/samples/smb/pom.xml b/samples/smb/pom.xml new file mode 100644 index 0000000..fd1d568 --- /dev/null +++ b/samples/smb/pom.xml @@ -0,0 +1,112 @@ + + 4.0.0 + + org.springframework.integration.samples + smb + 1.0.0.BUILD-SNAPSHOT + jar + + smb + http://www.springsource.org/spring-integration + + + 2.2.1 + + + + UTF-8 + 2.2.1.RELEASE + 1.0.0.BUILD-SNAPSHOT + 1.2.17 + 4.11 + + + + + repo.springsource.org.milestone + Spring Framework Maven Milestone Repository + https://repo.springsource.org/libs-snapshot + + + + + + + maven-eclipse-plugin + 2.9 + + + org.springframework.ide.eclipse.core.springnature + + + org.springframework.ide.eclipse.core.springbuilder + + true + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + -Xlint:all + true + true + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + org.springframework.integration.samples.smb.Main + + + + + + + + + + + junit + junit + ${junit.version} + test + + + + + + org.springframework.integration + spring-integration-core + ${spring.integration.version} + + + + org.springframework.integration + spring-integration-file + ${spring.integration.version} + + + + org.springframework.integration + spring-integration-smb + ${spring.integration.smb.version} + + + + + + log4j + log4j + ${log4j.version} + + + + diff --git a/samples/smb/src/main/java/org/springframework/integration/samples/smb/Main.java b/samples/smb/src/main/java/org/springframework/integration/samples/smb/Main.java new file mode 100644 index 0000000..6963c7b --- /dev/null +++ b/samples/smb/src/main/java/org/springframework/integration/samples/smb/Main.java @@ -0,0 +1,118 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.samples.smb; + +import java.util.Scanner; + +import org.apache.log4j.Logger; +import org.springframework.context.support.GenericXmlApplicationContext; +import org.springframework.integration.smb.session.SmbSessionFactory; + + +/** + * Starts the Spring Context and will initialize the Spring Integration routes. + * + * @author Gunnar Hillert + * @since 1.0 + * + */ +public final class Main { + + private static final Logger LOGGER = Logger.getLogger(Main.class); + + private Main() { } + + /** + * Load the Spring Integration Application Context + * + * @param args - command line arguments + */ + public static void main(final String... args) { + + final Scanner scanner = new Scanner(System.in); + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("\n=========================================================" + + "\n " + + "\n Welcome to the Spring Integration Smb Sample " + + "\n " + + "\n For more information please visit: " + + "\nhttps://github.com/SpringSource/spring-integration-extensions" + + "\n " + + "\n=========================================================" ); + } + + final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); + + System.out.println("Please enter the: "); + System.out.println("\t- SMB Host"); + System.out.println("\t- SMB Share and Directory"); + System.out.println("\t- SMB Username"); + System.out.println("\t- SMB Password"); + + System.out.print("Host: "); + final String host = scanner.nextLine(); + + System.out.print("Share and Directory (e.g. myFile/path/to/): "); + final String shareAndDir = scanner.nextLine(); + + System.out.print("Username (e.g. guest): "); + final String username = scanner.nextLine(); + + System.out.print("Password (can be empty): "); + final String password = scanner.nextLine(); + + context.getEnvironment().getSystemProperties().put("host", host); + context.getEnvironment().getSystemProperties().put("shareAndDir", shareAndDir); + context.getEnvironment().getSystemProperties().put("username", username); + context.getEnvironment().getSystemProperties().put("password", password); + + context.load("classpath:META-INF/spring/integration/*-context.xml"); + context.registerShutdownHook(); + context.refresh(); + + context.registerShutdownHook(); + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("\n=========================================================" + + "\n " + + "\n Please press 'q + Enter' to quit the application. " + + "\n " + + "\n=========================================================" ); + } + + SmbSessionFactory smbSessionFactory = context.getBean("smbSession", SmbSessionFactory.class); + + System.out.println("Polling from Share: " + smbSessionFactory.getUrl()); + + while (true) { + + final String input = scanner.nextLine(); + + if("q".equals(input.trim())) { + break; + } + + } + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Exiting application...bye."); + } + + System.exit(0); + + } +} diff --git a/samples/smb/src/main/resources/META-INF/spring/integration/spring-integration-context.xml b/samples/smb/src/main/resources/META-INF/spring/integration/spring-integration-context.xml new file mode 100644 index 0000000..0e29784 --- /dev/null +++ b/samples/smb/src/main/resources/META-INF/spring/integration/spring-integration-context.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/smb/src/main/resources/log4j.xml b/samples/smb/src/main/resources/log4j.xml new file mode 100644 index 0000000..ca8ef90 --- /dev/null +++ b/samples/smb/src/main/resources/log4j.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +