1 16 17 package samples.message; 18 19 import org.apache.axis.client.Call; 20 import org.apache.axis.client.Service; 21 import org.apache.axis.message.SOAPBodyElement; 22 import org.apache.axis.utils.Options; 23 import org.apache.axis.utils.XMLUtils; 24 import org.w3c.dom.CDATASection ; 25 import org.w3c.dom.Document ; 26 import org.w3c.dom.Element ; 27 28 import javax.xml.parsers.DocumentBuilder ; 29 import javax.xml.parsers.DocumentBuilderFactory ; 30 import java.net.URL ; 31 import java.util.Vector ; 32 33 36 public class TestMsg { 37 public String doit(String [] args) throws Exception { 38 Options opts = new Options(args); 39 opts.setDefaultURL("http://localhost:8080/axis/services/MessageService"); 40 41 Service service = new Service(); 42 Call call = (Call) service.createCall(); 43 44 call.setTargetEndpointAddress( new URL (opts.getURL()) ); 45 SOAPBodyElement[] input = new SOAPBodyElement[3]; 46 47 input[0] = new SOAPBodyElement(XMLUtils.StringToElement("urn:foo", 48 "e1", "Hello")); 49 input[1] = new SOAPBodyElement(XMLUtils.StringToElement("urn:foo", 50 "e1", "World")); 51 52 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 53 Document doc = builder.newDocument(); 54 Element cdataElem = doc.createElementNS("urn:foo", "e3"); 55 CDATASection cdata = doc.createCDATASection("Text with\n\tImportant <b> whitespace </b> and tags! "); 56 cdataElem.appendChild(cdata); 57 58 input[2] = new SOAPBodyElement(cdataElem); 59 60 Vector elems = (Vector ) call.invoke( input ); 61 SOAPBodyElement elem = null ; 62 Element e = null ; 63 64 elem = (SOAPBodyElement) elems.get(0); 65 e = elem.getAsDOM(); 66 67 String str = "Res elem[0]=" + XMLUtils.ElementToString(e); 68 69 elem = (SOAPBodyElement) elems.get(1); 70 e = elem.getAsDOM(); 71 str = str + "Res elem[1]=" + XMLUtils.ElementToString(e); 72 73 elem = (SOAPBodyElement) elems.get(2); 74 e = elem.getAsDOM(); 75 str = str + "Res elem[2]=" + XMLUtils.ElementToString(e); 76 77 return( str ); 78 } 79 80 public static void main(String [] args) throws Exception { 81 String res = (new TestMsg()).doit(args); 82 System.out.println(res); 83 } 84 } 85 | Popular Tags |