KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > message > TestMsg


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
25 import org.w3c.dom.Document JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27
28 import javax.xml.parsers.DocumentBuilder JavaDoc;
29 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
30 import java.net.URL JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 /**
34  * Simple test driver for our message service.
35  */

36 public class TestMsg {
37     public String JavaDoc doit(String JavaDoc[] args) throws Exception JavaDoc {
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 JavaDoc(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 JavaDoc builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
53         Document JavaDoc doc = builder.newDocument();
54         Element cdataElem = doc.createElementNS("urn:foo", "e3");
55         CDATASection JavaDoc 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 JavaDoc elems = (Vector JavaDoc) 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 JavaDoc 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 JavaDoc[] args) throws Exception JavaDoc {
81         String JavaDoc res = (new TestMsg()).doit(args);
82         System.out.println(res);
83     }
84 }
85
Popular Tags