From 9b26c725e34d5c418dade384f6440a498d682610 Mon Sep 17 00:00:00 2001 From: Jonas Partner Date: Fri, 3 Oct 2008 10:42:26 +0000 Subject: [PATCH] IN PROGRESS - issue INT-389: Allow configuration of a WebServiceMessageSender instance for WS handlers http://jira.springframework.org/browse/INT-389 added setter methods on AbstractWebServiceHandler and namespace support --- .../ws/config/WebServiceHandlerParser.java | 13 +++++++ .../ws/config/spring-integration-ws-1.0.xsd | 2 + .../ws/handler/AbstractWebServiceHandler.java | 9 +++++ .../ws/config/StubMessageSender.java | 39 +++++++++++++++++++ .../config/WebServiceHandlerParserTests.java | 26 +++++++++++++ .../simpleWebServiceHandlerParserTests.xml | 22 ++++++++++- 6 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubMessageSender.java diff --git a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceHandlerParser.java b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceHandlerParser.java index 380e022aec..ebf2740999 100644 --- a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceHandlerParser.java +++ b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/config/WebServiceHandlerParser.java @@ -91,6 +91,19 @@ public class WebServiceHandlerParser extends AbstractSingleBeanDefinitionParser if (StringUtils.hasText(faultMessageResolverRef)) { builder.addPropertyReference("faultMessageResolver", faultMessageResolverRef); } + + String messageSenderRef = element.getAttribute("message-sender"); + String messageSenderListRef = element.getAttribute("message-senders"); + if(StringUtils.hasText(messageSenderRef) && StringUtils.hasText(messageSenderListRef)){ + throw new ConfigurationException("Only one of message-sender or mesage-senders should be specified"); + } + + if (StringUtils.hasText(messageSenderRef)) { + builder.addPropertyReference("messageSender", messageSenderRef); + } + if (StringUtils.hasText(messageSenderListRef)) { + builder.addPropertyReference("messageSenders", messageSenderListRef); + } } } 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 7d046d8987..a835171d16 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 @@ -33,6 +33,8 @@ + + diff --git a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/handler/AbstractWebServiceHandler.java b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/handler/AbstractWebServiceHandler.java index ab9b758845..5ae9dd4917 100644 --- a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/handler/AbstractWebServiceHandler.java +++ b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/handler/AbstractWebServiceHandler.java @@ -30,6 +30,7 @@ import org.springframework.ws.client.core.WebServiceMessageCallback; import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.ws.soap.SoapMessage; import org.springframework.ws.soap.client.core.SoapActionCallback; +import org.springframework.ws.transport.WebServiceMessageSender; /** * Base class for outbound Web Service-invoking adapters. @@ -65,7 +66,15 @@ public abstract class AbstractWebServiceHandler extends AbstractMessageHandlingE public void setFaultMessageResolver(FaultMessageResolver faultMessageResolver) { this.webServiceTemplate.setFaultMessageResolver(faultMessageResolver); } + + public void setMessageSender(WebServiceMessageSender messageSender) { + this.webServiceTemplate.setMessageSender(messageSender); + } + public void setMessageSenders(WebServiceMessageSender[] messageSenders) { + this.webServiceTemplate.setMessageSenders(messageSenders); + } + protected WebServiceTemplate getWebServiceTemplate() { return this.webServiceTemplate; } diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubMessageSender.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubMessageSender.java new file mode 100644 index 0000000000..d6d90f0623 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubMessageSender.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2007 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 java.io.IOException; +import java.net.URI; + +import org.springframework.ws.transport.WebServiceConnection; +import org.springframework.ws.transport.WebServiceMessageSender; + +/** + * + * @author Jonas Partner + * + */ +public class StubMessageSender implements WebServiceMessageSender { + + public WebServiceConnection createConnection(URI uri) throws IOException { + return null; + } + + public boolean supports(URI uri) { + return false; + } + +} diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHandlerParserTests.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHandlerParserTests.java index 8cd13b7db0..66d30177e6 100644 --- a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHandlerParserTests.java +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/WebServiceHandlerParserTests.java @@ -32,6 +32,7 @@ import org.springframework.ws.WebServiceMessageFactory; import org.springframework.ws.client.core.FaultMessageResolver; import org.springframework.ws.client.core.SourceExtractor; import org.springframework.ws.client.core.WebServiceMessageCallback; +import org.springframework.ws.transport.WebServiceMessageSender; /** * @author Mark Fisher @@ -108,6 +109,31 @@ public class WebServiceHandlerParserTests { assertEquals(resolver, accessor.getPropertyValue("faultMessageResolver")); } + + @Test + public void testSimpleWebServiceHandlerWithCustomMessageSender() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "simpleWebServiceHandlerParserTests.xml", this.getClass()); + MessageEndpoint endpoint = (MessageEndpoint) context.getBean("handlerWithCustomMessageSender"); + assertEquals(SimpleWebServiceHandler.class, endpoint.getClass()); + DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint); + accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); + WebServiceMessageSender messageSender = (WebServiceMessageSender) context.getBean("messageSender"); + assertEquals(messageSender, ((WebServiceMessageSender[])accessor.getPropertyValue("messageSenders"))[0]); + } + @Test + public void testSimpleWebServiceHandlerWithCustomMessageSenderList() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "simpleWebServiceHandlerParserTests.xml", this.getClass()); + MessageEndpoint endpoint = (MessageEndpoint) context.getBean("handlerWithCustomMessageSenderList"); + assertEquals(SimpleWebServiceHandler.class, endpoint.getClass()); + DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint); + accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); + WebServiceMessageSender messageSender = (WebServiceMessageSender) context.getBean("messageSender"); + assertEquals(messageSender, ((WebServiceMessageSender[])accessor.getPropertyValue("messageSenders"))[0]); + assertEquals("Wrong number of message senders " ,2 , ((WebServiceMessageSender[])accessor.getPropertyValue("messageSenders")).length); + } + @Test public void testWebServiceHandlerWithAllInOneMarshaller() { ApplicationContext context = new ClassPathXmlApplicationContext( diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/simpleWebServiceHandlerParserTests.xml b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/simpleWebServiceHandlerParserTests.xml index d4624c0d08..91f96c8a11 100644 --- a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/simpleWebServiceHandlerParserTests.xml +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/simpleWebServiceHandlerParserTests.xml @@ -3,12 +3,15 @@ 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/integration/ws/spring-integration-ws-1.0.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util.xsd"> @@ -41,6 +44,16 @@ input-channel="inputChannel" uri="http://example.org" fault-message-resolver="faultMessageResolver"/> + + + + @@ -49,5 +62,12 @@ + + + + + + +