Skip to content

Commit 7dc0f5d

Browse files
artembilangaryrussell
authored andcommitted
INT-4409: Do not override soapAction to if empty
JIRA: https://jira.spring.io/browse/INT-4409 The `SoapMessage` may come as a `payload` and be already with the `soapAction` header. Right now it is overridden independently of the value from the headers. * Do not override `soapAction` in the `SoapMessage` if header doesn't have value
1 parent 00c983d commit 7dc0f5d

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

spring-integration-ws/src/main/java/org/springframework/integration/ws/DefaultSoapHeaderMapper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -114,10 +114,12 @@ protected Map<String, Object> extractUserDefinedHeaders(SoapMessage source) {
114114
@Override
115115
protected void populateStandardHeaders(Map<String, Object> headers, SoapMessage target) {
116116
String soapAction = getHeaderIfAvailable(headers, WebServiceHeaders.SOAP_ACTION, String.class);
117-
if (!StringUtils.hasText(soapAction)) {
118-
soapAction = "\"\"";
117+
if (StringUtils.hasText(soapAction)) {
118+
target.setSoapAction(soapAction);
119+
}
120+
else if (!StringUtils.hasText(target.getSoapAction())) {
121+
target.setSoapAction("\"\"");
119122
}
120-
target.setSoapAction(soapAction);
121123
}
122124

123125
@Override

spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,7 +37,6 @@
3737
import javax.xml.soap.SOAPException;
3838
import javax.xml.soap.SOAPMessage;
3939
import javax.xml.transform.Source;
40-
import javax.xml.transform.TransformerException;
4140
import javax.xml.transform.dom.DOMSource;
4241

4342
import org.junit.Test;
@@ -48,12 +47,15 @@
4847
import org.springframework.ws.soap.SoapHeaderElement;
4948
import org.springframework.ws.soap.SoapMessage;
5049
import org.springframework.ws.soap.saaj.SaajSoapMessage;
50+
import org.springframework.ws.transport.TransportConstants;
5151
import org.springframework.xml.namespace.QNameUtils;
5252
import org.springframework.xml.transform.StringSource;
5353

5454
/**
5555
* @author Gary Russell
5656
* @author Mauro Molinari
57+
* @author Artem Bilan
58+
*
5759
* @since 2.1
5860
*
5961
*/
@@ -100,20 +102,20 @@ public void testCustomSoapHeader() {
100102
@Test
101103
public void testRealSoapHeader() throws Exception {
102104
String soap =
103-
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
104-
+ "<soapenv:Header>"
105-
+ "<auth>"
105+
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
106+
+ "<soapenv:Header>"
107+
+ "<auth>"
106108
+ "<username>user</username>"
107109
+ "<password>pass</password>"
108-
+ "</auth>"
109-
+ "<bar>BAR</bar>"
110-
+ "<baz>BAZ</baz>"
111-
+ "<qux>qux</qux>"
112-
+ "</soapenv:Header>"
113-
+ "<soapenv:Body>"
114-
+ "<foo>foo</foo>"
115-
+ "</soapenv:Body>"
116-
+ "</soapenv:Envelope>";
110+
+ "</auth>"
111+
+ "<bar>BAR</bar>"
112+
+ "<baz>BAZ</baz>"
113+
+ "<qux>qux</qux>"
114+
+ "</soapenv:Header>"
115+
+ "<soapenv:Body>"
116+
+ "<foo>foo</foo>"
117+
+ "</soapenv:Body>"
118+
+ "</soapenv:Envelope>";
117119
SOAPMessage message = MessageFactory.newInstance()
118120
.createMessage(new MimeHeaders(), new ByteArrayInputStream(soap.getBytes("UTF-8")));
119121
SoapMessage soapMessage = new SaajSoapMessage(message);
@@ -175,7 +177,7 @@ public void testExtractStandardHeadersNonEmptySoapAction() {
175177
}
176178

177179
@Test
178-
public void testFromHeadersToRequest() throws SOAPException, TransformerException {
180+
public void testFromHeadersToRequest() throws SOAPException {
179181
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
180182
mapper.setReplyHeaderNames("foo", "auth", "myHeader");
181183

@@ -226,4 +228,28 @@ public void testFromHeadersToRequest() throws SOAPException, TransformerExceptio
226228
System. out. println(stringResult.toString());*/
227229
}
228230

231+
232+
@Test
233+
public void testDoNotOverriderSoapAction() throws Exception {
234+
MimeHeaders mimeHeaders = new MimeHeaders();
235+
236+
String testSoapAction = "fooAction";
237+
238+
mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION, testSoapAction);
239+
240+
String soap =
241+
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"></soapenv:Envelope>";
242+
243+
SOAPMessage message = MessageFactory.newInstance()
244+
.createMessage(mimeHeaders, new ByteArrayInputStream(soap.getBytes()));
245+
246+
SaajSoapMessage soapMessage = new SaajSoapMessage(message);
247+
248+
DefaultSoapHeaderMapper headerMapper = new DefaultSoapHeaderMapper();
249+
250+
headerMapper.fromHeadersToRequest(new MessageHeaders(null), soapMessage);
251+
252+
assertEquals(testSoapAction, soapMessage.getSoapAction());
253+
}
254+
229255
}

0 commit comments

Comments
 (0)