diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/HeaderFilterParser.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/HeaderFilterParser.java new file mode 100644 index 0000000000..d8398a48d7 --- /dev/null +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/HeaderFilterParser.java @@ -0,0 +1,48 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.config.xml; + +import org.w3c.dom.Element; + +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.util.StringUtils; + +/** + * Parser for the 'header-filter' element. + * + * @author Mark Fisher + * @since 2.0 + */ +public class HeaderFilterParser extends AbstractTransformerParser { + + @Override + protected final String getTransformerClassName() { + return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.HeaderFilter"; + } + + @Override + protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + String headerNames = element.getAttribute("header-names"); + if (!StringUtils.hasText(headerNames)) { + parserContext.getReaderContext().error("The 'header-names' attribute must not be empty.", + parserContext.extractSource(element)); + } + builder.addConstructorArgValue(headerNames); + } + +} diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java index c55008e769..20474c3acc 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceHandler.java @@ -40,6 +40,7 @@ public class IntegrationNamespaceHandler extends AbstractIntegrationNamespaceHan registerBeanDefinitionParser("aggregator", new AggregatorParser()); registerBeanDefinitionParser("resequencer", new ResequencerParser()); registerBeanDefinitionParser("header-enricher", new StandardHeaderEnricherParser()); + registerBeanDefinitionParser("header-filter", new HeaderFilterParser()); registerBeanDefinitionParser("object-to-string-transformer", new ObjectToStringTransformerParser()); registerBeanDefinitionParser("payload-serializing-transformer", new PayloadSerializingTransformerParser()); registerBeanDefinitionParser("payload-deserializing-transformer", new PayloadDeserializingTransformerParser()); diff --git a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd index d3b42a24f7..1c06a3696e 100644 --- a/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd +++ b/org.springframework.integration/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd @@ -1013,6 +1013,7 @@ minOccurs="0" maxOccurs="unbounded" /> + @@ -1405,6 +1406,28 @@ + + + + Defines a HeaderFilter endpoint to remove values defined in the MessageHeaders. + + + + + + + + + Specify one or more header names (as a comma separated list) to + be removed from the MessageHeaders of the Message being handled. + + + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderFilterParserTests-context.xml b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderFilterParserTests-context.xml new file mode 100644 index 0000000000..1c3b26f6e1 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderFilterParserTests-context.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderFilterParserTests.java b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderFilterParserTests.java new file mode 100644 index 0000000000..ce486799a2 --- /dev/null +++ b/org.springframework.integration/src/test/java/org/springframework/integration/config/xml/HeaderFilterParserTests.java @@ -0,0 +1,67 @@ +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.config.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.core.Message; +import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.message.MessageBuilder; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + * @since 2.0 + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class HeaderFilterParserTests { + + @Autowired + private MessageChannel input; + + @Test + public void verifyHeadersRemoved() { + QueueChannel replyChannel = new QueueChannel(); + Message message = MessageBuilder.withPayload("test") + .setReplyChannel(replyChannel) + .setHeader("a", 1) + .setHeader("b", 2) + .setHeader("c", 3) + .setHeader("d", 4) + .setHeader("e", 5) + .build(); + input.send(message); + Message result = replyChannel.receive(0); + assertNotNull(result); + assertEquals("test", result.getPayload()); + assertNull(result.getHeaders().get("a")); + assertNull(result.getHeaders().get("c")); + assertNull(result.getHeaders().get("d")); + assertNotNull(result.getHeaders().get("b")); + assertNotNull(result.getHeaders().get("e")); + } + +}