Skip to content

Commit 416cc39

Browse files
committed
INTEXT-40 Add ZIP Transformer
* Add zip-transformer * Add unzip-transformer * Add UnZipResultSplitter * Add sample For reference see: https://jira.springsource.org/browse/INTEXT-40
1 parent ba52da8 commit 416cc39

File tree

62 files changed

+4694
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+4694
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ target
2222
spring-integration-aws/src/test/resources/awscredentials.properties
2323
*.orig
2424
/spring-integration-java-dsl/hostkey.ser
25+
.springBeans
26+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The Spring Integration Extensions project provides extension modules for [Spring
1414
* [Splunk][] Support
1515
* [Voldemort][] Support
1616
* [XQuery][] Support
17-
17+
* Zip Support (Compression and Uncompression)
1818

1919
## Samples
2020

samples/zip/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Spring Integration Zip Sample
2+
===================
3+
4+
This sample illustrates the usage of the Spring Integration Zip Extension. It uses the following components:
5+
6+
* zip-transformer
7+
* unzip-transformer
8+
9+
You can run the application by either
10+
11+
* running the "Main" class from within STS (Right-click on Main class --> Run As --> Java Application)
12+
* or from the command line:
13+
- mvn package
14+
- mvn exec:java
15+
16+
You should see a screen as the following:
17+
18+
```
19+
=========================================================
20+
21+
Welcome to the Spring Integration Zip Sample
22+
23+
For more information please visit:
24+
http://www.springsource.org/spring-integration
25+
26+
=========================================================
27+
17:08:41.883 INFO [org.springframework.integration.samples.zip.Main.main()][org.springframework.integration.samples.zip.SpringIntegrationUtils]
28+
=========================================================
29+
30+
Intput directory is: '/dev/spring-integration-extensions/samples/zip/input-zip'
31+
Intput directory is: '/dev/spring-integration-extensions/samples/zip/input-uncompressed'
32+
Output directory is: 'target/output/decompressedFilesOut'
33+
Output directory is: 'target/output/zipFilesOut'
34+
35+
=========================================================
36+
17:08:41.887 INFO [org.springframework.integration.samples.zip.Main.main()][org.springframework.integration.samples.zip.Main]
37+
=========================================================
38+
39+
Please press 'q + Enter' to quit the application.
40+
41+
=========================================================
42+
```
43+
## Compressing Files
44+
45+
Drop an uncompressed file into the **input-uncompressed** directory. The file will be compressed and stored under **target/output/zipFilesOut**.
46+
47+
## Uncompressing Files
48+
49+
Drop a compressed file into the **input-zip** directory. The file will be decompressed and stored under **target/output/decompressedFilesOut**.
50+
51+
--------------------------------------------------------------------------------
52+
53+
For help please take a look at the Spring Integration documentation:
54+
55+
http://www.springsource.org/spring-integration
56+

samples/zip/pom.xml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.springframework.integration.samples</groupId>
6+
<artifactId>zip-sample</artifactId>
7+
<version>1.0.0.BUILD-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>zip-sample</name>
11+
<url>http://projects.spring.io/spring-integration/</url>
12+
13+
<prerequisites>
14+
<maven>2.2.1</maven>
15+
</prerequisites>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
<spring.integration.zip.version>1.0.0.BUILD-SNAPSHOT</spring.integration.zip.version>
20+
<log4j.version>1.2.17</log4j.version>
21+
<junit.version>4.11</junit.version>
22+
</properties>
23+
24+
<repositories>
25+
<repository>
26+
<id>repo.spring.io.milestone</id>
27+
<name>Spring Framework Maven Milestone Repository</name>
28+
<url>https://repo.spring.io/libs-milestone</url>
29+
</repository>
30+
</repositories>
31+
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<artifactId>maven-eclipse-plugin</artifactId>
36+
<version>2.9</version>
37+
<configuration>
38+
<additionalProjectnatures>
39+
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
40+
</additionalProjectnatures>
41+
<additionalBuildcommands>
42+
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
43+
</additionalBuildcommands>
44+
<downloadSources>true</downloadSources>
45+
<downloadJavadocs>true</downloadJavadocs>
46+
</configuration>
47+
</plugin>
48+
<plugin>
49+
<groupId>org.apache.maven.plugins</groupId>
50+
<artifactId>maven-compiler-plugin</artifactId>
51+
<version>3.0</version>
52+
<configuration>
53+
<source>1.6</source>
54+
<target>1.6</target>
55+
<compilerArgument>-Xlint:all</compilerArgument>
56+
<showWarnings>true</showWarnings>
57+
<showDeprecation>true</showDeprecation>
58+
</configuration>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.codehaus.mojo</groupId>
62+
<artifactId>exec-maven-plugin</artifactId>
63+
<version>1.2.1</version>
64+
<configuration>
65+
<mainClass>org.springframework.integration.samples.zip.Main</mainClass>
66+
</configuration>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
71+
<dependencies>
72+
73+
<!-- Testing -->
74+
75+
<dependency>
76+
<groupId>junit</groupId>
77+
<artifactId>junit</artifactId>
78+
<version>${junit.version}</version>
79+
<scope>test</scope>
80+
</dependency>
81+
82+
<!-- Spring Integration -->
83+
84+
<dependency>
85+
<groupId>org.springframework.integration</groupId>
86+
<artifactId>spring-integration-zip</artifactId>
87+
<version>${spring.integration.zip.version}</version>
88+
</dependency>
89+
90+
<dependency>
91+
<groupId>org.springframework</groupId>
92+
<artifactId>spring-core</artifactId>
93+
<version>4.2.0.RC1</version>
94+
</dependency>
95+
96+
<!-- Logging -->
97+
98+
<dependency>
99+
<groupId>log4j</groupId>
100+
<artifactId>log4j</artifactId>
101+
<version>${log4j.version}</version>
102+
</dependency>
103+
104+
<!-- Other -->
105+
106+
<dependency>
107+
<groupId>commons-io</groupId>
108+
<artifactId>commons-io</artifactId>
109+
<version>2.4</version>
110+
</dependency>
111+
112+
<dependency>
113+
<groupId>org.slf4j</groupId>
114+
<artifactId>slf4j-jcl</artifactId>
115+
<version>1.7.12</version>
116+
</dependency>
117+
118+
</dependencies>
119+
</project>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.integration.samples.zip;
17+
18+
import java.util.Scanner;
19+
20+
import org.apache.log4j.Logger;
21+
import org.springframework.context.support.AbstractApplicationContext;
22+
import org.springframework.context.support.ClassPathXmlApplicationContext;
23+
24+
25+
/**
26+
* Starts the Spring Context and will initialize the Spring Integration routes.
27+
*
28+
* @author Gunnar Hillert
29+
* @since 1.0
30+
*
31+
*/
32+
public final class Main {
33+
34+
private static final Logger LOGGER = Logger.getLogger(Main.class);
35+
36+
private Main() { }
37+
38+
/**
39+
* Load the Spring Integration Application Context
40+
*
41+
* @param args - command line arguments
42+
*/
43+
public static void main(final String... args) {
44+
45+
if (LOGGER.isInfoEnabled()) {
46+
LOGGER.info("\n========================================================="
47+
+ "\n "
48+
+ "\n Welcome to the Spring Integration Zip Sample "
49+
+ "\n "
50+
+ "\n For more information please visit: "
51+
+ "\n http://www.springsource.org/spring-integration "
52+
+ "\n "
53+
+ "\n=========================================================" );
54+
}
55+
56+
final AbstractApplicationContext context =
57+
new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");
58+
59+
context.registerShutdownHook();
60+
61+
SpringIntegrationUtils.displayDirectories(context);
62+
63+
final Scanner scanner = new Scanner(System.in);
64+
65+
if (LOGGER.isInfoEnabled()) {
66+
LOGGER.info("\n========================================================="
67+
+ "\n "
68+
+ "\n Please press 'q + Enter' to quit the application. "
69+
+ "\n "
70+
+ "\n=========================================================" );
71+
}
72+
73+
while (!scanner.hasNext("q")) {
74+
//Do nothing unless user presses 'q' to quit.
75+
}
76+
77+
if (LOGGER.isInfoEnabled()) {
78+
LOGGER.info("Exiting application...bye.");
79+
}
80+
81+
System.exit(0);
82+
83+
}
84+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright 2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.samples.zip;
18+
19+
import java.io.File;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import org.apache.commons.logging.Log;
25+
import org.apache.commons.logging.LogFactory;
26+
import org.springframework.beans.DirectFieldAccessor;
27+
import org.springframework.context.ApplicationContext;
28+
import org.springframework.expression.Expression;
29+
import org.springframework.integration.file.FileReadingMessageSource;
30+
import org.springframework.integration.file.FileWritingMessageHandler;
31+
32+
/**
33+
* Displays the names of the input and output directories.
34+
*
35+
* @author Gunnar Hillert
36+
* @since 1.0
37+
*
38+
*/
39+
public final class SpringIntegrationUtils {
40+
41+
private static final Log logger = LogFactory.getLog(SpringIntegrationUtils.class);
42+
43+
private SpringIntegrationUtils() { }
44+
45+
/**
46+
* Helper Method to dynamically determine and display input and output
47+
* directories as defined in the Spring Integration context.
48+
*
49+
* @param context Spring Application Context
50+
*/
51+
public static void displayDirectories(final ApplicationContext context) {
52+
53+
final Map<String, FileReadingMessageSource> fileReadingMessageSources = context.getBeansOfType(FileReadingMessageSource.class);
54+
55+
final List<String> inputDirectories = new ArrayList<String>();
56+
57+
for (FileReadingMessageSource source : fileReadingMessageSources.values()) {
58+
final File inDir = (File) new DirectFieldAccessor(source).getPropertyValue("directory");
59+
inputDirectories.add(inDir.getAbsolutePath());
60+
}
61+
62+
63+
final Map<String, FileWritingMessageHandler> fileWritingMessageHandlers = context.getBeansOfType(FileWritingMessageHandler.class);
64+
65+
final List<String> outputDirectories = new ArrayList<String>();
66+
67+
for (final FileWritingMessageHandler messageHandler : fileWritingMessageHandlers.values()) {
68+
final Expression outDir = (Expression) new DirectFieldAccessor(messageHandler).getPropertyValue("destinationDirectoryExpression");
69+
outputDirectories.add(outDir.getExpressionString());
70+
}
71+
72+
final StringBuilder stringBuilder = new StringBuilder();
73+
74+
stringBuilder.append("\n=========================================================");
75+
stringBuilder.append("\n");
76+
77+
for (final String inputDirectory : inputDirectories) {
78+
stringBuilder.append("\n Intput directory is: '" + inputDirectory + "'");
79+
}
80+
81+
for (final String outputDirectory : outputDirectories) {
82+
stringBuilder.append("\n Output directory is: '" + outputDirectory + "'");
83+
}
84+
85+
stringBuilder.append("\n\n=========================================================");
86+
87+
logger.info(stringBuilder.toString());
88+
89+
}
90+
91+
}

0 commit comments

Comments
 (0)