1 package test.functional; 2 3 import junit.framework.TestCase; 4 import org.apache.axis.AxisEngine; 5 import org.apache.axis.client.Call; 6 import org.apache.axis.client.Service; 7 8 import javax.xml.messaging.URLEndpoint; 9 import javax.xml.soap.MessageFactory ; 10 import javax.xml.soap.Name ; 11 import javax.xml.soap.SOAPBody ; 12 import javax.xml.soap.SOAPBodyElement ; 13 import javax.xml.soap.SOAPConnection ; 14 import javax.xml.soap.SOAPConnectionFactory ; 15 import javax.xml.soap.SOAPElement ; 16 import javax.xml.soap.SOAPEnvelope ; 17 import javax.xml.soap.SOAPMessage ; 18 19 import java.net.URL ; 20 21 24 public class TestEncoding extends TestCase { 25 Call call = null; 26 27 public TestEncoding(String s) { 28 super(s); 29 } 30 31 protected void setUp() throws Exception { 32 if (call == null) { 33 Service service = new Service(); 34 service.getEngine().setOption(AxisEngine.PROP_XML_ENCODING, "UTF-8"); 35 call = (Call) service.createCall(); 36 call.setTargetEndpointAddress(new URL ("http://localhost:8080/jws/EchoHeaders.jws")); 37 } 38 } 39 40 private void runtest(String send, String get) throws Exception { 41 String ret = (String ) call.invoke("echo", new Object []{send}); 42 assertEquals(ret, get); 43 } 44 45 private void runtest(String value) throws Exception { 46 runtest(value, value); 47 } 48 49 public void testSimpleString() throws Exception { 50 runtest("a simple string"); 51 } 52 53 public void testStringWithApostrophes() throws Exception { 54 runtest("this isn't a simple string"); 55 } 56 57 public void testStringWithEntities() throws Exception { 58 runtest("&<>'"", "&<>'""); 59 } 60 61 public void testStringWithRawEntities() throws Exception { 62 runtest("&<>'\"", "&<>'\""); 63 } 64 65 public void testStringWithLeadingAndTrailingSpaces() throws Exception { 66 runtest(" centered "); 67 } 68 69 public void testWhitespace() throws Exception { 70 runtest(" \n \t "); } 72 73 public void testFrenchAccents() throws Exception { 74 runtest("\u00e0\u00e2\u00e4\u00e7\u00e8\u00e9\u00ea\u00eb\u00ee\u00ef\u00f4\u00f6\u00f9\u00fb\u00fc"); 75 } 76 77 public void testFrenchAccents2() throws Exception { 78 runtest("Une chaîne avec des caractères accentués"); 79 } 80 81 public void testGermanUmlauts() throws Exception { 82 runtest(" Some text \u00df with \u00fc special \u00f6 chars \u00e4."); 83 } 84 85 public void testWelcomeUnicode() throws Exception { 86 runtest( 88 "Chinese (trad.) : \u6b61\u8fce \n" + 89 "Greek : \u03ba\u03b1\u03bb\u03ce\u03c2 \u03bf\u03c1\u03af\u03c3\u03b1\u03c4\u03b5 \n" + 90 "Japanese : \u3088\u3046\u3053\u305d"); 91 } 92 93 public void testSynchronization() throws Exception { 94 SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance(); 95 SOAPConnection con = scFactory.createConnection(); 96 97 MessageFactory factory = MessageFactory.newInstance(); 98 SOAPMessage message = factory.createMessage(); 99 String requestEncoding = "UTF-16"; 100 message.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding); 101 102 SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); 103 SOAPBody body = envelope.getBody(); 104 105 Name bodyName = envelope.createName("echo"); 106 SOAPBodyElement bodyElement = body.addBodyElement(bodyName); 107 108 Name name = envelope.createName("arg0"); 109 SOAPElement symbol = bodyElement.addChildElement(name); 110 symbol.addTextNode("Hello"); 111 112 URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/EchoHeaders.jws"); 113 SOAPMessage response = con.call(message, endpoint); 114 String responseEncoding = (String ) response.getProperty(SOAPMessage.CHARACTER_SET_ENCODING); 115 assertEquals(requestEncoding.toLowerCase(), responseEncoding.toLowerCase()); 116 } 117 } 118 | Popular Tags |