Migrate Zip sample from SI-Extensions

* Migrate `cafe-scripted` to GraalVM Polyglot
* Fix emails for authors
* Upgrade some deps
This commit is contained in:
Artem Bilan
2024-10-03 16:33:51 -04:00
parent 8cbb6311f7
commit 580f19f025
75 changed files with 4354 additions and 741 deletions

58
basic/zip/README.md Normal file
View File

@@ -0,0 +1,58 @@
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 the IDE
* or from the command line using Maven in this sub-project:
- mvn package
- mvn exec:java
* or from the command line using Gradle from the root project:
- gradlew :zip:run
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.spring.io/spring-integration

157
basic/zip/pom.xml Normal file
View File

@@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.integration.samples</groupId>
<artifactId>zip</artifactId>
<version>6.4.0</version>
<url>https://github.com/spring-projects/spring-integration-samples</url>
<organization>
<name>Spring IO</name>
<url>https://spring.io/projects/spring-integration</url>
</organization>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>artembilan</id>
<name>Artem Bilan</name>
<email>artem.bilan@broadcom.com</email>
<roles>
<role>project lead</role>
</roles>
</developer>
<developer>
<id>garyrussell</id>
<name>Gary Russell</name>
<email>github@gprussell.net</email>
<roles>
<role>project lead emeritus</role>
</roles>
</developer>
<developer>
<id>markfisher</id>
<name>Mark Fisher</name>
<email>mark.ryan.fisher@gmail.com</email>
<roles>
<role>project founder and lead emeritus</role>
</roles>
</developer>
</developers>
<scm>
<connection>scm:git:scm:git:git://github.com/spring-projects/spring-integration-samples.git</connection>
<developerConnection>scm:git:scm:git:ssh://git@github.com:spring-projects/spring-integration-samples.git</developerConnection>
<url>https://github.com/spring-projects/spring-integration-samples</url>
</scm>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/spring-projects/spring-integration-samples/issues</url>
</issueManagement>
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-zip</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.23.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.1</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.18.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.2.0-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.4.0-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<java.version>17</java.version>
</properties>
<repositories>
<repository>
<id>repo.spring.io.milestone</id>
<name>Spring Framework Maven Milestone Repository</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>repo.spring.io.snapshot</id>
<name>Spring Framework Maven Snapshot Repository</name>
<url>https://repo.spring.io/snapshot</url>
</repository>
</repositories>
</project>

View File

@@ -0,0 +1,106 @@
/*
* 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 6.4
*
*/
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("""
=========================================================\
\
Welcome to the Spring Integration Zip Sample \
\
For more information please visit: \
https://www.springsource.org/spring-integration \
\
=========================================================""");
}
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("""
=========================================================\
\
Please press 'q + Enter' to quit the application. \
\
=========================================================""");
}
while (true) {
if (scanner.hasNext("q")) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Exiting application...bye.");
}
scanner.close();
System.exit(0);
}
}
}
}

View File

@@ -0,0 +1,92 @@
/*
* 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 6.4
*
*/
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());
}
}

View File

@@ -0,0 +1,39 @@
<?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>

View File

@@ -0,0 +1,17 @@
<?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.file" level="debug"/>
<Logger name="org.springframework.integration.zip" level="debug"/>
<Logger name="org.springframework.integration.samples.zip" level="info"/>
<Root level="warn">
<AppenderRef ref="STDOUT" />
</Root>
</Loggers>
</Configuration>

View File

@@ -0,0 +1,47 @@
/*
* 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.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
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
* @author Artem Bilan
*
* @since 6.4
*/
public class SpringIntegrationProjectStartupTest {
@Test
public void testStartupOfSpringIntegrationContext() throws Exception{
try(ConfigurableApplicationContext context
= new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml",
SpringIntegrationProjectStartupTest.class)) {
SpringIntegrationUtils.displayDirectories(context);
Thread.sleep(2000);
}
}
}