From f19eed355c86141ccbe4f455cdcb64ab2edc5467 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sun, 13 Dec 2009 23:21:04 +0000 Subject: [PATCH] INT-879 Added header-enricher for setting the SOAP Action. --- .../WebServiceHeaderEnricherParser.java | 32 +++++++++ .../ws/config/WsNamespaceHandler.java | 1 + .../ws/config/spring-integration-ws-2.0.xsd | 45 +++++++++++++ .../WebServiceHeaderEnricherTests-context.xml | 18 +++++ .../config/WebServiceHeaderEnricherTests.java | 66 +++++++++++++++++++ 5 files changed, 162 insertions(+) create mode 100644 org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherParser.java create mode 100644 org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests-context.xml create mode 100644 org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests.java diff --git a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherParser.java b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherParser.java new file mode 100644 index 0000000000..04c67825cd --- /dev/null +++ b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherParser.java @@ -0,0 +1,32 @@ +/* + * Copyright 2002-2009 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.ws.config; + +import org.springframework.integration.config.xml.HeaderEnricherParserSupport; +import org.springframework.integration.ws.WebServiceHeaders; + +/** + * @author Mark Fisher + * @since 2.0 + */ +public class WebServiceHeaderEnricherParser extends HeaderEnricherParserSupport { + + public WebServiceHeaderEnricherParser() { + this.addElementToHeaderMapping("soap-action", WebServiceHeaders.SOAP_ACTION); + } + +} diff --git a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WsNamespaceHandler.java b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WsNamespaceHandler.java index 2d2b2cc0a0..76fd6b7533 100644 --- a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WsNamespaceHandler.java +++ b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WsNamespaceHandler.java @@ -27,6 +27,7 @@ public class WsNamespaceHandler extends AbstractIntegrationNamespaceHandler { public void init() { this.registerBeanDefinitionParser("outbound-gateway", new WebServiceOutboundGatewayParser()); this.registerBeanDefinitionParser("inbound-gateway", new WebServiceInboundGatewayParser()); + this.registerBeanDefinitionParser("header-enricher", new WebServiceHeaderEnricherParser()); } } diff --git a/org.springframework.integration.ws/src/main/resources/org/springframework/integration/ws/config/spring-integration-ws-2.0.xsd b/org.springframework.integration.ws/src/main/resources/org/springframework/integration/ws/config/spring-integration-ws-2.0.xsd index dd0d67e93a..0e4cf06350 100644 --- a/org.springframework.integration.ws/src/main/resources/org/springframework/integration/ws/config/spring-integration-ws-2.0.xsd +++ b/org.springframework.integration.ws/src/main/resources/org/springframework/integration/ws/config/spring-integration-ws-2.0.xsd @@ -223,4 +223,49 @@ + + + + + Defines a Transformer for adding a SOAP Action value. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests-context.xml b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests-context.xml new file mode 100644 index 0000000000..2e30d44bc9 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests-context.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests.java new file mode 100644 index 0000000000..7e15f3fe04 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHeaderEnricherTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2002-2009 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.ws.config; + +import static org.junit.Assert.assertEquals; + +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.integration.channel.MessageChannelTemplate; +import org.springframework.integration.core.Message; +import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.message.StringMessage; +import org.springframework.integration.ws.WebServiceHeaders; +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 WebServiceHeaderEnricherTests { + + @Autowired @Qualifier("literalValueInput") + private MessageChannel literalValueInput; + + @Autowired @Qualifier("expressionInput") + private MessageChannel expressionInput; + + @Test + public void literalValue() { + MessageChannelTemplate template = new MessageChannelTemplate(literalValueInput); + Message result = template.sendAndReceive(new StringMessage("foo")); + Map headers = result.getHeaders(); + assertEquals("http://test", headers.get(WebServiceHeaders.SOAP_ACTION)); + } + + @Test + public void expression() { + MessageChannelTemplate template = new MessageChannelTemplate(expressionInput); + Message result = template.sendAndReceive(new StringMessage("foo")); + Map headers = result.getHeaders(); + assertEquals("http://foo", headers.get(WebServiceHeaders.SOAP_ACTION)); + } + +}