Merge pull request #28 from ghillert/INTEXT-35

* ghillert-INTEXT-35:
  INTEXT-35 - Add SMB Sample For reference see: https://jira.springsource.org/browse/INTEXT-35
This commit is contained in:
Gunnar Hillert
2013-02-22 14:44:05 -05:00
6 changed files with 363 additions and 0 deletions

View File

@@ -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

58
samples/smb/README.md Normal file
View File

@@ -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

112
samples/smb/pom.xml Normal file
View File

@@ -0,0 +1,112 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>smb</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<packaging>jar</packaging>
<name>smb</name>
<url>http://www.springsource.org/spring-integration</url>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.integration.version>2.2.1.RELEASE</spring.integration.version>
<spring.integration.smb.version>1.0.0.BUILD-SNAPSHOT</spring.integration.smb.version>
<log4j.version>1.2.17</log4j.version>
<junit.version>4.11</junit.version>
</properties>
<repositories>
<repository>
<id>repo.springsource.org.milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>https://repo.springsource.org/libs-snapshot</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.springframework.integration.samples.smb.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Spring Integration -->
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-file</artifactId>
<version>${spring.integration.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-smb</artifactId>
<version>${spring.integration.smb.version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -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);
}
}

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-smb="http://www.springframework.org/schema/integration/smb"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/smb http://www.springframework.org/schema/integration/smb/spring-integration-smb.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder />
<!--
smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?[param=value[param2=value2[...]]]
-->
<bean id="smbSession" class="org.springframework.integration.smb.session.SmbSessionFactory">
<property name="host" value="${host}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="shareAndDir" value="${shareAndDir}"/>
</bean>
<int-smb:inbound-channel-adapter local-directory="target/smb-transfer-work"
session-factory="smbSession" remote-directory="."
auto-create-local-directory="true" delete-remote-files="false"
channel="inboundChannel">
<int:poller fixed-rate="10000" max-messages-per-poll="1"/>
</int-smb:inbound-channel-adapter>
<int:channel id="inboundChannel">
<int:interceptors>
<int:wire-tap channel="loggit"/>
</int:interceptors>
</int:channel>
<int:logging-channel-adapter id="loggit" level="INFO"
logger-name="org.springframework.integration.samples.smb"
expression="'File Name: ' + payload.name + '(' + payload.length() + ')'"/>
<int-file:outbound-channel-adapter channel="inboundChannel" directory="target/smb-out"/>
</beans>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
</layout>
</appender>
<!-- Loggers -->
<logger name="org.springframework.integration">
<level value="warn" />
</logger>
<logger name="org.springframework.integration.samples.smb">
<level value="info" />
</logger>
<!-- Root Logger -->
<root>
<priority value="warn" />
<appender-ref ref="console" />
</root>
</log4j:configuration>