1 16 package test.message; 17 18 import junit.framework.Test; 19 import junit.framework.TestCase; 20 import junit.framework.TestSuite; 21 22 import javax.xml.soap.MessageFactory ; 23 import javax.xml.soap.MimeHeaders ; 24 import javax.xml.soap.Name ; 25 import javax.xml.soap.SOAPBody ; 26 import javax.xml.soap.SOAPBodyElement ; 27 import javax.xml.soap.SOAPMessage ; 28 import javax.xml.soap.SOAPPart ; 29 import java.io.ByteArrayInputStream ; 30 import java.util.Iterator ; 31 32 37 public class TestSOAPBody extends TestCase { 38 39 44 public static Test suite() { 45 return new TestSuite(test.message.TestSOAPBody.class); 46 } 47 48 53 public static void main(String [] argv) throws Exception { 54 TestSOAPBody tester = new TestSOAPBody("TestSOAPBody"); 55 tester.testSoapBodyBUG(); 56 } 57 58 63 public TestSOAPBody(String name) { 64 super(name); 65 } 66 67 String xmlString = 68 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 69 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" + 70 " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" + 71 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + 72 " <soapenv:Header>\n" + 73 " <shw:Hello xmlns:shw=\"http://www.jcommerce.net/soap/ns/SOAPHelloWorld\">\n" + 74 " <shw:Myname>Tony</shw:Myname>\n" + 75 " </shw:Hello>\n" + 76 " </soapenv:Header>\n" + 77 " <soapenv:Body>\n" + 78 " <shw:Address xmlns:shw=\"http://www.jcommerce.net/soap/ns/SOAPHelloWorld\">\n" + 79 " <shw:City>GENT</shw:City>\n" + 80 " </shw:Address>\n" + 81 " </soapenv:Body>\n" + 82 "</soapenv:Envelope>"; 83 84 89 public void testSoapBodyBUG() throws Exception { 90 MimeHeaders mimeheaders = new MimeHeaders (); 91 92 mimeheaders.addHeader("Content-Type", "text/xml"); 93 ByteArrayInputStream instream = new ByteArrayInputStream (xmlString.getBytes()); 94 MessageFactory factory = 95 MessageFactory.newInstance(); 96 SOAPMessage msg = 97 factory.createMessage(mimeheaders, instream); 98 org.apache.axis.client.AxisClient axisengine = 99 new org.apache.axis.client.AxisClient(); 100 101 ((org.apache.axis.Message) msg).setMessageContext( 103 new org.apache.axis.MessageContext(axisengine)); 104 SOAPPart sp = msg.getSOAPPart(); 105 javax.xml.soap.SOAPEnvelope se = sp.getEnvelope(); 106 javax.xml.soap.SOAPHeader sh = se.getHeader(); 107 SOAPBody sb = se.getBody(); 108 Iterator it = sb.getChildElements(); 109 int count = 0; 110 111 while (it.hasNext()) { 112 SOAPBodyElement el = (SOAPBodyElement ) it.next(); 113 count++; 114 Name name = el.getElementName(); 115 System.out.println("Element:" + el); 116 System.out.println("BODY ELEMENT NAME:" + name.getPrefix() + ":" 117 + name.getLocalName() + " " + name.getURI()); 118 } 119 assertTrue(count == 1); 120 } 121 } 122 | Popular Tags |