INT-879 Added header-enricher for setting the SOAP Action.

This commit is contained in:
Mark Fisher
2009-12-13 23:21:04 +00:00
parent cb519ac9db
commit f19eed355c
5 changed files with 162 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -223,4 +223,49 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="header-enricher">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines a Transformer for adding a SOAP Action value.
</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="transformerType">
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:element name="soap-action" type="headerType"/>
</xsd:choice>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="headerType">
<xsd:attribute name="value" type="xsd:string" />
<xsd:attribute name="ref" type="xsd:string" />
<xsd:attribute name="expression" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="transformerType">
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="input-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="output-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:schema>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/ws"
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/ws
http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd">
<header-enricher input-channel="literalValueInput">
<soap-action value="http://test"/>
</header-enricher>
<header-enricher input-channel="expressionInput">
<soap-action expression="'http://' + payload"/>
</header-enricher>
</beans:beans>

View File

@@ -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<String, Object> 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<String, Object> headers = result.getHeaders();
assertEquals("http://foo", headers.get(WebServiceHeaders.SOAP_ACTION));
}
}