INT-1446 added 'header-mapper' attribute support for non-marshalling WS inbound gateway

This commit is contained in:
Mark Fisher
2010-10-18 09:20:17 -04:00
parent 01da99eff2
commit 2f9f92235c
4 changed files with 71 additions and 3 deletions

View File

@@ -13,16 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ws.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.integration.config.xml.AbstractInboundGatewayParser;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* @author Iwein Fuld
* @author Mark Fisher
*/
public class WebServiceInboundGatewayParser extends AbstractInboundGatewayParser {
@@ -48,6 +51,12 @@ public class WebServiceInboundGatewayParser extends AbstractInboundGatewayParser
builder.addConstructorArgReference(unmarshallerRef);
}
}
String headerMapperRef = element.getAttribute("header-mapper");
if (StringUtils.hasText(headerMapperRef)) {
Assert.isTrue(!StringUtils.hasText(marshallerRef),
"The 'header-mapper' attribute cannot be used when a 'marshaller' is provided.");
builder.addPropertyReference("headerMapper", headerMapperRef);
}
}
}

View File

@@ -248,6 +248,21 @@
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="extract-payload" type="xsd:boolean"/>
<xsd:attribute name="header-mapper">
<xsd:annotation>
<xsd:documentation>
Reference to a HeaderMapper&lt;SoapHeader&gt; implementation
that this gateway will use to map between Spring Integration
MessageHeaders and the SoapHeader. This strategy can only be
applied when a 'marshaller' is not being configured.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.mapping.HeaderMapper"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

View File

@@ -31,7 +31,17 @@
<si:queue/>
</si:channel>
<si:channel id="headerMappingRequests">
<si:queue/>
</si:channel>
<ws:inbound-gateway id="headerMappingGateway" request-channel="headerMappingRequests"
header-mapper="testHeaderMapper"/>
<bean id="marshaller" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.oxm.AbstractMarshaller" />
</bean>
<bean id="testHeaderMapper" class="org.springframework.integration.ws.config.WebServiceInboundGatewayParserTests$TestHeaderMapper"/>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.ws.config;
import static junit.framework.Assert.assertEquals;
@@ -23,6 +24,8 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import javax.xml.transform.Source;
@@ -30,13 +33,16 @@ import javax.xml.transform.Source;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessageHeaders;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.mapping.HeaderMapper;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.ws.MarshallingWebServiceInboundGateway;
import org.springframework.integration.ws.SimpleWebServiceInboundGateway;
@@ -46,12 +52,12 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ws.context.DefaultMessageContext;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.soap.SoapHeader;
/**
*
* @author Iwein Fuld
* @author Oleg Zhurakousky
*
* @author Mark Fisher
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -116,6 +122,7 @@ public class WebServiceInboundGatewayParserTests {
is(marshaller));
assertTrue("messaging gateway is not running", marshallingGateway.isRunning());
}
@Test
public void testMessageHistoryWithMarshallingGateway() throws Exception {
MessageContext context = new DefaultMessageContext(new StubMessageFactory());
@@ -130,6 +137,7 @@ public class WebServiceInboundGatewayParserTests {
assertNotNull(componentHistoryRecord);
assertEquals("ws:outbound-gateway", componentHistoryRecord.get("type"));
}
@Test
public void testMessageHistoryWithSimpleGateway() throws Exception {
MessageContext context = new DefaultMessageContext(new StubMessageFactory());
@@ -142,4 +150,30 @@ public class WebServiceInboundGatewayParserTests {
assertNotNull(componentHistoryRecord);
assertEquals("ws:outbound-gateway", componentHistoryRecord.get("type"));
}
@Autowired
private SimpleWebServiceInboundGateway headerMappingGateway;
@Autowired
private HeaderMapper<SoapHeader> testHeaderMapper;
@Test
public void testHeaderMapperReference() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(headerMappingGateway);
Object headerMapper = accessor.getPropertyValue("headerMapper");
assertEquals(testHeaderMapper, headerMapper);
}
@SuppressWarnings("unused")
private static class TestHeaderMapper implements HeaderMapper<SoapHeader> {
public void fromHeaders(MessageHeaders headers, SoapHeader target) {
}
public Map<String, ?> toHeaders(SoapHeader source) {
return Collections.emptyMap();
}
}
}