From b3719ff09694e6fe7a2bee64ddd00dd0d076526c Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 8 Jul 2008 01:03:06 +0000 Subject: [PATCH] Added namespace support for "message-factory" and "fault-message-resolver" (INT-291). --- .../ws/config/WebServiceHandlerParser.java | 8 ++++ .../ws/config/spring-integration-ws-1.0.xsd | 2 + .../ws/config/StubFaultMessageResolver.java | 32 ++++++++++++++++ .../ws/config/StubMessageFactory.java | 38 +++++++++++++++++++ .../config/WebServiceHandlerParserTests.java | 26 +++++++++++++ .../simpleWebServiceHandlerParserTests.xml | 12 ++++++ .../template.mf | 2 +- 7 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubFaultMessageResolver.java create mode 100644 org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubMessageFactory.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 7ff0aeed12..2206145b21 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 @@ -74,6 +74,14 @@ public class WebServiceHandlerParser extends AbstractSingleBeanDefinitionParser if (StringUtils.hasText(requestCallbackRef)) { builder.addPropertyReference("requestCallback", requestCallbackRef); } + String messageFactoryRef = element.getAttribute("message-factory"); + if (StringUtils.hasText(messageFactoryRef)) { + builder.addPropertyReference("messageFactory", messageFactoryRef); + } + String faultMessageResolverRef = element.getAttribute("fault-message-resolver"); + if (StringUtils.hasText(faultMessageResolverRef)) { + builder.addPropertyReference("faultMessageResolver", faultMessageResolverRef); + } } } 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 a2113a1041..78bf3ad71f 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 @@ -32,6 +32,8 @@ + + diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubFaultMessageResolver.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubFaultMessageResolver.java new file mode 100644 index 0000000000..3a6b665f8f --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubFaultMessageResolver.java @@ -0,0 +1,32 @@ +/* + * Copyright 2002-2008 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 org.springframework.ws.WebServiceMessage; +import org.springframework.ws.client.core.FaultMessageResolver; + +/** + * @author Mark Fisher + */ +public class StubFaultMessageResolver implements FaultMessageResolver { + + public void resolveFault(WebServiceMessage message) throws IOException { + } + +} diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubMessageFactory.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubMessageFactory.java new file mode 100644 index 0000000000..5ee23499e7 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/config/StubMessageFactory.java @@ -0,0 +1,38 @@ +/* + * Copyright 2002-2008 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.io.InputStream; + +import org.springframework.ws.WebServiceMessage; +import org.springframework.ws.WebServiceMessageFactory; + +/** + * @author Mark Fisher + */ +public class StubMessageFactory implements WebServiceMessageFactory { + + public WebServiceMessage createWebServiceMessage() { + return null; + } + + public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException { + return null; + } + +} 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 afc03b69c7..0cfe337b2d 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 @@ -28,6 +28,8 @@ import org.springframework.integration.ws.handler.MarshallingWebServiceHandler; import org.springframework.integration.ws.handler.SimpleWebServiceHandler; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; +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; @@ -68,6 +70,30 @@ public class WebServiceHandlerParserTests { assertEquals(callback, accessor.getPropertyValue("requestCallback")); } + @Test + public void testSimpleWebServiceHandlerWithCustomMessageFactory() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "simpleWebServiceHandlerParserTests.xml", this.getClass()); + MessageHandler handler = (MessageHandler) context.getBean("handlerWithCustomMessageFactory"); + assertEquals(SimpleWebServiceHandler.class, handler.getClass()); + DirectFieldAccessor accessor = new DirectFieldAccessor(handler); + accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); + WebServiceMessageFactory factory = (WebServiceMessageFactory) context.getBean("messageFactory"); + assertEquals(factory, accessor.getPropertyValue("messageFactory")); + } + + @Test + public void testSimpleWebServiceHandlerWithCustomFaultMessageResolver() { + ApplicationContext context = new ClassPathXmlApplicationContext( + "simpleWebServiceHandlerParserTests.xml", this.getClass()); + MessageHandler handler = (MessageHandler) context.getBean("handlerWithCustomFaultMessageResolver"); + assertEquals(SimpleWebServiceHandler.class, handler.getClass()); + DirectFieldAccessor accessor = new DirectFieldAccessor(handler); + accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); + FaultMessageResolver resolver = (FaultMessageResolver) context.getBean("faultMessageResolver"); + assertEquals(resolver, accessor.getPropertyValue("faultMessageResolver")); + } + @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 1513252654..03afa13389 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 @@ -18,8 +18,20 @@ uri="http://example.org" request-callback="requestCallback"/> + + + + + + + + diff --git a/org.springframework.integration.ws/template.mf b/org.springframework.integration.ws/template.mf index e5ff6fca4b..85adedceb1 100644 --- a/org.springframework.integration.ws/template.mf +++ b/org.springframework.integration.ws/template.mf @@ -5,7 +5,7 @@ Bundle-ManifestVersion: 2 Import-Template: org.springframework.integration.*;version="[1.0.0, 1.0.1)", org.springframework.beans.factory.*;version="[2.5.4.A, 3.0.0)", - org.springframework.oxm;version="[1.5.1.A, 2.0.0)";resolution:=optional, + org.springframework.oxm;version="[1.5.1.A, 2.0.0)", org.springframework.util;version="[2.5.4.A, 3.0.0)", org.springframework.ws.*;version="[1.5.1.A, 2.0.0)", org.springframework.xml.transform;version="[1.5.1.A, 2.0.0)"