/**
*
*/
package lee;
import java.util.List;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.fkjava.cfx.ws.Cat;
import org.fkjava.cfx.ws.Entry;
import org.fkjava.cfx.ws.HelloWorld;
import org.fkjava.cfx.ws.HelloWorldService;
import org.fkjava.cfx.ws.StringCat;
import org.fkjava.cfx.ws.User;
/**
* @author Kevin 客户端调用服务器端暴露出来的服务 客户端不是直接跟远端服务器打交道,而是通过远端服务器代理,即存根,所以客户端首先要拿到存根
*/
public class ClientMain {
/**
* @param args
*/
public static void main(String[] args) {
// 得到org.fkjava.cfx.ws.impl.HelloWorldWs(这个类实现接口javax.xml.ws.Service,
// 此类能够得到远端服务器的代理,即是能得到存根)
HelloWorldService helloWorldWs = new HelloWorldService();
// org.fkjava.cfx.ws.impl.HelloWorldWs.getHelloWorldWsPort()
// 能得到存根,存根实现接口org.fkjava.cfx.ws.HelloWorld
HelloWorld helloWorld = helloWorldWs.getHelloWorldPort();
// 为客户端增加拦截器,在调用Web Services之前
Client client = ClientProxy.getClient(helloWorld);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
System.out.println(helloWorld.sayHi("Tom"));
System.out.println("=================================");
User user = new User();
user.setName("里斯");
user.setPassword("456789");
List<Cat> cats = helloWorld.getCatsByUser(user);
for (Cat cat : cats) {
System.out.println("猫的信息如下:");
System.out.println(cat.getId());
System.out.println(cat.getName());
System.out.println(cat.getColor());
}
System.out.println("=================================");
StringCat stringCat = helloWorld.getAllCats();
for (Entry entry : stringCat.getEntryList()) {
System.out.println(entry.getKey() + entry.getValue().getName());
}
System.out.println("客户端调用成功!");
}
}