1 package demo.hw_https.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.SOAPService; 8 9 public final class Client { 10 11 private static final QName SERVICE_NAME 12 = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService"); 13 14 15 private static final QName SECURE_PORT_NAME = 16 new QName ("http://objectweb.org/hello_world_soap_http", 17 "SecurePort"); 18 19 private static final QName STRICT_SECURE_PORT_NAME = 20 new QName ("http://objectweb.org/hello_world_soap_http", 21 "StrictSecurePort"); 22 23 24 private static final QName INSECURE_PORT_NAME = 25 new QName ("http://objectweb.org/hello_world_soap_http", 26 "InsecurePort"); 27 28 29 private Client() { 30 } 31 32 public static void main(String args[]) throws Exception { 33 34 if (args.length == 0) { 35 System.out.println("please specify wsdl"); 36 System.exit(1); 37 } 38 39 URL wsdlURL; 40 File wsdlFile = new File (args[0]); 41 if (wsdlFile.exists()) { 42 wsdlURL = wsdlFile.toURL(); 43 } else { 44 wsdlURL = new URL (args[0]); 45 } 46 47 System.out.println(wsdlURL); 48 SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME); 49 Greeter port; 50 51 if ((args[1] != null) && (args[1].equalsIgnoreCase("secure_user"))) { 52 System.out.println("The secure_user credentials will be used for the invocation."); 53 System.out.println(); 54 port = ss.getPort(SECURE_PORT_NAME, Greeter.class); 55 } else if ((args[1] != null) && (args[1].equalsIgnoreCase("strict_secure_user"))) { 56 String configurerProperty = "celtix.security.configurer" 57 + ".celtix.{http://objectweb.org/hello_world_soap_http}" 58 + "SOAPService/StrictSecurePort.http-client"; 59 String configurerClass = "demo.hw_https.common.DemoSecurityConfigurer"; 60 System.setProperty(configurerProperty, configurerClass); 61 System.out.println("The strict_secure_user credentials will be used for the invocation."); 62 System.out.println("Extra security data will be provided by the class, " + configurerClass 63 + " because the system property " + configurerProperty 64 + " has been set."); 65 System.out.println(); 66 port = ss.getPort(STRICT_SECURE_PORT_NAME, Greeter.class); 67 } else { 68 System.out.println("The insecure_user credentials will be used for the invocation."); 69 System.out.println(); 70 port = ss.getPort(INSECURE_PORT_NAME, Greeter.class); 71 } 72 73 String resp; 74 75 System.out.println("Invoking greetMe..."); 76 try { 77 resp = port.greetMe(System.getProperty("user.name")); 78 System.out.println("Server responded with: " + resp); 79 System.out.println(); 80 81 } catch (Exception e) { 82 System.out.println("Invocation to server failed with the following error : " + e.getCause()); 83 System.out.println(); 84 } 85 86 System.exit(0); 87 } 88 89 } 90 | Popular Tags |