From f99183afca7b585fa99b63e435ee79d9ec36209c Mon Sep 17 00:00:00 2001 From: Mauro Molinari Date: Sun, 19 Jul 2015 22:05:39 +0200 Subject: [PATCH] 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 --- .../ws/DefaultSoapHeaderMapper.java | 11 +++++- .../ws/DefaultSoapHeaderMapperTests.java | 38 ++++++++++++++++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/spring-integration-ws/src/main/java/org/springframework/integration/ws/DefaultSoapHeaderMapper.java b/spring-integration-ws/src/main/java/org/springframework/integration/ws/DefaultSoapHeaderMapper.java index c7e3af944b..0534755f15 100644 --- a/spring-integration-ws/src/main/java/org/springframework/integration/ws/DefaultSoapHeaderMapper.java +++ b/spring-integration-ws/src/main/java/org/springframework/integration/ws/DefaultSoapHeaderMapper.java @@ -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 implements SoapHeaderMapper { @@ -61,7 +62,13 @@ public class DefaultSoapHeaderMapper extends AbstractHeaderMapper i @Override protected Map extractStandardHeaders(SoapMessage source) { - return Collections.emptyMap(); + final String soapAction = source.getSoapAction(); + if (StringUtils.hasText(soapAction)) { + Map headers = new HashMap(1); + headers.put(WebServiceHeaders.SOAP_ACTION, soapAction); + return headers; + } else + return Collections.emptyMap(); } @Override diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java index 330b70dd67..ae336b6a12 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java @@ -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 standardHeaders = mapper.toHeadersFromRequest(soapMessage); + + assertEquals(1, standardHeaders.size()); + assertTrue(standardHeaders.containsKey(WebServiceHeaders.SOAP_ACTION)); + assertEquals("foo", standardHeaders.get(WebServiceHeaders.SOAP_ACTION)); + } + }