INT-2466: Propagate SOAP action from inbound

JIRA: https://jira.spring.io/browse/INT-2466

Current reference documentation says that: "If the incoming web service
message is a SOAP message the SOAP Action header will be added to the
headers of the Message that is forwarded onto the request channel."
However, `DefaultSoapHeaderMapper` was actually missing to do that.

Polishing
This commit is contained in:
Mauro Molinari
2015-07-19 22:05:39 +02:00
committed by Artem Bilan
parent a8f47ee343
commit f99183afca
2 changed files with 45 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -45,6 +45,7 @@ import org.springframework.xml.namespace.QNameUtils;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Stephane Nicoll
* @author Mauro Molinari
* @since 2.0
*/
public class DefaultSoapHeaderMapper extends AbstractHeaderMapper<SoapMessage> implements SoapHeaderMapper {
@@ -61,7 +62,13 @@ public class DefaultSoapHeaderMapper extends AbstractHeaderMapper<SoapMessage> i
@Override
protected Map<String, Object> extractStandardHeaders(SoapMessage source) {
return Collections.emptyMap();
final String soapAction = source.getSoapAction();
if (StringUtils.hasText(soapAction)) {
Map<String, Object> headers = new HashMap<String, Object>(1);
headers.put(WebServiceHeaders.SOAP_ACTION, soapAction);
return headers;
} else
return Collections.emptyMap();
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2015 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.
@@ -13,10 +13,12 @@
* 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.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -32,6 +34,7 @@ import org.springframework.ws.soap.SoapMessage;
/**
* @author Gary Russell
* @author Mauro Molinari
* @since 2.1
*
*/
@@ -48,7 +51,7 @@ public class DefaultSoapHeaderMapperTests {
@Test
public void testCustomSoapHeader() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
mapper.setReplyHeaderNames(new String[] {"x:attr", "x:elem"});
mapper.setReplyHeaderNames("x:attr", "x:elem");
SoapMessage soapMessage = mock(SoapMessage.class);
SoapHeader soapHeader = mock(SoapHeader.class);
@SuppressWarnings("unchecked")
@@ -75,4 +78,35 @@ public class DefaultSoapHeaderMapperTests {
assertSame(soapHeaderElement, headers.get("x:elem"));
}
@Test
public void testExtractStandardHeadersNullSoapAction() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
SoapMessage soapMessage = mock(SoapMessage.class);
when(soapMessage.getSoapAction()).thenReturn(null);
assertTrue(mapper.extractStandardHeaders(soapMessage).isEmpty());
}
@Test
public void testExtractStandardHeadersEmptySoapAction() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
SoapMessage soapMessage = mock(SoapMessage.class);
when(soapMessage.getSoapAction()).thenReturn("");
assertTrue(mapper.extractStandardHeaders(soapMessage).isEmpty());
}
@Test
public void testExtractStandardHeadersNonEmptySoapAction() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
SoapMessage soapMessage = mock(SoapMessage.class);
when(soapMessage.getSoapAction()).thenReturn("foo");
Map<String, Object> standardHeaders = mapper.toHeadersFromRequest(soapMessage);
assertEquals(1, standardHeaders.size());
assertTrue(standardHeaders.containsKey(WebServiceHeaders.SOAP_ACTION));
assertEquals("foo", standardHeaders.get(WebServiceHeaders.SOAP_ACTION));
}
}