1 package demo.handlers.client; 2 3 import java.io.File ; 4 import javax.xml.namespace.QName ; 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 serviceName = new QName ("http://www.objectweb.org/handlers", 13 "AddNumbersService"); 14 15 static QName portName = new QName ("http://www.objectweb.org/handlers", 16 "AddNumbersPort"); 17 private Client() { 18 } 19 20 public static void main(String [] args) throws Exception { 21 22 if (args.length == 0) { 23 System.err.println("please provide wsdl"); 24 System.exit(0); 25 } 26 27 File wsdl = new File (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 |