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 18 public class TestString2 extends TestCase { 19 20 public static final String myNS = "urn:myNS"; 21 22 public TestString2(String name) { 23 super(name); 24 } 25 26 private void runtest(String value, String expected) throws Exception { 27 MessageContext msgContext = new MessageContext(new AxisServer()); 28 MessageFactory factory = MessageFactory.newInstance(); 29 org.apache.axis.Message message = (org.apache.axis.Message) factory.createMessage(); 30 message.setMessageContext(msgContext); 31 String requestEncoding = "UTF-16"; 32 msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding); 33 message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding); 34 RPCParam input = new RPCParam("urn:myNamespace", "testParam", value); 35 36 RPCElement body = new RPCElement("urn:myNamespace", "method1", new Object []{ input }); 37 message.getSOAPBody().addChildElement(body); 38 39 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 40 message.writeTo(baos); 41 42 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 43 DeserializationContext dser = new DeserializationContext( 44 new InputSource (bais), msgContext, org.apache.axis.Message.REQUEST); 45 dser.parse(); 46 47 org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope(); 48 RPCElement rpcElem = (RPCElement)env.getFirstBody(); 49 RPCParam output = rpcElem.getParam("testParam"); 50 assertNotNull("No <testParam> param", output); 51 52 String result = (String )output.getObjectValue(); 53 assertNotNull("No value for testParam param", result); 54 assertEquals("Expected result not received.", expected, result); 55 56 String nodeValue = output.getValue(); 57 assertNotNull("No node value for testParam param", nodeValue); 58 assertEquals(expected, nodeValue); 59 } 60 61 private void runtest(String value) throws Exception { 62 runtest(value, value); 63 } 64 65 public void testSimpleString() throws Exception { 66 runtest("a simple string"); 67 } 68 69 public void testStringWithApostrophes() throws Exception { 70 runtest("this isn't a simple string"); 71 } 72 73 public void testStringWithEntities() throws Exception { 74 runtest("&<>'"", "&<>'""); 75 } 76 77 public void testStringWithRawEntities() throws Exception { 78 runtest("&<>'\"", "&<>'\""); 79 } 80 81 public void testStringWithLeadingAndTrailingSpaces() throws Exception { 82 runtest(" centered "); 83 } 84 85 public void testWhitespace() throws Exception { 86 runtest(" \n \t "); } 88 89 public void testFrenchAccents() throws Exception { 90 runtest("\u00e0\u00e2\u00e4\u00e7\u00e8\u00e9\u00ea\u00eb\u00ee\u00ef\u00f4\u00f6\u00f9\u00fb\u00fc"); 91 } 92 93 public void testFrenchAccents2() throws Exception { 94 runtest("Une chaîne avec des caractères accentués"); 95 } 96 97 public void testGermanUmlauts() throws Exception { 98 runtest(" Some text \u00df with \u00fc special \u00f6 chars \u00e4."); 99 } 100 101 public void testWelcomeUnicode() throws Exception { 102 runtest( 104 "Chinese (trad.) : \u6b61\u8fce "); 105 } 106 107 public void testWelcomeUnicode2() throws Exception { 108 runtest( 110 "Greek : \u03ba\u03b1\u03bb\u03ce\u03c2 \u03bf\u03c1\u03af\u03c3\u03b1\u03c4\u03b5"); 111 } 112 113 public void testWelcomeUnicode3() throws Exception { 114 runtest( 116 "Japanese : \u3088\u3046\u3053\u305d"); 117 } 118 } 119 | Popular Tags |