Skip to content

Commit a598971

Browse files
committed
feat: SnsOutboundChannelAdapterParser to parse sns-outbound-channel-adapter element
1 parent 35f1457 commit a598971

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.integration.aws.outbound.SnsMessageHandler;
6+
import org.springframework.integration.config.xml.AbstractOutboundChannelAdapterParser;
7+
import org.w3c.dom.Element;
8+
9+
public class SnsOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser {
10+
11+
@Override
12+
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
13+
return XmlBeanDefinitionBuilder.newInstance(element, parserContext, SnsMessageHandler.class)
14+
.unsupportedAttributeWarning("failure-channel", "resource-id-resolver", "error-message-strategy", "async-handler")
15+
.addConstructorArgReference("sns")
16+
.setExpressionPropertyIfAttributeDefined("topic-arn")
17+
.setExpressionPropertyIfAttributeDefined("subject")
18+
.setExpressionPropertyIfAttributeDefined("message-group-id")
19+
.setExpressionPropertyIfAttributeDefined("message-deduplication-id")
20+
.setExpressionPropertyIfAttributeDefined("body")
21+
.setExpressionValueIfAttributeDefined("send-timeout")
22+
.setPropertyValueIfAttributeDefined("outputChannelName", "success-channel")
23+
.build();
24+
}
25+
}

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

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,11 @@ public XmlBeanDefinitionBuilder addConstructorArgValue(String attributeName) {
5353
}
5454

5555
public XmlBeanDefinitionBuilder addExclusiveConstructorArgReference(String attribute1, String attribute2) {
56-
return addExclusiveConstructorArg(attribute1, attribute2, BeanDefinitionBuilder::addConstructorArgReference, BeanDefinitionBuilder::addConstructorArgReference);
56+
return setExclusiveAttribute(attribute1, attribute2, BeanDefinitionBuilder::addConstructorArgReference, BeanDefinitionBuilder::addConstructorArgReference);
5757
}
5858

5959
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) {
64-
var value1 = element.getAttribute(attribute1);
65-
var value2 = element.getAttribute(attribute2);
66-
if (StringUtils.hasText(value1) == StringUtils.hasText(value2)) {
67-
error(attribute1 + " or " + attribute2 + " required and mutually exclusive");
68-
} else if (StringUtils.hasText(value1)) {
69-
arg1.accept(builder, value1);
70-
} else {
71-
arg2.accept(builder, value2);
72-
}
73-
return this;
60+
return setExclusiveAttribute(attribute1, attribute2, (b, v) -> b.addConstructorArgValue(arg1.apply(v)), (b, v) -> b.addConstructorArgValue(arg2.apply(v)));
7461
}
7562

7663
public XmlBeanDefinitionBuilder setPropertyReference(String attributeName) {
@@ -121,6 +108,18 @@ public XmlBeanDefinitionBuilder setPropertyValueIfAttributeDefined(String proper
121108
return this;
122109
}
123110

111+
public XmlBeanDefinitionBuilder setExpressionPropertyIfAttributeDefined(String attribute) {
112+
return setExpressionPropertyIfAttributeDefined(attribute, attribute + "-expression");
113+
}
114+
115+
public XmlBeanDefinitionBuilder setExpressionPropertyIfAttributeDefined(String attribute, String expressionAttribute) {
116+
return setExpressionPropertyIfAttributeDefined(attribute, expressionAttribute, attributeNameToPropertyName(attribute), attributeNameToPropertyName(expressionAttribute));
117+
}
118+
119+
public XmlBeanDefinitionBuilder setExpressionPropertyIfAttributeDefined(String attribute, String expressionAttribute, String property, String expressionProperty) {
120+
return setIfExclusiveAttributeDefined(attribute, expressionAttribute, (b, v) -> b.addPropertyValue(property, v), (b, v) -> b.addPropertyValue(expressionProperty, new ExpressionBeanDefinitionFactory().createBeanDefinition(v)));
121+
}
122+
124123
public XmlBeanDefinitionBuilder setExpressionValueIfAttributeDefined(String attribute) {
125124
return setPropertyValueIfExclusiveAttributeDefined(attribute, attribute + "-expression", attributeNameToPropertyName(attribute), attributeNameToPropertyName(attribute + "-expression-string"));
126125
}
@@ -130,11 +129,31 @@ public XmlBeanDefinitionBuilder setPropertyValueIfExclusiveAttributeDefined(Stri
130129
}
131130

132131
public XmlBeanDefinitionBuilder setPropertyValueIfExclusiveAttributeDefined(String attribute1, String attribute2, String property1, String property2) {
133-
if (StringUtils.hasText(element.getAttribute(attribute1)) && StringUtils.hasText(element.getAttribute(attribute2))) {
132+
return setIfExclusiveAttributeDefined(attribute1, attribute2, (b, v) -> b.addPropertyValue(property1, v), (b, v) -> b.addPropertyValue(property2, v));
133+
}
134+
135+
public XmlBeanDefinitionBuilder setExclusiveAttribute(String attribute1, String attribute2, BiConsumer<BeanDefinitionBuilder, String> arg1, BiConsumer<BeanDefinitionBuilder, String> arg2) {
136+
var value1 = element.getAttribute(attribute1);
137+
var value2 = element.getAttribute(attribute2);
138+
if (StringUtils.hasText(value1) == StringUtils.hasText(value2)) {
139+
error(attribute1 + " or " + attribute2 + " required and mutually exclusive");
140+
} else if (StringUtils.hasText(value1)) {
141+
arg1.accept(builder, value1);
142+
} else {
143+
arg2.accept(builder, value2);
144+
}
145+
return this;
146+
}
147+
148+
public XmlBeanDefinitionBuilder setIfExclusiveAttributeDefined(String attribute1, String attribute2, BiConsumer<BeanDefinitionBuilder, String> arg1, BiConsumer<BeanDefinitionBuilder, String> arg2) {
149+
var value1 = element.getAttribute(attribute1);
150+
var value2 = element.getAttribute(attribute2);
151+
if (StringUtils.hasText(value1) && StringUtils.hasText(value2)) {
134152
error(attribute1 + " and " + attribute2 + " attributes are mutually exclusive");
153+
} if (StringUtils.hasText(value1)) {
154+
arg1.accept(builder, value1);
135155
} else {
136-
setValueIfAttributeDefined(builder, element, attribute1, property1);
137-
setValueIfAttributeDefined(builder, element, attribute2, property2);
156+
arg2.accept(builder, value2);
138157
}
139158
return this;
140159
}

int-aws-support/src/main/resources/org/springframework/integration/aws/config/xml/element-parser.mapping

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ s3-outbound-channel-adapter: org.springframework.integration.aws.config.xml.S3Ou
44
s3-outbound-gateway: org.springframework.integration.aws.config.xml.S3OutboundGatewayParser
55
sqs-outbound-channel-adapter: org.springframework.integration.aws.config.xml.SqsOutboundChannelAdapterParser
66
sqs-message-driven-channel-adapter: org.springframework.integration.aws.config.xml.SqsMessageDrivenChannelAdapterParser
7-
sns-inbound-channel-adapter: org.springframework.integration.aws.config.xml.SnsInboundChannelAdapterParser
7+
sns-inbound-channel-adapter: org.springframework.integration.aws.config.xml.SnsInboundChannelAdapterParser
8+
sns-outbound-channel-adapter: org.springframework.integration.aws.config.xml.SnsOutboundChannelAdapterParser

0 commit comments

Comments
 (0)