KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > hw > client > Client


1 package demo.hw.client;
2
3 import java.io.File JavaDoc;
4 import java.net.URL JavaDoc;
5 import javax.xml.namespace.QName JavaDoc;
6 import org.objectweb.hello_world_soap_http.Greeter;
7 import org.objectweb.hello_world_soap_http.PingMeFault;
8 import org.objectweb.hello_world_soap_http.SOAPService;
9
10 public final class Client {
11
12     private static final QName JavaDoc SERVICE_NAME
13         = new QName JavaDoc("http://objectweb.org/hello_world_soap_http", "SOAPService");
14
15
16     private Client() {
17     }
18
19     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
20         
21         if (args.length == 0) {
22             System.out.println("please specify wsdl");
23             System.exit(1);
24         }
25
26         URL JavaDoc wsdlURL;
27         File JavaDoc wsdlFile = new File JavaDoc(args[0]);
28         if (wsdlFile.exists()) {
29             wsdlURL = wsdlFile.toURL();
30         } else {
31             wsdlURL = new URL JavaDoc(args[0]);
32         }
33         
34         System.out.println(wsdlURL);
35         SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
36         Greeter port = ss.getSoapPort();
37         String JavaDoc resp;
38
39         System.out.println("Invoking sayHi...");
40         resp = port.sayHi();
41         System.out.println("Server responded with: " + resp);
42         System.out.println();
43
44         System.out.println("Invoking greetMe...");
45         resp = port.greetMe(System.getProperty("user.name"));
46         System.out.println("Server responded with: " + resp);
47         System.out.println();
48
49         System.out.println("Invoking greetMeOneWay...");
50         port.greetMeOneWay(System.getProperty("user.name"));
51         System.out.println("No response from server as method is OneWay");
52         System.out.println();
53
54         try {
55             System.out.println("Invoking pingMe, expecting exception...");
56             port.pingMe();
57         } catch (PingMeFault ex) {
58             System.out.println("Expected exception: PingMeFault has occurred.");
59             System.out.println(ex.toString());
60         }
61         System.exit(0);
62     }
63
64 }
Popular Tags