INT-1134 added namespace support for the <header-filter/> element
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
@@ -1013,6 +1013,7 @@
|
||||
minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element ref="service-activator" />
|
||||
<xsd:element ref="header-enricher" />
|
||||
<xsd:element ref="header-filter" />
|
||||
<xsd:element ref="transformer" />
|
||||
<xsd:element ref="payload-serializing-transformer" />
|
||||
<xsd:element ref="payload-deserializing-transformer" />
|
||||
@@ -1405,6 +1406,28 @@
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="header-filter">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a HeaderFilter endpoint to remove values defined in the MessageHeaders.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="inputOutputEndpointType">
|
||||
<xsd:attribute name="header-names" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Specify one or more header names (as a comma separated list) to
|
||||
be removed from the MessageHeaders of the Message being handled.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="transformer"
|
||||
type="expressionOrInnerEndpointDefinitionAware">
|
||||
<xsd:annotation>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<header-filter input-channel="input" header-names="a,d, c"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user