|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
37 | 37 | import javax.xml.soap.SOAPException;
|
38 | 38 | import javax.xml.soap.SOAPMessage;
|
39 | 39 | import javax.xml.transform.Source;
|
40 |
| -import javax.xml.transform.TransformerException; |
41 | 40 | import javax.xml.transform.dom.DOMSource;
|
42 | 41 |
|
43 | 42 | import org.junit.Test;
|
|
48 | 47 | import org.springframework.ws.soap.SoapHeaderElement;
|
49 | 48 | import org.springframework.ws.soap.SoapMessage;
|
50 | 49 | import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
| 50 | +import org.springframework.ws.transport.TransportConstants; |
51 | 51 | import org.springframework.xml.namespace.QNameUtils;
|
52 | 52 | import org.springframework.xml.transform.StringSource;
|
53 | 53 |
|
54 | 54 | /**
|
55 | 55 | * @author Gary Russell
|
56 | 56 | * @author Mauro Molinari
|
| 57 | + * @author Artem Bilan |
| 58 | + * |
57 | 59 | * @since 2.1
|
58 | 60 | *
|
59 | 61 | */
|
@@ -100,20 +102,20 @@ public void testCustomSoapHeader() {
|
100 | 102 | @Test
|
101 | 103 | public void testRealSoapHeader() throws Exception {
|
102 | 104 | 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>" |
106 | 108 | + "<username>user</username>"
|
107 | 109 | + "<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>"; |
117 | 119 | SOAPMessage message = MessageFactory.newInstance()
|
118 | 120 | .createMessage(new MimeHeaders(), new ByteArrayInputStream(soap.getBytes("UTF-8")));
|
119 | 121 | SoapMessage soapMessage = new SaajSoapMessage(message);
|
@@ -175,7 +177,7 @@ public void testExtractStandardHeadersNonEmptySoapAction() {
|
175 | 177 | }
|
176 | 178 |
|
177 | 179 | @Test
|
178 |
| - public void testFromHeadersToRequest() throws SOAPException, TransformerException { |
| 180 | + public void testFromHeadersToRequest() throws SOAPException { |
179 | 181 | DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
|
180 | 182 | mapper.setReplyHeaderNames("foo", "auth", "myHeader");
|
181 | 183 |
|
@@ -226,4 +228,28 @@ public void testFromHeadersToRequest() throws SOAPException, TransformerExceptio
|
226 | 228 | System. out. println(stringResult.toString());*/
|
227 | 229 | }
|
228 | 230 |
|
| 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 | + |
229 | 255 | }
|
0 commit comments