Skip to content

Commit 210a2f9

Browse files
committed
Migrate Zip Extension as a core module
1 parent 39c73d4 commit 210a2f9

Some content is hidden

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

48 files changed

+2821
-5
lines changed

build.gradle

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,34 @@ ext {
8787
lettuceVersion = '6.2.3.RELEASE'
8888
log4jVersion = '2.19.0'
8989
mailVersion = '1.0.0'
90-
micrometerPropagationVersion = '1.0.1-SNAPSHOT'
91-
micrometerTracingVersion = '1.0.2-SNAPSHOT'
90+
micrometerPropagationVersion = '1.0.2'
91+
micrometerTracingVersion = '1.0.2'
9292
micrometerVersion = '1.11.0-SNAPSHOT'
9393
mockitoVersion = '5.1.1'
9494
mongoDriverVersion = '4.8.2'
9595
mysqlVersion = '8.0.32'
9696
pahoMqttClientVersion = '1.2.5'
9797
postgresVersion = '42.5.2'
9898
r2dbch2Version = '1.0.0.RELEASE'
99-
reactorVersion = '2022.0.3-SNAPSHOT'
99+
reactorVersion = '2022.0.3'
100100
resilience4jVersion = '2.0.2'
101101
romeToolsVersion = '1.18.0'
102102
rsocketVersion = '1.1.3'
103103
servletApiVersion = '6.0.0'
104104
smackVersion = '4.4.6'
105105
springAmqpVersion = '3.0.2-SNAPSHOT'
106106
springDataVersion = '2023.0.0-SNAPSHOT'
107-
springGraphqlVersion = '1.2.0-SNAPSHOT'
107+
springGraphqlVersion = '1.1.2-SNAPSHOT'
108108
springKafkaVersion = '3.0.3-SNAPSHOT'
109109
springRetryVersion = '2.0.0'
110110
springSecurityVersion = '6.1.0-SNAPSHOT'
111-
springVersion = '6.0.5-SNAPSHOT'
111+
springVersion = '6.0.5'
112112
springWsVersion = '4.0.1'
113113
testcontainersVersion = '1.17.6'
114114
tomcatVersion = '11.0.0-M1'
115115
xmlUnitVersion = '2.9.1'
116116
xstreamVersion = '1.4.20'
117+
ztZipVersion = '1.15'
117118

118119
javaProjects = subprojects - project(':spring-integration-bom')
119120
}
@@ -1094,6 +1095,15 @@ project('spring-integration-zeromq') {
10941095
}
10951096
}
10961097

1098+
project('spring-integration-zip') {
1099+
description = 'Spring Integration Zip Support'
1100+
dependencies {
1101+
api project(':spring-integration-file')
1102+
api "org.zeroturnaround:zt-zip:$ztZipVersion"
1103+
}
1104+
}
1105+
1106+
10971107
project('spring-integration-zookeeper') {
10981108
description = 'Spring Integration Zookeeper Support'
10991109
dependencies {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2015-2023 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+
* https://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.zip;
18+
19+
/**
20+
* Zip adapter specific message headers.
21+
*
22+
* @author Gunnar Hillert
23+
*
24+
* @since 6.1
25+
*/
26+
public abstract class ZipHeaders {
27+
28+
public static final String PREFIX = "zip_";
29+
30+
public static final String ZIP_ENTRY_FILE_NAME = PREFIX + "entryFilename";
31+
32+
public static final String ZIP_ENTRY_PATH = PREFIX + "entryPath";
33+
34+
public static final String ZIP_ENTRY_LAST_MODIFIED_DATE = PREFIX + "entryLastModifiedDate";
35+
36+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2015-2023 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+
* https://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.zip.config.xml;
18+
19+
import org.w3c.dom.Element;
20+
21+
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
22+
import org.springframework.beans.factory.xml.ParserContext;
23+
import org.springframework.integration.config.xml.AbstractTransformerParser;
24+
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
25+
import org.springframework.util.StringUtils;
26+
27+
/**
28+
* Base class for Zip transformer parsers.
29+
*
30+
* @author Gunnar Hillert
31+
* @author Artem Bilan
32+
*
33+
* @since 6.1
34+
*/
35+
public abstract class AbstractZipTransformerParser extends AbstractTransformerParser {
36+
37+
/**
38+
* @param element The XML Element to process
39+
* @param parserContext The Spring ParserContext
40+
* @param builder BeanDefinitionBuilder for constructing Bean Definitions
41+
*/
42+
@Override
43+
protected final void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
44+
String deleteFiles = element.getAttribute("delete-files");
45+
if (StringUtils.hasText(deleteFiles)) {
46+
builder.addPropertyValue("deleteFiles", deleteFiles);
47+
}
48+
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset");
49+
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-type", "zipResultType");
50+
postProcessTransformer(element, parserContext, builder);
51+
}
52+
53+
/**
54+
* Subclasses may override this method to provide additional configuration.
55+
*
56+
* @param element The XML Element to process
57+
* @param parserContext The Spring ParserContext
58+
* @param builder BeanDefinitionBuilder for constructing Bean Definitions
59+
*/
60+
protected void postProcessTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
61+
}
62+
63+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2015-2023 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+
* https://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.zip.config.xml;
18+
19+
import org.w3c.dom.Element;
20+
21+
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
22+
import org.springframework.beans.factory.xml.ParserContext;
23+
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
24+
import org.springframework.integration.zip.transformer.UnZipTransformer;
25+
26+
/**
27+
* Parser for the 'unzip-transformer' element.
28+
*
29+
* @author Gunnar Hillert
30+
* @author Artem Bilan
31+
*
32+
* @since 6.1
33+
*/
34+
public class UnZipTransformerParser extends AbstractZipTransformerParser {
35+
36+
@Override
37+
protected String getTransformerClassName() {
38+
return UnZipTransformer.class.getName();
39+
}
40+
41+
@Override
42+
protected void postProcessTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
43+
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "expect-single-result");
44+
}
45+
46+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2015-2023 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+
* https://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.zip.config.xml;
18+
19+
import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler;
20+
21+
/**
22+
* The namespace handler for the Zip namespace
23+
*
24+
* @author Gunnar Hillert
25+
*
26+
* @since 6.1
27+
*
28+
*/
29+
public class ZipNamespaceHandler extends AbstractIntegrationNamespaceHandler {
30+
31+
@Override
32+
public void init() {
33+
this.registerBeanDefinitionParser("zip-transformer", new ZipTransformerParser());
34+
this.registerBeanDefinitionParser("unzip-transformer", new UnZipTransformerParser());
35+
}
36+
37+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2015-2023 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+
* https://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.zip.config.xml;
18+
19+
import org.w3c.dom.Element;
20+
21+
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
22+
import org.springframework.beans.factory.xml.ParserContext;
23+
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
24+
import org.springframework.integration.zip.transformer.ZipTransformer;
25+
26+
/**
27+
* Parser for the 'zip-transformer' element.
28+
*
29+
* @author Gunnar Hillert
30+
* @author Artem Bilan
31+
*
32+
* @since 6.1
33+
*/
34+
public class ZipTransformerParser extends AbstractZipTransformerParser {
35+
36+
@Override
37+
protected String getTransformerClassName() {
38+
return ZipTransformer.class.getName();
39+
}
40+
41+
@Override
42+
protected void postProcessTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
43+
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "compression-level");
44+
}
45+
46+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Provides parser classes to provide Xml namespace support for the Zip components.
3+
*/
4+
package org.springframework.integration.zip.config.xml;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Root package of the Zip Module.
3+
*/
4+
package org.springframework.integration.zip;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2015-2023 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+
* https://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.zip.splitter;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
import org.apache.commons.io.FilenameUtils;
24+
25+
import org.springframework.integration.file.FileHeaders;
26+
import org.springframework.integration.splitter.AbstractMessageSplitter;
27+
import org.springframework.integration.support.MessageBuilder;
28+
import org.springframework.integration.zip.ZipHeaders;
29+
import org.springframework.messaging.Message;
30+
import org.springframework.messaging.MessageHeaders;
31+
import org.springframework.util.Assert;
32+
33+
/**
34+
*
35+
* @author Gunnar Hillert
36+
* @author Andriy Kryvtsun
37+
* @author Artem Bilan
38+
*
39+
* @since 6.1
40+
*/
41+
public class UnZipResultSplitter extends AbstractMessageSplitter {
42+
43+
@Override
44+
@SuppressWarnings("unchecked")
45+
protected Object splitMessage(Message<?> message) {
46+
Assert.state(message.getPayload() instanceof Map,
47+
"The UnZipResultSplitter supports only Map<String, Object> payload");
48+
Map<String, Object> unzippedEntries = (Map<String, Object>) message.getPayload();
49+
MessageHeaders headers = message.getHeaders();
50+
51+
List<MessageBuilder<Object>> messageBuilders = new ArrayList<>(unzippedEntries.size());
52+
53+
for (Map.Entry<String, Object> entry : unzippedEntries.entrySet()) {
54+
String path = FilenameUtils.getPath(entry.getKey());
55+
String filename = FilenameUtils.getName(entry.getKey());
56+
MessageBuilder<Object> messageBuilder = MessageBuilder.withPayload(entry.getValue())
57+
.setHeader(FileHeaders.FILENAME, filename)
58+
.setHeader(ZipHeaders.ZIP_ENTRY_PATH, path)
59+
.copyHeadersIfAbsent(headers);
60+
messageBuilders.add(messageBuilder);
61+
}
62+
63+
return messageBuilders;
64+
}
65+
66+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Classes to support Splitter pattern for Zip.
3+
*/
4+
package org.springframework.integration.zip.splitter;

0 commit comments

Comments
 (0)