diff --git a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java index 50325e5300..776c3968e9 100644 --- a/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java +++ b/org.springframework.integration.ws/src/main/java/org/springframework/integration/ws/AbstractWebServiceOutboundGateway.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.springframework.integration.core.Message; import org.springframework.integration.core.MessageChannel; +import org.springframework.integration.core.MessagingException; import org.springframework.integration.handler.AbstractReplyProducingMessageHandler; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -115,18 +116,19 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro private WebServiceMessageCallback getRequestCallback(Message requestMessage) { - if (this.requestCallback != null) { - return this.requestCallback; - } String soapAction = requestMessage.getHeaders().get(WebServiceHeaders.SOAP_ACTION, String.class); - return (soapAction != null) ? new TypeCheckingSoapActionCallback(soapAction) : null; + return (soapAction != null) ? + new TypeCheckingSoapActionCallback(soapAction, this.requestCallback) : this.requestCallback; } private static class TypeCheckingSoapActionCallback extends SoapActionCallback { - TypeCheckingSoapActionCallback(String soapAction) { + private final WebServiceMessageCallback callbackDelegate; + + TypeCheckingSoapActionCallback(String soapAction, WebServiceMessageCallback callbackDelegate) { super(soapAction); + this.callbackDelegate = callbackDelegate; } @Override @@ -134,6 +136,14 @@ public abstract class AbstractWebServiceOutboundGateway extends AbstractReplyPro if (message instanceof SoapMessage) { super.doWithMessage(message); } + if (this.callbackDelegate != null) { + try { + this.callbackDelegate.doWithMessage(message); + } + catch (Exception e) { + throw new MessagingException("error occurred in WebServiceMessageCallback", e); + } + } } } diff --git a/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java new file mode 100644 index 0000000000..7440abd726 --- /dev/null +++ b/org.springframework.integration.ws/src/test/java/org/springframework/integration/ws/SimpleWebServiceOutboundGatewayTests.java @@ -0,0 +1,82 @@ +/* + * Copyright 2002-2010 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.net.URI; +import java.util.concurrent.atomic.AtomicReference; + +import javax.xml.transform.TransformerException; + +import org.junit.Test; + +import org.springframework.integration.message.MessageBuilder; +import org.springframework.ws.WebServiceMessage; +import org.springframework.ws.client.core.WebServiceMessageCallback; +import org.springframework.ws.client.support.destination.DestinationProvider; +import org.springframework.ws.soap.SoapMessage; + +/** + * @author Mark Fisher + * @since 2.0 + */ +public class SimpleWebServiceOutboundGatewayTests { + + @Test // INT-1051 + public void soapActionAndCustomCallback() { + String uri = "http://www.example.org"; + SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(new TestDestinationProvider(uri)); + final AtomicReference soapActionFromCallback = new AtomicReference(); + gateway.setRequestCallback(new WebServiceMessageCallback() { + public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException { + SoapMessage soapMessage = (SoapMessage) message; + soapActionFromCallback.set(soapMessage.getSoapAction()); + } + }); + gateway.afterPropertiesSet(); + String soapActionHeaderValue = "testAction"; + String request = "foo"; + try { + gateway.handleMessage(MessageBuilder.withPayload(request) + .setHeader(WebServiceHeaders.SOAP_ACTION, soapActionHeaderValue) + .build()); + } + catch (Exception e) { + // expected + } + assertNotNull(soapActionFromCallback.get()); + assertEquals("\"" + soapActionHeaderValue + "\"", soapActionFromCallback.get()); + } + + + private static class TestDestinationProvider implements DestinationProvider { + + private final URI uri; + + TestDestinationProvider(String uri) { + this.uri = URI.create(uri); + } + + public URI getDestination() { + return this.uri; + } + } + +}