Skip to content

Commit fb216dc

Browse files
committed
fix: S3OutboundChannelAdapterParser expression bean
1 parent 0d36be3 commit fb216dc

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.springframework.integration.aws.config.xml;
22

3+
import org.springframework.beans.factory.config.TypedStringValue;
34
import org.springframework.beans.factory.support.AbstractBeanDefinition;
5+
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
46
import org.springframework.beans.factory.xml.ParserContext;
5-
import org.springframework.expression.Expression;
67
import org.springframework.integration.aws.outbound.S3MessageHandler;
8+
import org.springframework.integration.config.ExpressionFactoryBean;
79
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
810
import org.w3c.dom.Element;
911

@@ -13,12 +15,19 @@ public class S3OutboundChannelAdapterParser extends AbstractOutboundChannelAdapt
1315
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
1416
return XmlBeanDefinitionBuilder.newInstance(element, parserContext, S3MessageHandler.class)
1517
.addExclusiveConstructorArgReference("s3", "transfer-manager")
16-
.addExclusiveConstructorArgValue("bucket", "bucket-expression", String.class, Expression.class)
18+
.addExclusiveConstructorArgValue("bucket", "bucket-expression", TypedStringValue::new, this::expression)
1719
.setPropertyValueIfAttributeDefined("key-expression")
1820
.setPropertyValueIfAttributeDefined("destination-bucket-expression")
1921
.setPropertyValueIfAttributeDefined("destination-key-expression")
2022
.setPropertyValueIfExclusiveAttributeDefined("command", "command-expression")
2123
.setPropertyReferenceIfAttributeDefined("upload-metadata-provider")
2224
.build();
2325
}
26+
27+
private AbstractBeanDefinition expression(String value) {
28+
return BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class)
29+
.addConstructorArgValue(value)
30+
.applyCustomizers(def -> def.setAutowireCandidate(false))
31+
.getBeanDefinition();
32+
}
2433
}

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import org.springframework.util.StringUtils;
88
import org.w3c.dom.Element;
99

10+
import java.util.function.BiConsumer;
1011
import java.util.function.Consumer;
12+
import java.util.function.Function;
1113

1214
import static org.springframework.core.Conventions.attributeNameToPropertyName;
1315
import static org.springframework.integration.config.xml.IntegrationNamespaceUtils.setReferenceIfAttributeDefined;
@@ -45,29 +47,28 @@ public XmlBeanDefinitionBuilder addConstructorArgReference(String attributeName)
4547
return this;
4648
}
4749

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-
5950
public XmlBeanDefinitionBuilder addConstructorArgValue(String attributeName) {
6051
builder.addConstructorArgValue(new TypedStringValue(element.getAttribute(attributeName)));
6152
return this;
6253
}
6354

64-
public XmlBeanDefinitionBuilder addExclusiveConstructorArgValue(String attribute1, String attribute2, Class<?> type1, Class<?> type2) {
55+
public XmlBeanDefinitionBuilder addExclusiveConstructorArgReference(String attribute1, String attribute2) {
56+
return addExclusiveConstructorArg(attribute1, attribute2, BeanDefinitionBuilder::addConstructorArgReference, BeanDefinitionBuilder::addConstructorArgReference);
57+
}
58+
59+
public XmlBeanDefinitionBuilder addExclusiveConstructorArgValue(String attribute1, String attribute2, Function<String, ?> arg1, Function<String, ?> arg2) {
60+
return addExclusiveConstructorArg(attribute1, attribute2, (b, v) -> b.addConstructorArgValue(arg1.apply(v)), (b, v) -> b.addConstructorArgValue(arg2.apply(v)));
61+
}
62+
63+
public XmlBeanDefinitionBuilder addExclusiveConstructorArg(String attribute1, String attribute2, BiConsumer<BeanDefinitionBuilder, String> arg1, BiConsumer<BeanDefinitionBuilder, String> arg2) {
6564
var value1 = element.getAttribute(attribute1);
6665
var value2 = element.getAttribute(attribute2);
6766
if (StringUtils.hasText(value1) == StringUtils.hasText(value2)) {
6867
error(attribute1 + " or " + attribute2 + " required and mutually exclusive");
68+
} else if (StringUtils.hasText(value1)) {
69+
arg1.accept(builder, value1);
6970
} else {
70-
builder.addConstructorArgValue(StringUtils.hasText(value1) ? new TypedStringValue(value1, type1) : new TypedStringValue(value2, type2));
71+
arg2.accept(builder, value2);
7172
}
7273
return this;
7374
}

0 commit comments

Comments
 (0)