|
16 | 16 |
|
17 | 17 | package org.springframework.ws.soap; |
18 | 18 |
|
| 19 | +import java.io.ByteArrayOutputStream; |
| 20 | +import java.util.Map; |
| 21 | +import java.util.regex.Matcher; |
| 22 | +import java.util.regex.Pattern; |
| 23 | + |
| 24 | +import org.xml.sax.SAXParseException; |
| 25 | + |
19 | 26 | import org.springframework.core.io.Resource; |
20 | 27 | import org.springframework.util.StringUtils; |
21 | 28 | import org.springframework.ws.mime.AbstractMimeMessageTestCase; |
22 | 29 | import org.springframework.ws.mime.MimeMessage; |
| 30 | +import org.springframework.ws.transport.MockTransportOutputStream; |
| 31 | +import org.springframework.ws.transport.TransportConstants; |
23 | 32 | import org.springframework.xml.validation.XmlValidator; |
24 | 33 | import org.springframework.xml.validation.XmlValidatorFactory; |
25 | | -import org.xml.sax.SAXParseException; |
26 | 34 |
|
27 | 35 | public abstract class AbstractSoapMessageTestCase extends AbstractMimeMessageTestCase { |
28 | 36 |
|
@@ -50,6 +58,21 @@ public void testSoapAction() throws Exception { |
50 | 58 | assertEquals("Invalid SOAP Action", "\"SoapAction\"", soapMessage.getSoapAction()); |
51 | 59 | } |
52 | 60 |
|
| 61 | + public void testCharsetAttribute() throws Exception { |
| 62 | + MockTransportOutputStream outputStream = new MockTransportOutputStream(new ByteArrayOutputStream()); |
| 63 | + soapMessage.writeTo(outputStream); |
| 64 | + Map headers = outputStream.getHeaders(); |
| 65 | + String contentType = (String) headers.get(TransportConstants.HEADER_CONTENT_TYPE); |
| 66 | + if (contentType != null) { |
| 67 | + Pattern charsetPattern = Pattern.compile("charset\\s*=\\s*([^;]+)"); |
| 68 | + Matcher matcher = charsetPattern.matcher(contentType); |
| 69 | + if (matcher.find() && matcher.groupCount() == 1) { |
| 70 | + String charset = matcher.group(1).trim(); |
| 71 | + assertTrue("Invalid charset", charset.indexOf('"') < 0); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + |
53 | 76 | protected abstract Resource[] getSoapSchemas(); |
54 | 77 |
|
55 | 78 | public abstract void testGetVersion() throws Exception; |
|
0 commit comments