INT-1051 SoapAction callback now delegates to an additional request callback if provided, rather than being *replaced* by it.

This commit is contained in:
Mark Fisher
2010-05-07 21:49:38 +00:00
parent df1489ad08
commit 8c22f5c749
2 changed files with 97 additions and 5 deletions

View File

@@ -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);
}
}
}
}

View File

@@ -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<String> soapActionFromCallback = new AtomicReference<String>();
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 = "<test>foo</test>";
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;
}
}
}