1 16 package org.apache.axis2.saaj; 17 18 import junit.framework.TestCase; 19 20 import javax.xml.soap.*; 21 import java.util.Iterator ; 22 23 27 public class SOAPBodyTest extends TestCase { 28 29 34 38 43 public static void main(String [] argv) throws Exception { 44 SOAPBodyTest tester = new SOAPBodyTest("TestSOAPBody"); 45 tester.testSoapBodyBUG(); 46 } 47 48 53 public SOAPBodyTest(String name) { 54 super(name); 55 } 56 57 62 public void testSoapBodyBUG() throws Exception { 63 64 MessageFactory fact = MessageFactory.newInstance(); 65 SOAPMessage message = fact.createMessage(); 66 SOAPPart soapPart = message.getSOAPPart(); 67 SOAPEnvelopeImpl env = (SOAPEnvelopeImpl)soapPart.getEnvelope(); 68 SOAPHeader header = env.getHeader(); 69 Name hns = env.createName("Hello","shw", "http://www.jcommerce.net/soap/ns/SOAPHelloWorld"); 70 SOAPElement headElmnt = header.addHeaderElement(hns); 71 Name hns1 = env.createName("Myname","shw", "http://www.jcommerce.net/soap/ns/SOAPHelloWorld"); 72 SOAPElement myName = headElmnt.addChildElement(hns1); 73 myName.addTextNode("Tony"); 74 Name ns = env.createName("Address", "shw", "http://www.jcommerce.net/soap/ns/SOAPHelloWorld"); 75 SOAPBody body = env.getBody(); 76 SOAPElement bodyElmnt = body.addBodyElement(ns); 77 Name ns1 = env.createName("City", "shw", "http://www.jcommerce.net/soap/ns/SOAPHelloWorld"); 78 SOAPElement city = bodyElmnt.addChildElement(ns1); 79 city.addTextNode("GENT"); 80 81 Iterator it = body.getChildElements(); 82 int count = 0; 83 84 while (it.hasNext()) { 85 SOAPElement el = (SOAPElement) it.next(); 86 count++; 87 Name name = el.getElementName(); 88 System.out.println("Element:" + el); 89 System.out.println("BODY ELEMENT NAME:" + name.getPrefix() + ":" 90 + name.getLocalName() + " " + name.getURI()); 91 } 92 assertTrue(count == 1); 93 } 94 95 } 96 | Popular Tags |