OPEN - issue INT-597: Add namespace support for inbound WS gateway

http://jira.springframework.org/browse/INT-597

Modified xsd, added namespace handler and testcase.
This commit is contained in:
Iwein Fuld
2009-03-12 13:43:47 +00:00
parent 3c9ddafdcd
commit 34a977a3a0
5 changed files with 212 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
/*
* 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.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.integration.adapter.config.AbstractRemotingGatewayParser;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
/**
*
* @author Iwein Fuld
*
*/
public class WebServiceInboundGatewayParser extends AbstractRemotingGatewayParser {
@Override
protected String getBeanClassName(Element element) {
String simpleClassName = (StringUtils.hasText(element.getAttribute("marshaller"))) ?
"MarshallingWebServiceInboundGateway" : "SimpleWebServiceInboundGateway";
return "org.springframework.integration.ws." + simpleClassName;
}
@Override
protected void doPostProcess(BeanDefinitionBuilder builder, Element element) {
String marshallerRef = element.getAttribute("marshaller");
if (StringUtils.hasText(marshallerRef)) {
builder.addPropertyReference("marshaller",marshallerRef);
String unmarshallerRef = element.getAttribute("unmarshaller");
if (StringUtils.hasText(unmarshallerRef)) {
builder.addPropertyReference("unmarshaller",unmarshallerRef);
}
}
}
}

View File

@@ -20,11 +20,13 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
/**
* @author Mark Fisher
* @author Iwein Fuld
*/
public class WsNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
this.registerBeanDefinitionParser("outbound-gateway", new WebServiceOutboundGatewayParser());
this.registerBeanDefinitionParser("inbound-gateway", new WebServiceInboundGatewayParser());
}
}

View File

@@ -115,4 +115,51 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="inbound-gateway">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines a Web Service based inbound Messaging Gateway.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="request-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="reply-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="marshaller" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.oxm.Marshaller"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="unmarshaller" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.oxm.Unmarshaller"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="extract-payload" type="xsd:boolean"/>
</xsd:complexType>
</xsd:element>
</xsd:schema>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:si="http://www.springframework.org/schema/integration"
xmlns:ws="http://www.springframework.org/schema/integration/ws"
xmlns:util='http://www.springframework.org/schema/util'
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration/ws
http://www.springframework.org/schema/integration/ws/spring-integration-ws-1.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<ws:inbound-gateway id="simple" request-channel="requests" />
<ws:inbound-gateway id="extractsPayload" request-channel="requests" extract-payload="false"/>
<ws:inbound-gateway id="marshalling" request-channel="requests"
marshaller="marshaller" unmarshaller="marshaller" />
<si:channel id="requests" />
<bean id="marshaller" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.springframework.oxm.AbstractMarshaller" />
</bean>
</beans>

View File

@@ -0,0 +1,87 @@
/*
* 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.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.ws.MarshallingWebServiceInboundGateway;
import org.springframework.integration.ws.SimpleWebServiceInboundGateway;
import org.springframework.oxm.AbstractMarshaller;
import org.springframework.oxm.Marshaller;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class WebServiceInboundGatewayParserTests {
@Autowired
@Qualifier("requests")
MessageChannel requestChannel;
@Test
public void configOk() throws Exception {
// config valid
}
//Simple
@Autowired
@Qualifier("simple")
SimpleWebServiceInboundGateway simpleGateway;
@Test
public void simpleGatewayProperties() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(simpleGateway);
assertThat(
(MessageChannel) accessor.getPropertyValue("requestChannel"),
is(requestChannel));
}
//extractPayload = false
@Autowired
@Qualifier("extractsPayload")
SimpleWebServiceInboundGateway payloadExtractingGateway;
@Test
public void extractPayloadSet() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(
payloadExtractingGateway);
assertThat((Boolean) accessor.getPropertyValue("extractPayload"),
is(false));
}
//marshalling
@Autowired
MarshallingWebServiceInboundGateway marshallingGateway;
@Autowired
AbstractMarshaller marshaller;
@Test
public void marshallersSet() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(marshallingGateway);
assertThat((AbstractMarshaller) accessor.getPropertyValue("marshaller"),
is(marshaller));
assertThat((AbstractMarshaller) accessor.getPropertyValue("unmarshaller"),
is(marshaller));
}
}