KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > hello_world_soap_http > GreeterClient


1 package org.objectweb.hello_world_soap_http;
2
3 import java.net.URL JavaDoc;
4
5 import javax.xml.namespace.QName JavaDoc;
6
7 import org.objectweb.celtix.Bus;
8
9 public class GreeterClient {
10     
11     protected GreeterClient() {
12     }
13     
14     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
15         
16         String JavaDoc operationName = "sayHi";
17         if (args.length > 0) {
18             operationName = args[0];
19         }
20         String JavaDoc[] params = null;
21         if (args.length > 1) {
22             params = new String JavaDoc[args.length - 1];
23             System.arraycopy(args, 1, params, 0, params.length);
24         }
25         
26         System.out.println("Invoking operation: " + operationName);
27         System.out.print("Parameters:");
28         for (String JavaDoc p : params) {
29             System.out.print(" " + p);
30         }
31         System.out.println();
32         
33         Bus bus = Bus.init();
34         
35         URL JavaDoc url = GreeterClient.class.getResource("/wsdl/hello_world.wsdl");
36         assert null != url;
37         
38         QName JavaDoc serviceName = new QName JavaDoc("http://objectweb.org/hello_world_soap_http", "SOAPService");
39         SOAPService ss = new SOAPService(url, serviceName);
40         Greeter port = ss.getSoapPort();
41         
42         if ("sayHi".equals(operationName)) {
43             System.out.println("Invoking sayHi...");
44             System.out.println("server responded with: " + port.sayHi());
45         } else if ("greetMe".equals(operationName) && params != null && params.length > 0) {
46             System.out.println("Invoking greetMe...");
47             System.out.println("server responded with: " + port.greetMe(params[0]));
48         } else if ("greetMeOneWay".equals(operationName) && params != null && params.length > 0) {
49             System.out.println("Invoking greetMeOneWay...");
50             port.greetMeOneWay(params[0]);
51             System.out.println("no response from server as method is OneWay");
52         } else {
53             System.err.println("No such operation");
54         }
55         
56         
57         bus.shutdown(true);
58     }
59
60 }
61
Popular Tags