Cat.java:

 package com.war3.ws.domain;

 public class Cat {

     private Integer id;
private String name;
private String color; public Cat() {
super();
} public Cat(Integer id, String name, String color) {
super();
this.id = id;
this.name = name;
this.color = color;
} public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
} }

User.java:

 package com.war3.ws.domain;

 public class User {

     private Integer id;
private String name;
private String pass;
private String address; public User() {
super();
} public User(Integer id, String name, String pass, String address) {
super();
this.id = id;
this.name = name;
this.pass = pass;
this.address = address;
} public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
} @Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((pass == null) ? 0 : pass.hashCode());
return result;
} @Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
User other = (User) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (pass == null) {
if (other.pass != null)
return false;
} else if (!pass.equals(other.pass))
return false;
return true;
} }

UserService.java:

 package com.war3.service;

 import java.util.List;

 import com.war3.ws.domain.Cat;
import com.war3.ws.domain.User; public interface UserService { List<Cat> getCatsByUser(User user);
}

UserServiceImpl.java:

 package com.war3.service.impl;

 import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import com.war3.service.UserService;
import com.war3.ws.domain.Cat;
import com.war3.ws.domain.User; public class UserServiceImpl implements UserService { static Map<User,List<Cat>> catDb = new HashMap<User,List<Cat>>(); static{
List<Cat> catList1 = new ArrayList<Cat>();
catList1.add(new Cat(1,"加菲猫","橙色"));
catList1.add(new Cat(2,"机器猫","蓝色"));
catDb.put(new User(1,"孙悟空","1111","花果山"), catList1); List<Cat> catList2 = new ArrayList<Cat>();
catList2.add(new Cat(3,"熊猫","黑白色"));
catList2.add(new Cat(4,"kitty","白色"));
catDb.put(new User(2,"猪八戒","2222","高老庄"), catList2);
}
@Override
public List<Cat> getCatsByUser(User user) {
return catDb.get(user);
} }

HelloWorld.java:

 package com.war3.ws;

 import java.util.List;

 import javax.jws.WebService;

 import com.war3.ws.domain.Cat;
import com.war3.ws.domain.User; @WebService
public interface HelloWorld { List<Cat> getCatsByUser(User user);
String sayHi(String name);
}

HelloWorldWS.java:

 package com.war3.ws.impl;

 import java.util.List;

 import javax.jws.WebService;

 import com.war3.service.UserService;
import com.war3.service.impl.UserServiceImpl;
import com.war3.ws.HelloWorld;
import com.war3.ws.domain.Cat;
import com.war3.ws.domain.User; @WebService(endpointInterface="com.war3.ws.HelloWorld")
public class HelloWorldWS implements HelloWorld{ @Override
public List<Cat> getCatsByUser(User user) {
UserService us = new UserServiceImpl();
return us.getCatsByUser(user);
} @Override
public String sayHi(String name) {
return "welcome to the google"+name;
} }

ServerMain.java:

 package com.war3.ws.server;

 import javax.xml.ws.Endpoint;

 import com.war3.ws.HelloWorld;
import com.war3.ws.impl.HelloWorldWS; public class ServerMain { public static void main(String[] args) {
HelloWorld hw = new HelloWorldWS();
Endpoint.publish("http://localhost:8080/hello", hw);
System.out.println("WebService暴露服务成功!");
}
}

运行主类,暴露服务成功!

我们写一个测试类ClientMain.java:

 package com.war3.ws.client;

 import java.util.List;

 import com.war3.ws.Cat;
import com.war3.ws.HelloWorld;
import com.war3.ws.User;
import com.war3.ws.impl.HelloWorldWSService; public class ClientMain { public static void main(String[] args) {
HelloWorldWSService factory = new HelloWorldWSService();
HelloWorld hw = factory.getHelloWorldWSPort();
System.out.println(hw.sayHi("tom")); User user = new User();
user.setName("孙悟空");
user.setPass("1111");
List<Cat> catList = hw.getCatsByUser(user);
for(Cat cat:catList){
System.out.println(cat.getName()+","+cat.getColor());
}
}
}

CXF-02: 使用CXF处理JavaBean式的复合类型和List集合类型的更多相关文章

  1. 关于很简单的设计模式,ui-dao-database,以及JavaBean和util工具类

    关于很简单的设计模式,ui-dao-database,以及JavaBean和util工具类 24. 三 / J2EE / 没有评论   简单的j2ee设计模式, UI通过DAO层访问数据库或者xml文 ...

  2. 1067: spark.components:NavigatorContent 类型值的隐式强制指令的目标是非相关类型 String

    1.错误描写叙述 此行的多个标记: -workId -1067: spark.components:NavigatorContent 类型值的隐式强制指令的目标是非相关类型 String. 2.错误原 ...

  3. scala中隐式转换之隐式转换调用类中本不存在的方法

    /** * Created by root * Description : 隐式转换调用类中本不存在的方法 */ class Person(name : String){ def getPersonN ...

  4. javabean(实体类)转Map类型

    javabean(实体类)转Map类型 从网上"風亦飞"的导出EXCEL的源代码提取出来的.认为非常好用.分享一下给大家,主要看beanToMap方法就OK了 /*以下是从poi导 ...

  5. 设计模式——懒汉式单例类PK饿汉式单例类

    前言 我们都知道生活中好多小软件,有的支持多IP在线,有的仅仅局限于单个IP在线.为什么这样设计,在软件开发阶段就是,有需求就是发展.这就是软件开发的一个设计模式--懒汉式单例类和饿汉式单例类. 内容 ...

  6. 解决.Net MVC 中出现 非介入式客户端验证规则中的验证类型名称必须唯一。下列验证类型出现重复: required 的bug

    最近在开动科技创新作品的开发,出现了一个让人很烦恼的错误,每次从浏览页跳转到编辑页时就会出现一下错误 非介入式客户端验证规则中的验证类型名称必须唯一.下列验证类型出现重复: required 上一下出 ...

  7. CXF学习(4) 处理无法自动转换的复合数据类型

    只贴出服务端代码 1.Service接口类 package com.test.hello; import java.util.Map; import javax.jws.WebService; imp ...

  8. (二)CXF之用CXF官方工具生成客户端Client

    一.CXF工具的下载与使用 登录CXF官网:http://cxf.apache.org/download.html 下载,本系列使用的是3.1.5版本: 添加path环境变量 二.案例 2.1 发布w ...

  9. css笔记02:选择器(标签式和类)

    body { margin:; padding:; background:#000 url('images/backgrounds/star.png') no-repeat fixed; font: ...

随机推荐

  1. sys.argv[]用法-转载

    sys.argv变量是一个字符串的列表.特别地,sys.argv包含了命令行参数 的列表,即使用命令行传递给你的程序的参数. 这里,当我们执行python using_sys.py we are ar ...

  2. http缓存(http caching)

    通过使用缓存web网站和web应用的性能能够得到显著的提升.Web caches能够减小延迟和网络流量,从而缩短展示资源所花费的时间. 在http中控制缓存行为的首部字段是Cache-Control, ...

  3. 碎片︱R语言与深度学习

    笔者:受alphago影响,想看看深度学习,但是其在R语言中的应用包可谓少之又少,更多的是在matlab和python中或者是调用.整理一下目前我看到的R语言的材料: ---------------- ...

  4. Caused by: java.lang.ClassNotFoundException: com.mchange.v2.ser.Indirector

    1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...

  5. Array.from()

    es6 Array.from() 方法将两类对象转为真正的数组 用法:用于将两类对象转为真正的数组:类似数组的对象和可遍历(iterable)的对象(包含ES6新增的数据结构Set和Map); 说明: ...

  6. mac下安装ELK

    本文主要为自己所走弯路而做的补充,对小白(比如我)来讲某些博客讲的还是高深了,特地来此补充说明一些东西. 主要步骤参考http://blog.csdn.net/ywheel1989/article/d ...

  7. R语言学习 第七篇:列表

    列表(List)是R中最复杂的数据类型,一般来说,列表是数据对象的有序集合,但是,列表的各个元素(item)的数据类型可以不同,每个元素的长度可以不同,是R中最灵活的数据类型.列表项可以是列表类型,因 ...

  8. AI CV 会议2018

    (1) NIPS,  Conference and Workshop on Neural Information Processing Systems, A类顶会 1987年由联结主义学派创建,每年一 ...

  9. thinkphp5源码解析(2)控制器

    入口文件index.php: // 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 require __DIR ...

  10. ArcGIS API for JavaScript 4.4 版本加载谷歌地图

    ArcGIS API for JavaScript 4.X 版本升级后,API发生了很大的变化. 其中就支持了WebEarth展示,主要是通过 esri/views/SceneView 实现的. 在新 ...