KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > samples > encoding > TestElem


1 package samples.encoding;
2
3 import org.apache.axis.client.Call;
4 import org.apache.axis.client.Service;
5 import org.apache.axis.utils.Options;
6 import org.apache.axis.utils.XMLUtils;
7 import org.w3c.dom.Element JavaDoc;
8
9 import javax.xml.namespace.QName JavaDoc;
10 import java.io.ByteArrayInputStream JavaDoc;
11 import java.net.URL JavaDoc;
12
13 public class TestElem {
14     static String JavaDoc xml = "<x:hello xmlns:x=\"urn:foo\">a string</x:hello>" ;
15
16     public static String JavaDoc doit(String JavaDoc[] args,String JavaDoc xml) throws Exception JavaDoc {
17         ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(xml.getBytes());
18
19         String JavaDoc sURL = "http://" + args[0] + ":" + args[1] + "/axis/services/ElementService" ;
20         QName JavaDoc sqn = new QName JavaDoc(sURL, "ElementService" );
21         QName JavaDoc pqn = new QName JavaDoc(sURL, "ElementService" );
22
23         //Service service=new Service(new URL("file:ElementService.wsdl"),sqn);
24
Service service = new Service(new URL JavaDoc(sURL+"?wsdl"),sqn);
25         Call call = (Call) service.createCall( pqn, "echoElement" );
26
27         Options opts = new Options(args);
28         opts.setDefaultURL( call.getTargetEndpointAddress() );
29         call.setTargetEndpointAddress( new URL JavaDoc(opts.getURL()) );
30
31         Element JavaDoc elem = XMLUtils.newDocument(bais).getDocumentElement();
32
33         elem = (Element JavaDoc) call.invoke( new Object JavaDoc[] { "a string", elem } );
34         return( XMLUtils.ElementToString( elem ) );
35     }
36
37     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
38         System.out.println("Sent: " + xml );
39         String JavaDoc res = doit(args, xml);
40         System.out.println("Returned: " + res );
41     }
42 }
43
Popular Tags