INT-1919 added support for treating '*' as literal value via 'pattern-match' boolean attribute on header-filter with default value 'true'

This commit is contained in:
Oleg Zhurakousky
2011-06-01 07:16:17 -04:00
parent bd896ab986
commit 6c7755b688
5 changed files with 82 additions and 1 deletions

View File

@@ -42,6 +42,8 @@ public class HeaderFilterParser extends AbstractTransformerParser {
parserContext.getReaderContext().error("The 'header-names' attribute must not be empty.",
parserContext.extractSource(element));
}
String pattern = element.getAttribute("pattern-match");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "pattern-match");
builder.addConstructorArgValue(headerNames);
}

View File

@@ -30,6 +30,8 @@ import org.springframework.util.Assert;
public class HeaderFilter implements Transformer {
private final String[] headersToRemove;
private volatile boolean patternMatch;
public HeaderFilter(String... headersToRemove) {
@@ -37,10 +39,20 @@ public class HeaderFilter implements Transformer {
this.headersToRemove = headersToRemove;
}
public void setPatternMatch(boolean patternMatch) {
this.patternMatch = patternMatch;
}
public Message<?> transform(Message<?> message) {
MessageBuilder<?> builder = MessageBuilder.fromMessage(message);
builder.removeHeaders(headersToRemove);
if (this.patternMatch){
builder.removeHeaders(headersToRemove);
}
else {
for (String headerToRemove : headersToRemove) {
builder.removeHeader(headerToRemove);
}
}
return builder.build();
}

View File

@@ -1669,6 +1669,17 @@ endpoint itself is a Polling Consumer for a channel with a queue.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="pattern-match" type="xsd:boolean" default="true">
<xsd:annotation>
<xsd:documentation>
Boolean flag that specifies whether values provided in 'header-names' should be treated as
match patterns or literal values. For example header-names='foo*' would mean remove all
headers that begin with 'foo' including the header named 'foo*'. However if you want to
treat '*' as literal value setting this flag to FALSE will not perform pattern match and
the only header that will be removed is that has an exact match
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="transformer">