Skip to content

Commit 71dcedf

Browse files
committed
feat: S3OutboundChannelAdapterParser for s3-outbound-channel-adapter
1 parent e1c543c commit 71dcedf

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.springframework.integration.aws.config.xml;
2+
3+
import org.springframework.beans.factory.support.AbstractBeanDefinition;
4+
import org.springframework.beans.factory.xml.ParserContext;
5+
import org.springframework.expression.Expression;
6+
import org.springframework.integration.aws.outbound.S3MessageHandler;
7+
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
8+
import org.w3c.dom.Element;
9+
10+
public class S3OutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser {
11+
12+
@Override
13+
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
14+
return XmlBeanDefinitionBuilder.newInstance(element, parserContext, S3MessageHandler.class)
15+
.addExclusiveConstructorArgReference("s3", "transfer-manager")
16+
.addExclusiveConstructorArgValue("bucket", "bucket-expression", String.class, Expression.class)
17+
.setPropertyValueIfAttributeDefined("key-expression")
18+
.setPropertyValueIfAttributeDefined("destination-bucket-expression")
19+
.setPropertyValueIfAttributeDefined("destination-key-expression")
20+
.setPropertyValueIfExclusiveAttributeDefined("command", "command-expression")
21+
.setPropertyReferenceIfAttributeDefined("upload-metadata-provider")
22+
.build();
23+
}
24+
}

int-aws-support/src/main/java/org/springframework/integration/aws/config/xml/XmlBeanDefinitionBuilder.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,33 @@ public XmlBeanDefinitionBuilder addConstructorArgReference(String attributeName)
4545
return this;
4646
}
4747

48+
public XmlBeanDefinitionBuilder addExclusiveConstructorArgReference(String attribute1, String attribute2) {
49+
var value1 = element.getAttribute(attribute1);
50+
var value2 = element.getAttribute(attribute2);
51+
if (StringUtils.hasText(value1) == StringUtils.hasText(value2)) {
52+
error(attribute1 + " or " + attribute2 + " required and mutually exclusive");
53+
} else {
54+
builder.addConstructorArgReference(StringUtils.hasText(value1) ? value1 : value2);
55+
}
56+
return this;
57+
}
58+
4859
public XmlBeanDefinitionBuilder addConstructorArgValue(String attributeName) {
4960
builder.addConstructorArgValue(new TypedStringValue(element.getAttribute(attributeName)));
5061
return this;
5162
}
5263

64+
public XmlBeanDefinitionBuilder addExclusiveConstructorArgValue(String attribute1, String attribute2, Class<?> type1, Class<?> type2) {
65+
var value1 = element.getAttribute(attribute1);
66+
var value2 = element.getAttribute(attribute2);
67+
if (StringUtils.hasText(value1) == StringUtils.hasText(value2)) {
68+
error(attribute1 + " or " + attribute2 + " required and mutually exclusive");
69+
} else {
70+
builder.addConstructorArgValue(StringUtils.hasText(value1) ? new TypedStringValue(value1, type1) : new TypedStringValue(value2, type2));
71+
}
72+
return this;
73+
}
74+
5375
public XmlBeanDefinitionBuilder setPropertyReference(String attributeName) {
5476
builder.addPropertyReference(attributeNameToPropertyName(attributeName), element.getAttribute(attributeName));
5577
return this;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
s3-inbound-channel-adapter: org.springframework.integration.aws.config.xml.S3InboundChannelAdapterParser
22
s3-inbound-streaming-channel-adapter: org.springframework.integration.aws.config.xml.S3InboundStreamingChannelAdapterParser
3+
s3-outbound-channel-adapter: org.springframework.integration.aws.config.xml.S3OutboundChannelAdapterParser
34
sqs-outbound-channel-adapter: org.springframework.integration.aws.config.xml.SqsOutboundChannelAdapterParser
45
sqs-message-driven-channel-adapter: org.springframework.integration.aws.config.xml.SqsMessageDrivenChannelAdapterParser

0 commit comments

Comments
 (0)