1 package demo.hw.client; 2 3 import java.io.File ; 4 import java.net.URL ; 5 import javax.xml.namespace.QName ; 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 SERVICE_NAME 13 = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService"); 14 15 16 private Client() { 17 } 18 19 public static void main(String args[]) throws Exception { 20 21 if (args.length == 0) { 22 System.out.println("please specify wsdl"); 23 System.exit(1); 24 } 25 26 URL wsdlURL; 27 File wsdlFile = new File (args[0]); 28 if (wsdlFile.exists()) { 29 wsdlURL = wsdlFile.toURL(); 30 } else { 31 wsdlURL = new URL (args[0]); 32 } 33 34 System.out.println(wsdlURL); 35 SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME); 36 Greeter port = ss.getSoapPort(); 37 String 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 |