diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java index fccba58315..1ee8279d82 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java @@ -60,8 +60,6 @@ import org.springframework.xml.transform.TransformerObjectSupport; */ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyProducingMessageHandler { - private final WebServiceTemplate webServiceTemplate; - private final String uri; private final DestinationProvider destinationProvider; @@ -72,12 +70,16 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro private volatile WebServiceMessageCallback requestCallback; + private WebServiceTemplate webServiceTemplate; + private volatile boolean ignoreEmptyResponses = true; private volatile boolean encodeUri = true; protected volatile SoapHeaderMapper headerMapper = new DefaultSoapHeaderMapper(); + private boolean webServiceTemplateExplicitlySet; + public AbstractWebServiceOutboundGateway(final String uri, WebServiceMessageFactory messageFactory) { Assert.hasText(uri, "URI must not be empty"); this.webServiceTemplate = new WebServiceTemplate(messageFactory); @@ -137,7 +139,15 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro this.ignoreEmptyResponses = ignoreEmptyResponses; } + public void setWebServiceTemplate(WebServiceTemplate webServiceTemplate) { + Assert.notNull(webServiceTemplate, "'webServiceTemplate' must not be null"); + this.webServiceTemplate = webServiceTemplate; + this.webServiceTemplateExplicitlySet = true; + } + public void setMessageFactory(WebServiceMessageFactory messageFactory) { + Assert.state(!this.webServiceTemplateExplicitlySet, + () -> "'messageFactory' must be specified on the provided: " + this.webServiceTemplate); this.webServiceTemplate.setMessageFactory(messageFactory); } @@ -146,18 +156,26 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro } public void setFaultMessageResolver(FaultMessageResolver faultMessageResolver) { + Assert.state(!this.webServiceTemplateExplicitlySet, + () -> "'faultMessageResolver' must be specified on the provided: " + this.webServiceTemplate); this.webServiceTemplate.setFaultMessageResolver(faultMessageResolver); } public void setMessageSender(WebServiceMessageSender messageSender) { + Assert.state(!this.webServiceTemplateExplicitlySet, + () -> "'messageSender' must be specified on the provided: " + this.webServiceTemplate); this.webServiceTemplate.setMessageSender(messageSender); } public void setMessageSenders(WebServiceMessageSender... messageSenders) { + Assert.state(!this.webServiceTemplateExplicitlySet, + () -> "'messageSenders' must be specified on the provided: " + this.webServiceTemplate); this.webServiceTemplate.setMessageSenders(messageSenders); } public void setInterceptors(ClientInterceptor... interceptors) { + Assert.state(!this.webServiceTemplateExplicitlySet, + () -> "'interceptors' must be specified on the provided: " + this.webServiceTemplate); this.webServiceTemplate.setInterceptors(interceptors); } diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParser.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParser.java index 119ef5091d..5069fd560e 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParser.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParser.java @@ -56,7 +56,7 @@ public class WebServiceOutboundGatewayParser extends AbstractOutboundGatewayPars String uri = element.getAttribute("uri"); String destinationProvider = element.getAttribute("destination-provider"); List uriVariableElements = DomUtils.getChildElementsByTagName(element, "uri-variable"); - if (!(StringUtils.hasText(destinationProvider) ^ StringUtils.hasText(uri))) { + if (StringUtils.hasText(destinationProvider) == StringUtils.hasText(uri)) { parserContext.getReaderContext().error( "Exactly one of 'uri' or 'destination-provider' is required.", element); } @@ -74,7 +74,8 @@ public class WebServiceOutboundGatewayParser extends AbstractOutboundGatewayPars for (Element uriVariableElement : uriVariableElements) { String name = uriVariableElement.getAttribute("name"); String expression = uriVariableElement.getAttribute("expression"); - BeanDefinitionBuilder factoryBeanBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class); + BeanDefinitionBuilder factoryBeanBuilder = + BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class); factoryBeanBuilder.addConstructorArgValue(expression); uriVariableExpressions.put(name, factoryBeanBuilder.getBeanDefinition()); } @@ -112,11 +113,21 @@ public class WebServiceOutboundGatewayParser extends AbstractOutboundGatewayPars builder.addConstructorArgValue(null); } } + + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-callback"); + + String webServiceTemplateRef = element.getAttribute("web-service-template"); + + if (StringUtils.hasText(webServiceTemplateRef)) { + builder.addPropertyReference("webServiceTemplate", webServiceTemplateRef); + return; + } + String messageFactoryRef = element.getAttribute("message-factory"); if (StringUtils.hasText(messageFactoryRef)) { builder.addConstructorArgReference(messageFactoryRef); } - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-callback"); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "fault-message-resolver"); String messageSenderRef = element.getAttribute("message-sender"); diff --git a/spring-integration-ws/src/main/resources/org/springframework/integration/ws/config/spring-integration-ws-5.0.xsd b/spring-integration-ws/src/main/resources/org/springframework/integration/ws/config/spring-integration-ws-5.0.xsd index a477023afc..21eafbddaf 100644 --- a/spring-integration-ws/src/main/resources/org/springframework/integration/ws/config/spring-integration-ws-5.0.xsd +++ b/spring-integration-ws/src/main/resources/org/springframework/integration/ws/config/spring-integration-ws-5.0.xsd @@ -100,6 +100,20 @@ + + + + Reference to a WebServiceTemplate instance. + The WebServiceTemplate-specific options like 'message-sender(s)', 'interceptor(s)', + 'fault-message-resolver' and 'message-factory' must be declared on that instance. + + + + + + + + + + diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java index 740dda9518..f7781c3039 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java @@ -19,6 +19,7 @@ package org.springframework.integration.ws.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -29,10 +30,13 @@ import static org.mockito.Mockito.verify; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.springframework.beans.DirectFieldAccessor; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; +import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.endpoint.AbstractEndpoint; @@ -50,6 +54,7 @@ import org.springframework.messaging.support.GenericMessage; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; import org.springframework.scheduling.support.PeriodicTrigger; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.ws.WebServiceMessageFactory; import org.springframework.ws.client.core.FaultMessageResolver; import org.springframework.ws.client.core.SourceExtractor; @@ -66,20 +71,22 @@ import org.springframework.ws.transport.WebServiceMessageSender; * @author Gary Russell * @author Artem Bilan */ +@RunWith(SpringRunner.class) public class WebServiceOutboundGatewayParserTests { private static volatile int adviceCalled; + @Autowired + private ApplicationContext context; + @Test public void simpleGatewayWithReplyChannel() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithReplyChannel"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithReplyChannel", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); - Object expected = context.getBean("outputChannel"); + Object expected = this.context.getBean("outputChannel"); assertEquals(expected, accessor.getPropertyValue("outputChannel")); Assert.assertEquals(Boolean.FALSE, accessor.getPropertyValue("requiresReply")); @@ -95,83 +102,69 @@ public class WebServiceOutboundGatewayParserTests { Long sendTimeout = TestUtils.getPropertyValue(gateway, "messagingTemplate.sendTimeout", Long.class); assertEquals(Long.valueOf(777), sendTimeout); - context.close(); + + assertSame(this.context.getBean("webServiceTemplate"), + TestUtils.getPropertyValue(gateway, "webServiceTemplate")); } @Test public void simpleGatewayWithIgnoreEmptyResponseTrueByDefault() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithReplyChannel"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithReplyChannel", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); assertEquals(Boolean.TRUE, accessor.getPropertyValue("ignoreEmptyResponses")); Assert.assertEquals(Boolean.FALSE, accessor.getPropertyValue("requiresReply")); - context.close(); } @Test public void simpleGatewayWithIgnoreEmptyResponses() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithIgnoreEmptyResponsesFalseAndRequiresReplyTrue"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithIgnoreEmptyResponsesFalseAndRequiresReplyTrue", + AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); assertEquals(Boolean.FALSE, accessor.getPropertyValue("ignoreEmptyResponses")); Assert.assertEquals(Boolean.TRUE, accessor.getPropertyValue("requiresReply")); - context.close(); } @Test public void simpleGatewayWithDefaultSourceExtractor() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithDefaultSourceExtractor"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithDefaultSourceExtractor", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); assertEquals("DefaultSourceExtractor", accessor.getPropertyValue("sourceExtractor").getClass().getSimpleName()); - context.close(); } @Test public void simpleGatewayWithCustomSourceExtractor() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomSourceExtractor"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomSourceExtractor", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); SourceExtractor sourceExtractor = (SourceExtractor) context.getBean("sourceExtractor"); assertEquals(sourceExtractor, accessor.getPropertyValue("sourceExtractor")); - context.close(); } @Test public void simpleGatewayWithCustomRequestCallback() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomRequestCallback"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomRequestCallback", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); WebServiceMessageCallback callback = (WebServiceMessageCallback) context.getBean("requestCallback"); assertEquals(callback, accessor.getPropertyValue("requestCallback")); - context.close(); } @Test public void simpleGatewayWithCustomMessageFactory() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomMessageFactory"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomMessageFactory", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); @@ -179,14 +172,11 @@ public class WebServiceOutboundGatewayParserTests { accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); WebServiceMessageFactory factory = (WebServiceMessageFactory) context.getBean("messageFactory"); assertEquals(factory, accessor.getPropertyValue("messageFactory")); - context.close(); } @Test public void simpleGatewayWithCustomSourceExtractorAndMessageFactory() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomSourceExtractorAndMessageFactory"); + AbstractEndpoint endpoint = context.getBean("gatewayWithCustomSourceExtractorAndMessageFactory", AbstractEndpoint.class); SourceExtractor sourceExtractor = (SourceExtractor) context.getBean("sourceExtractor"); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); @@ -196,14 +186,11 @@ public class WebServiceOutboundGatewayParserTests { accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); WebServiceMessageFactory factory = (WebServiceMessageFactory) context.getBean("messageFactory"); assertEquals(factory, accessor.getPropertyValue("messageFactory")); - context.close(); } @Test public void simpleGatewayWithCustomFaultMessageResolver() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomFaultMessageResolver"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomFaultMessageResolver", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); @@ -211,15 +198,12 @@ public class WebServiceOutboundGatewayParserTests { accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); FaultMessageResolver resolver = (FaultMessageResolver) context.getBean("faultMessageResolver"); assertEquals(resolver, accessor.getPropertyValue("faultMessageResolver")); - context.close(); } @Test public void simpleGatewayWithCustomMessageSender() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomMessageSender"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomMessageSender", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); @@ -227,13 +211,10 @@ public class WebServiceOutboundGatewayParserTests { accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); WebServiceMessageSender messageSender = (WebServiceMessageSender) context.getBean("messageSender"); assertEquals(messageSender, ((WebServiceMessageSender[]) accessor.getPropertyValue("messageSenders"))[0]); - context.close(); } @Test public void simpleGatewayWithCustomMessageSenderList() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomMessageSenderList"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomMessageSenderList", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); @@ -243,14 +224,11 @@ public class WebServiceOutboundGatewayParserTests { assertEquals(messageSender, ((WebServiceMessageSender[]) accessor.getPropertyValue("messageSenders"))[0]); assertEquals("Wrong number of message senders ", 2, ((WebServiceMessageSender[]) accessor.getPropertyValue("messageSenders")).length); - context.close(); } @Test public void simpleGatewayWithCustomInterceptor() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomInterceptor"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomInterceptor", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); @@ -258,14 +236,11 @@ public class WebServiceOutboundGatewayParserTests { accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate")); ClientInterceptor interceptor = context.getBean("interceptor", ClientInterceptor.class); assertEquals(interceptor, ((ClientInterceptor[]) accessor.getPropertyValue("interceptors"))[0]); - context.close(); } @Test public void simpleGatewayWithCustomInterceptorList() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomInterceptorList"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomInterceptorList", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass()); @@ -275,14 +250,11 @@ public class WebServiceOutboundGatewayParserTests { assertEquals(interceptor, ((ClientInterceptor[]) accessor.getPropertyValue("interceptors"))[0]); assertEquals("Wrong number of interceptors ", 2, ((ClientInterceptor[]) accessor.getPropertyValue("interceptors")).length); - context.close(); } @Test public void simpleGatewayWithPoller() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithPoller"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithPoller", AbstractEndpoint.class); assertEquals(PollingConsumer.class, endpoint.getClass()); Object triggerObject = new DirectFieldAccessor(endpoint).getPropertyValue("trigger"); assertEquals(PeriodicTrigger.class, triggerObject.getClass()); @@ -290,26 +262,19 @@ public class WebServiceOutboundGatewayParserTests { DirectFieldAccessor accessor = new DirectFieldAccessor(trigger); assertEquals("PeriodicTrigger had wrong period", 5000, ((Long) accessor.getPropertyValue("period")).longValue()); - context.close(); } @Test public void simpleGatewayWithOrder() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithOrderAndAutoStartupFalse"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithOrderAndAutoStartupFalse", AbstractEndpoint.class); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); assertEquals(99, new DirectFieldAccessor(gateway).getPropertyValue("order")); - context.close(); } @Test public void simpleGatewayWithStartupFalse() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithOrderAndAutoStartupFalse"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithOrderAndAutoStartupFalse", AbstractEndpoint.class); assertEquals(Boolean.FALSE, new DirectFieldAccessor(endpoint).getPropertyValue("autoStartup")); - context.close(); } @Test @@ -388,9 +353,7 @@ public class WebServiceOutboundGatewayParserTests { @Test public void simpleGatewayWithDestinationProvider() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithDestinationProvider"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithDestinationProvider", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler"); StubDestinationProvider stubProvider = (StubDestinationProvider) context.getBean("destinationProvider"); @@ -401,39 +364,30 @@ public class WebServiceOutboundGatewayParserTests { Object destinationProviderObject = new DirectFieldAccessor( accessor.getPropertyValue("webServiceTemplate")).getPropertyValue("destinationProvider"); assertEquals("Wrong DestinationProvider", stubProvider, destinationProviderObject); - context.close(); } @Test public void advised() { adviceCalled = 0; - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithAdvice"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithAdvice", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); MessageHandler handler = TestUtils.getPropertyValue(endpoint, "handler", MessageHandler.class); handler.handleMessage(new GenericMessage("foo")); assertEquals(1, adviceCalled); - context.close(); } @Test public void testInt2718AdvisedInsideAChain() { adviceCalled = 0; - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); MessageChannel channel = context.getBean("gatewayWithAdviceInsideAChain", MessageChannel.class); channel.send(new GenericMessage("foo")); assertEquals(1, adviceCalled); - context.close(); } @Test @SuppressWarnings("unchecked") public void jmsUri() { - ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( - "simpleWebServiceOutboundGatewayParserTests.xml", this.getClass()); - AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithJmsUri"); + AbstractEndpoint endpoint = this.context.getBean("gatewayWithJmsUri", AbstractEndpoint.class); assertEquals(EventDrivenConsumer.class, endpoint.getClass()); MessageHandler handler = TestUtils.getPropertyValue(endpoint, "handler", MessageHandler.class); assertNull(TestUtils.getPropertyValue(handler, "destinationProvider")); @@ -454,7 +408,6 @@ public class WebServiceOutboundGatewayParserTests { verify(webServiceTemplate).sendAndReceive(eq("jms:wsQueue"), any(WebServiceMessageCallback.class), ArgumentMatchers.>any()); - context.close(); } @Test(expected = BeanDefinitionParsingException.class) diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 8bd784b1e1..b9a33ec819 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -125,3 +125,9 @@ The STOMP module has been changed to use `ReactorNettyTcpStompClient`, based on The `Reactor2TcpStompSessionManager` has been renamed to the `ReactorNettyTcpStompSessionManager` according to the `ReactorNettyTcpStompClient` foundation. See <> for more information. + +==== Web Services Changes + +The `WebServiceOutboundGateway` s can now be supplied with an externally configured `WebServiceTemplate` instances. + +See <> for more information. diff --git a/src/reference/asciidoc/ws.adoc b/src/reference/asciidoc/ws.adoc index f856fae736..ebf184c6fc 100644 --- a/src/reference/asciidoc/ws.adoc +++ b/src/reference/asciidoc/ws.adoc @@ -21,7 +21,9 @@ Internally, the parser will configure a fixed URI `DestinationProvider` implemen If you do need dynamic resolution of the URI at runtime, however, then the `DestinationProvider` can provide such behavior as looking up the URI from a registry. See the Spring Web Services http://docs.spring.io/spring-ws/docs/current/api/org/springframework/ws/client/support/destination/DestinationProvider.html[DestinationProvider] JavaDoc for more information about this strategy. -For more detail on the inner workings, see the Spring Web Services reference guide's chapter covering http://docs.spring.io/spring-ws/docs/current/reference/html/client.html[client access] as well as the chapter covering http://static.springframework.org/spring-ws/site/reference/html/oxm.html[Object/XML mapping]. +Starting with _version 5.0_ the `SimpleWebServiceOutboundGateway` and `MarshallingWebServiceOutboundGateway` can be supplied with an external `WebServiceTemplate` instance, which may be configured for any custom properties, including `checkConnectionForFault` allowing your application to deal with non-conforming services. + +For more detail on the inner workings, see the Spring Web Services reference guide's chapter covering http://docs.spring.io/spring-ws/docs/current/reference/html/client.html[client access] as well as the chapter covering http://docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html[Object/XML mapping]. [[webservices-inbound]] === Inbound Web Service Gateways @@ -125,6 +127,8 @@ For either outbound gateway type, the "message-factory" attribute can also be co For the simple inbound gateway type, the "extract-payload" attribute can be set to false to forward the entire `WebServiceMessage` instead of just its payload as a `Message` to the request channel. This might be useful, for example, when a custom Transformer works against the `WebServiceMessage` directly. +Starting with _version 5.0_ the `web-service-template` reference attribute is presented for the injection of a `WebServiceTemplate` with any possible custom properties. + [[outbound-uri]] === Outbound URI Configuration