diff --git a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParser.java b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParser.java new file mode 100644 index 0000000000..ac8f3eedc2 --- /dev/null +++ b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParser.java @@ -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); + } + } + } +} 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 be0724b1b8..e4bf219c29 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 @@ -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()); } } diff --git a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd index dff0eec843..a38b798348 100644 --- a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd +++ b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/spring-integration-ws-1.0.xsd @@ -115,4 +115,51 @@ + + + + + Defines a Web Service based inbound Messaging Gateway. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests-context.xml b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests-context.xml new file mode 100644 index 0000000000..20fd8b5249 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests-context.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java new file mode 100644 index 0000000000..60d58b52a2 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceInboundGatewayParserTests.java @@ -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)); + } +}