Samples JDK
Client.java
1 package com.freemindcafe.apache.cxf.wsdl.sample1;
2 
3 import java.io.File;
4 import java.net.URL;
5 
6 import javax.xml.namespace.QName;
7 
8 import org.apache.cxf.interceptor.LoggingInInterceptor;
9 import org.apache.cxf.interceptor.LoggingOutInterceptor;
10 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
14 import org.junit.Test;
15 
16 public final class Client {
17 
18  /**
19  * Has client code using SoapService. But It does not have any wsse or basic auth headers.
20  * @throws Exception
21  */
22  @Test
23  public void soap_service_based_client() throws Exception{
24 
25  QName SERVICE_NAME = new QName("http://apache.org/hello_world_soap_http","SOAPService");
26 
27  URL wsdlURL;
28  File wsdlFile = new File("src\\com\\freemindcafe\\apache\\cxf\\wsdl\\helloworld.wsdl");
29  wsdlURL = wsdlFile.toURL();
30 
31  System.out.println(wsdlURL);
32  SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
33  Greeter port = ss.getSoapPort();
34  String resp;
35 
36  System.out.println("Invoking sayHi...");
37  resp = port.sayHi();
38  System.out.println("Server responded with: " + resp);
39  System.out.println();
40 
41  System.out.println("Invoking greetMe...");
42  resp = port.greetMe(System.getProperty("user.name"));
43  System.out.println("Server responded with: " + resp);
44  System.out.println();
45 
46  System.out.println("Invoking greetMeOneWay...");
47  port.greetMeOneWay(System.getProperty("user.name"));
48  System.out.println("No response from server as method is OneWay");
49  System.out.println();
50 
51  try {
52  System.out.println("Invoking pingMe, expecting exception...");
53  port.pingMe();
54  } catch (PingMeFault ex) {
55  System.out.println("Expected exception: PingMeFault has occurred.");
56  System.out.println(ex.toString());
57  }
58  System.exit(0);
59 
60  }
61 
62  /**
63  * Has client code using JaxWsProxyFactoryBean. But It does not have any wsse or basic auth headers.
64  */
65  @Test
67  JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
68  factory.getInInterceptors().add(new LoggingInInterceptor());
69  factory.getOutInterceptors().add(new LoggingOutInterceptor());
70  factory.setServiceClass(Greeter.class);
71  factory.setAddress("http://localhost:9001/SoapContext/SoapPort");
72  Greeter client = (Greeter) factory.create();
73 
74  String reply = client.greetMe("nik");
75  System.out.println("Server said: " + reply);
76  System.exit(0);
77  }
78 
79 }