KickJava   Java API By Example, From Geeks To Geeks.

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


1 package demo.hw_https.client;
2
3 import java.io.File JavaDoc;
4 import java.net.URL JavaDoc;
5 import javax.xml.namespace.QName JavaDoc;
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 JavaDoc SERVICE_NAME
12         = new QName JavaDoc("http://objectweb.org/hello_world_soap_http", "SOAPService");
13     
14     
15     private static final QName JavaDoc SECURE_PORT_NAME =
16         new QName JavaDoc("http://objectweb.org/hello_world_soap_http",
17                   "SecurePort");
18     
19     private static final QName JavaDoc STRICT_SECURE_PORT_NAME =
20         new QName JavaDoc("http://objectweb.org/hello_world_soap_http",
21                   "StrictSecurePort");
22     
23
24     private static final QName JavaDoc INSECURE_PORT_NAME =
25         new QName JavaDoc("http://objectweb.org/hello_world_soap_http",
26                   "InsecurePort");
27
28
29     private Client() {
30     }
31
32     public static void main(String JavaDoc args[]) throws Exception JavaDoc {
33         
34         if (args.length == 0) {
35             System.out.println("please specify wsdl");
36             System.exit(1);
37         }
38
39         URL JavaDoc wsdlURL;
40         File JavaDoc wsdlFile = new File JavaDoc(args[0]);
41         if (wsdlFile.exists()) {
42             wsdlURL = wsdlFile.toURL();
43         } else {
44             wsdlURL = new URL JavaDoc(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 JavaDoc configurerProperty = "celtix.security.configurer"
57                         + ".celtix.{http://objectweb.org/hello_world_soap_http}"
58                         + "SOAPService/StrictSecurePort.http-client";
59             String JavaDoc 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 JavaDoc 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 JavaDoc 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