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..cd59e66e5c 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 @@ -229,15 +229,14 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro @Override public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException { Object payload = this.requestMessage.getPayload(); + doWithMessageInternal(message, payload); if (message instanceof SoapMessage) { - this.doWithMessageInternal(message, payload); AbstractWebServiceOutboundGateway.this.headerMapper .fromHeadersToRequest(this.requestMessage.getHeaders(), (SoapMessage) message); - if (this.requestCallback != null) { - this.requestCallback.doWithMessage(message); - } } - + if (this.requestCallback != null) { + this.requestCallback.doWithMessage(message); + } } public abstract void doWithMessageInternal(WebServiceMessage message, Object payload) diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java index b33b1aceb6..20c8af9255 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java @@ -16,17 +16,23 @@ package org.springframework.integration.ws; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URI; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; import org.hamcrest.Matchers; import org.junit.Test; @@ -40,36 +46,47 @@ import org.springframework.integration.handler.ReplyRequiredException; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; +import org.springframework.util.concurrent.SettableListenableFuture; import org.springframework.ws.WebServiceMessage; import org.springframework.ws.WebServiceMessageFactory; +import org.springframework.ws.client.WebServiceClientException; import org.springframework.ws.client.core.WebServiceMessageCallback; import org.springframework.ws.client.support.destination.DestinationProvider; +import org.springframework.ws.client.support.interceptor.ClientInterceptorAdapter; +import org.springframework.ws.context.MessageContext; +import org.springframework.ws.pox.PoxMessage; +import org.springframework.ws.pox.dom.DomPoxMessageFactory; import org.springframework.ws.soap.SoapMessage; import org.springframework.ws.transport.WebServiceConnection; import org.springframework.ws.transport.WebServiceMessageSender; +import org.springframework.xml.transform.StringResult; /** * @author Mark Fisher * @author Artem Bilan * @author Gunnar Hillert + * * @since 2.0 */ public class SimpleWebServiceOutboundGatewayTests { private static final String response = "Test Name"; - public static final String responseSoapMessage = " " + - " " + - response + - " " + - ""; + public static final String responseSoapMessage = + " " + + " " + + response + + " " + + ""; - public static final String responseEmptyBodySoapMessage = "\n" + - "\n" + - "\n" + - ""; + public static final String responseEmptyBodySoapMessage = + "\n" + + "\n" + + "\n" + + ""; @Test // INT-1051 public void soapActionAndCustomCallback() { @@ -91,8 +108,9 @@ public class SimpleWebServiceOutboundGatewayTests { gateway.handleMessage(MessageBuilder.withPayload(request) .setHeader(WebServiceHeaders.SOAP_ACTION, soapActionHeaderValue) .build()); + fail("Expected MessageHandlingException"); } - catch (Exception e) { + catch (MessageHandlingException e) { // expected } assertNotNull(soapActionFromCallback.get()); @@ -121,6 +139,51 @@ public class SimpleWebServiceOutboundGatewayTests { gateway.handleMessage(new GenericMessage("foo")); } + @Test + public void testDomPoxMessageFactory() throws Exception { + String uri = "http://www.example.org"; + SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(uri); + gateway.setBeanFactory(mock(BeanFactory.class)); + + final SettableListenableFuture requestFuture = new SettableListenableFuture<>(); + + ClientInterceptorAdapter interceptorAdapter = new ClientInterceptorAdapter() { + + @Override + public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException { + requestFuture.set(messageContext.getRequest()); + return super.handleRequest(messageContext); + } + + }; + gateway.setInterceptors(interceptorAdapter); + gateway.setMessageFactory(new DomPoxMessageFactory()); + gateway.afterPropertiesSet(); + + String request = "foo"; + try { + gateway.handleMessage(new GenericMessage<>(request)); + fail("Expected MessageHandlingException"); + } + catch (MessageHandlingException e) { + // expected + } + + WebServiceMessage requestMessage = requestFuture.get(10, TimeUnit.SECONDS); + + assertNotNull(requestMessage); + assertThat(requestMessage, instanceOf(PoxMessage.class)); + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + + StringResult stringResult = new StringResult(); + transformer.transform(requestMessage.getPayloadSource(), stringResult); + + assertEquals(request, stringResult.toString()); + } + public static WebServiceMessageSender createMockMessageSender(final String mockResponseMessage) throws Exception { WebServiceMessageSender messageSender = Mockito.mock(WebServiceMessageSender.class); WebServiceConnection wsConnection = Mockito.mock(WebServiceConnection.class); @@ -151,6 +214,7 @@ public class SimpleWebServiceOutboundGatewayTests { public URI getDestination() { return this.uri; } + } } diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayWithHeaderMapperTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayWithHeaderMapperTests.java index 8814c687c8..30269569cf 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayWithHeaderMapperTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayWithHeaderMapperTests.java @@ -57,6 +57,7 @@ import org.springframework.util.xml.DomUtils; import org.springframework.ws.WebServiceMessage; import org.springframework.ws.WebServiceMessageFactory; import org.springframework.ws.client.core.WebServiceTemplate; +import org.springframework.ws.pox.dom.DomPoxMessageFactory; import org.springframework.ws.soap.SoapHeader; import org.springframework.ws.soap.SoapMessage; import org.springframework.ws.soap.SoapMessageFactory; @@ -193,7 +194,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests { if (!soap) { WebServiceTemplate template = TestUtils.getPropertyValue(gateway, "webServiceTemplate", WebServiceTemplate.class); - template.setMessageFactory(new StubMessageFactory()); + template.setMessageFactory(new DomPoxMessageFactory()); } WebServiceMessageSender messageSender = Mockito.mock(WebServiceMessageSender.class);