Migrate Zip sample to SI-Samples project
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
Spring Integration Zip Sample
|
||||
===================
|
||||
|
||||
This sample illustrates the usage of the Spring Integration Zip Extension. It uses the following components:
|
||||
|
||||
* zip-transformer
|
||||
* unzip-transformer
|
||||
|
||||
You can run the application by either
|
||||
|
||||
* running the "Main" class from within STS (Right-click on Main class --> Run As --> Java Application)
|
||||
* or from the command line:
|
||||
- mvn package
|
||||
- mvn exec:java
|
||||
|
||||
You should see a screen as the following:
|
||||
|
||||
```
|
||||
=========================================================
|
||||
|
||||
Welcome to the Spring Integration Zip Sample
|
||||
|
||||
For more information please visit:
|
||||
https://www.springsource.org/spring-integration
|
||||
|
||||
=========================================================
|
||||
17:08:41.883 INFO [org.springframework.integration.samples.zip.Main.main()][org.springframework.integration.samples.zip.SpringIntegrationUtils]
|
||||
=========================================================
|
||||
|
||||
Intput directory is: '/dev/spring-integration-extensions/samples/zip/input-zip'
|
||||
Intput directory is: '/dev/spring-integration-extensions/samples/zip/input-uncompressed'
|
||||
Output directory is: 'target/output/decompressedFilesOut'
|
||||
Output directory is: 'target/output/zipFilesOut'
|
||||
|
||||
=========================================================
|
||||
17:08:41.887 INFO [org.springframework.integration.samples.zip.Main.main()][org.springframework.integration.samples.zip.Main]
|
||||
=========================================================
|
||||
|
||||
Please press 'q + Enter' to quit the application.
|
||||
|
||||
=========================================================
|
||||
```
|
||||
## Compressing Files
|
||||
|
||||
Drop an uncompressed file into the **input-uncompressed** directory. The file will be compressed and stored under **target/output/zipFilesOut**.
|
||||
|
||||
## Uncompressing Files
|
||||
|
||||
Drop a compressed file into the **input-zip** directory. The file will be decompressed and stored under **target/output/decompressedFilesOut**.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
For help please take a look at the Spring Integration documentation:
|
||||
|
||||
https://www.springsource.org/spring-integration
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>zip-sample</artifactId>
|
||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>zip-sample</name>
|
||||
<url>https://projects.spring.io/spring-integration/</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.integration.zip.version>2.0.0</spring.integration.zip.version>
|
||||
<log4j.version>2.17.2</log4j.version>
|
||||
<junit.version>4.13.2</junit.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo.spring.io.milestone</id>
|
||||
<name>Spring Framework Maven Milestone Repository</name>
|
||||
<url>https://repo.spring.io/libs-milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</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>3.0.0</version>
|
||||
<configuration>
|
||||
<mainClass>org.springframework.integration.samples.zip.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-zip</artifactId>
|
||||
<version>${spring.integration.zip.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-jcl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Other -->
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2020 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
|
||||
*
|
||||
* https://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.zip;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
|
||||
/**
|
||||
* Starts the Spring Context and will initialize the Spring Integration routes.
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public final class Main {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(Main.class);
|
||||
|
||||
private Main() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the Spring Integration Application Context
|
||||
*
|
||||
* @param args - command line arguments
|
||||
*/
|
||||
public static void main(final String... args) {
|
||||
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Welcome to the Spring Integration Zip Sample "
|
||||
+ "\n "
|
||||
+ "\n For more information please visit: "
|
||||
+ "\n https://www.springsource.org/spring-integration "
|
||||
+ "\n "
|
||||
+ "\n=========================================================");
|
||||
}
|
||||
|
||||
final AbstractApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");
|
||||
|
||||
context.registerShutdownHook();
|
||||
|
||||
SpringIntegrationUtils.displayDirectories(context);
|
||||
|
||||
final Scanner scanner = new Scanner(System.in);
|
||||
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Please press 'q + Enter' to quit the application. "
|
||||
+ "\n "
|
||||
+ "\n=========================================================");
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (scanner.hasNext("q")) {
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info("Exiting application...bye.");
|
||||
}
|
||||
scanner.close();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 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
|
||||
*
|
||||
* https://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.zip;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.FileWritingMessageHandler;
|
||||
|
||||
/**
|
||||
* Displays the names of the input and output directories.
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public final class SpringIntegrationUtils {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SpringIntegrationUtils.class);
|
||||
|
||||
private SpringIntegrationUtils() { }
|
||||
|
||||
/**
|
||||
* Helper Method to dynamically determine and display input and output
|
||||
* directories as defined in the Spring Integration context.
|
||||
*
|
||||
* @param context Spring Application Context
|
||||
*/
|
||||
public static void displayDirectories(final ApplicationContext context) {
|
||||
|
||||
Map<String, FileReadingMessageSource> fileReadingMessageSources = context.getBeansOfType(FileReadingMessageSource.class);
|
||||
|
||||
List<String> inputDirectories = new ArrayList<>();
|
||||
|
||||
for (FileReadingMessageSource source : fileReadingMessageSources.values()) {
|
||||
final File inDir = (File) new DirectFieldAccessor(source).getPropertyValue("directory");
|
||||
inputDirectories.add(inDir.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
Map<String, FileWritingMessageHandler> fileWritingMessageHandlers = context.getBeansOfType(FileWritingMessageHandler.class);
|
||||
|
||||
List<String> outputDirectories = new ArrayList<>();
|
||||
|
||||
for (final FileWritingMessageHandler messageHandler : fileWritingMessageHandlers.values()) {
|
||||
final Expression outDir = (Expression) new DirectFieldAccessor(messageHandler).getPropertyValue("destinationDirectoryExpression");
|
||||
outputDirectories.add(outDir.getExpressionString());
|
||||
}
|
||||
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
stringBuilder.append("\n=========================================================");
|
||||
stringBuilder.append("\n");
|
||||
|
||||
for (final String inputDirectory : inputDirectories) {
|
||||
stringBuilder.append("\n Input directory is: '" + inputDirectory + "'");
|
||||
}
|
||||
|
||||
for (final String outputDirectory : outputDirectories) {
|
||||
stringBuilder.append("\n Output directory is: '" + outputDirectory + "'");
|
||||
}
|
||||
|
||||
stringBuilder.append("\n\n=========================================================");
|
||||
|
||||
logger.info(stringBuilder.toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 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
|
||||
*
|
||||
* https://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.zip;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.integration.file.FileHeaders;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
* This Spring Integration transformation handler takes the input file, converts
|
||||
* the file into a string, converts the file contents into an upper-case string
|
||||
* and then sets a few Spring Integration message headers.
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @since 1.0
|
||||
*/
|
||||
public class TransformationHandler {
|
||||
|
||||
/**
|
||||
* Actual Spring Integration transformation handler.
|
||||
*
|
||||
* @param inputMessage Spring Integration input message
|
||||
* @return New Spring Integration message with updated headers
|
||||
*/
|
||||
@Transformer
|
||||
public Message<String> handleFile(final Message<File> inputMessage) {
|
||||
|
||||
final File inputFile = inputMessage.getPayload();
|
||||
final String filename = inputFile.getName();
|
||||
final String fileExtension = FilenameUtils.getExtension(filename);
|
||||
|
||||
final String inputAsString;
|
||||
|
||||
try {
|
||||
inputAsString = FileUtils.readFileToString(inputFile);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
return MessageBuilder.withPayload(inputAsString.toUpperCase(Locale.ENGLISH))
|
||||
.setHeader(FileHeaders.FILENAME, filename)
|
||||
.setHeader(FileHeaders.ORIGINAL_FILE, inputFile)
|
||||
.setHeader("file_size", inputFile.length())
|
||||
.setHeader("file_extension", fileExtension)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?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-file="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:int-zip="http://www.springframework.org/schema/integration/zip"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/file https://www.springframework.org/schema/integration/file/spring-integration-file.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/zip https://www.springframework.org/schema/integration/zip/spring-integration-zip.xsd">
|
||||
|
||||
<int-file:inbound-channel-adapter id="zipFilesIn"
|
||||
directory="file:input-zip">
|
||||
<int:poller id="poller" fixed-rate="5000" max-messages-per-poll="10" />
|
||||
</int-file:inbound-channel-adapter>
|
||||
|
||||
<int-file:inbound-channel-adapter id="uncompressedFilesIn" directory="file:input-uncompressed">
|
||||
<int:poller id="poller" fixed-rate="5000" max-messages-per-poll="10" />
|
||||
</int-file:inbound-channel-adapter>
|
||||
|
||||
<int-zip:zip-transformer id="zipFiles" input-channel="uncompressedFilesIn"
|
||||
output-channel="zipFilesOut" />
|
||||
|
||||
<int:chain id="unzipFiles" input-channel="zipFilesIn" output-channel="decompressedFilesOut">
|
||||
<int-zip:unzip-transformer result-type="BYTE_ARRAY"/>
|
||||
<int:splitter>
|
||||
<bean class="org.springframework.integration.zip.splitter.UnZipResultSplitter"/>
|
||||
</int:splitter>
|
||||
</int:chain>
|
||||
|
||||
<int-file:outbound-channel-adapter
|
||||
id="decompressedFilesOut" directory="file:target/output/decompressedFilesOut"
|
||||
delete-source-files="true" />
|
||||
|
||||
<int-file:outbound-channel-adapter
|
||||
id="zipFilesOut" directory="file:target/output/zipFilesOut"
|
||||
delete-source-files="true" />
|
||||
|
||||
</beans>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="STDOUT" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d %p [%t] [%c] - %m%n" />
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="org.springframework.integration" level="warn"/>
|
||||
<Logger name="org.springframework.integration.samples.zip" level="info"/>
|
||||
<Root level="warn">
|
||||
<AppenderRef ref="STDOUT" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 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
|
||||
*
|
||||
* https://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.zip;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import org.springframework.integration.samples.zip.SpringIntegrationUtils;
|
||||
|
||||
/**
|
||||
* Verify that the Spring Integration Application Context starts successfully.
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @since 1.0
|
||||
*
|
||||
*/
|
||||
public class SpringIntegrationProjectStartupTest {
|
||||
|
||||
@Test
|
||||
public void testStartupOfSpringIntegrationContext() throws Exception{
|
||||
final ApplicationContext context
|
||||
= new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
|
||||
SpringIntegrationProjectStartupTest.class);
|
||||
SpringIntegrationUtils.displayDirectories(context);
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user