| 1 |
package test.encoding; |
| 2 |
|
| 3 |
import junit.framework.TestCase; |
| 4 |
import org.apache.axis.MessageContext; |
| 5 |
import org.apache.axis.encoding.DeserializationContext; |
| 6 |
import org.apache.axis.message.RPCElement; |
| 7 |
import org.apache.axis.message.RPCParam; |
| 8 |
import org.apache.axis.server.AxisServer; |
| 9 |
import org.xml.sax.InputSource; |
| 10 |
|
| 11 |
import javax.xml.soap.SOAPMessage; |
| 12 |
import javax.xml.soap.MessageFactory; |
| 13 |
import java.io.ByteArrayOutputStream; |
| 14 |
import java.io.ByteArrayInputStream; |
| 15 |
|
| 16 |
/** |
| 17 |
* line feed normalization and character reference processing |
| 18 |
*/ |
| 19 |
public class TestString3 extends TestCase { |
| 20 |
|
| 21 |
public static final String myNS = "urn:myNS"; |
| 22 |
|
| 23 |
public TestString3(String name) { |
| 24 |
super(name); |
| 25 |
} |
| 26 |
|
| 27 |
static String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + |
| 28 |
"<soapenv:Body>" + |
| 29 |
"<ns1:method1 xmlns:ns1=\"urn:myNamespace\">" + |
| 30 |
"<ns1:testParam xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">"; |
| 31 |
|
| 32 |
static String xml2 = |
| 33 |
"</ns1:testParam>" + |
| 34 |
"</ns1:method1>" + |
| 35 |
"</soapenv:Body>" + |
| 36 |
"</soapenv:Envelope>"; |
| 37 |
|
| 38 |
private void runtest(String value, String expected) throws Exception { |
| 39 |
MessageContext msgContext = new MessageContext(new AxisServer()); |
| 40 |
String requestEncoding = "UTF-8"; |
| 41 |
msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding); |
| 42 |
|
| 43 |
String xml = xml1 + value + xml2; |
| 44 |
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); |
| 45 |
|
| 46 |
DeserializationContext dser = new DeserializationContext( |
| 47 |
new InputSource(bais), msgContext, org.apache.axis.Message.REQUEST); |
| 48 |
dser.parse(); |
| 49 |
|
| 50 |
org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope(); |
| 51 |
RPCElement rpcElem = (RPCElement)env.getFirstBody(); |
| 52 |
RPCParam output = rpcElem.getParam("testParam"); |
| 53 |
assertNotNull("No <testParam> param", output); |
| 54 |
|
| 55 |
String nodeValue = (String) output.getObjectValue(); |
| 56 |
assertNotNull("No node value for testParam param", nodeValue); |
| 57 |
assertEquals(expected, nodeValue); |
| 58 |
} |
| 59 |
|
| 60 |
public void testEntitizedCRLF() throws Exception { |
| 61 |
runtest("
Hello
World
", "\r\nHello\r\nWorld\r\n"); |
| 62 |
} |
| 63 |
|
| 64 |
public void testPlainCRLF() throws Exception { |
| 65 |
runtest("\r\nHello\r\nWorld\r\n", "\nHello\nWorld\n"); |
| 66 |
} |
| 67 |
|
| 68 |
public void testEntitizedCR() throws Exception { |
| 69 |
runtest("
Hello
World
", "\rHello\rWorld\r"); |
| 70 |
} |
| 71 |
|
| 72 |
public void testPlainCR() throws Exception { |
| 73 |
runtest("\rHello\rWorld\r", "\nHello\nWorld\n"); |
| 74 |
} |
| 75 |
} |