KickJava   Java API By Example, From Geeks To Geeks.

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


1 package demo.handlers.client;
2
3 import java.io.File JavaDoc;
4 import javax.xml.namespace.QName JavaDoc;
5 import org.objectweb.handlers.AddNumbers;
6 import org.objectweb.handlers.AddNumbersFault;
7 import org.objectweb.handlers.AddNumbersService;
8
9
10 public final class Client {
11
12     static QName JavaDoc serviceName = new QName JavaDoc("http://www.objectweb.org/handlers",
13                                            "AddNumbersService");
14
15     static QName JavaDoc portName = new QName JavaDoc("http://www.objectweb.org/handlers",
16                                         "AddNumbersPort");
17     private Client() {
18     }
19
20     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
21
22         if (args.length == 0) {
23             System.err.println("please provide wsdl");
24             System.exit(0);
25         }
26
27         File JavaDoc wsdl = new File JavaDoc(args[0]);
28
29         AddNumbersService service = new AddNumbersService(wsdl.toURL(), serviceName);
30         AddNumbers port = (AddNumbers)service.getPort(portName, AddNumbers.class);
31         
32         try {
33             int number1 = 10;
34             int number2 = 20;
35
36             System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
37             int result = port.addNumbers(number1, number2);
38             System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2, result);
39
40             number1 = 3;
41             number2 = 5;
42
43             System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
44             result = port.addNumbers(number1, number2);
45             System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2, result);
46             
47             number1 = -10;
48             System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
49             result = port.addNumbers(number1, number2);
50             System.out.printf("The result of adding %d and %d is %d.\n", number1, number2, result);
51
52         } catch (AddNumbersFault ex) {
53             System.out.printf("Caught AddNumbersFault: %s\n", ex.getFaultInfo().getMessage());
54         }
55
56         System.exit(0);
57     }
58 }
59
Popular Tags