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. SELinux一键开启与禁用脚本

    SELinux是美国国家安全局(NSA)对于强制访问控制的实现,是 Linux历史上最杰出的新安全子系统.但是SELinux的并不能与众多服务很好的兼容,有些人会关闭SELinux一了百了.在日常的运 ...

  2. H3C三层交换机配置IP

    1.直接在物理端口上设置IP地址. int f1/0/1 port link-mode route #链路模式采用路由 ip add 192.168.10.1 24 ospf network0type ...

  3. Hive数据倾斜总结

    倾斜的原因: 使map的输出数据更均匀的分布到reduce中去,是我们的最终目标.由于Hash算法的局限性,按key Hash会或多或少的造成数据倾斜.大量经验表明数据倾斜的原因是人为的建表疏忽或业务 ...

  4. ffmpeg结构体以及函数介绍(一)

    本文对在使用ffmpeg进行音视频编解码时使用到的一些函数做一个简单介绍,我当前使用的ffmpeg版本为:0.8.5,因为本人发现在不同的版本中,有些函数名称会有点小改动,所以在此有必要说明下ffmp ...

  5. Java Web项目(Extjs)报错三

    1. Java Web项目(Extjs)报错三 具体报错如下: at org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEng ...

  6. Java Web项目(Extjs)报错二

    1.Java Web项目(Extjs)报错二 具体报错如下: usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ...

  7. tar (child): jdk-7u71-linux-x64.tar.gz:无法 open: 没有那个文件或目录

    1 错误描述 youhaidong@youhaidong:~$ sudo mkdir /usr/lib/jvm [sudo] password for youhaidong: youhaidong@y ...

  8. Mac 常用快捷键

    可以按下组合键来实现通常需要鼠标.触控板或其他输入设备才能完成的操作. 要使用键盘快捷键,需按住一个或多个修饰键,同时按快捷键的最后一个键.例如,要使用快捷键 Command-C(拷贝),请按住 Co ...

  9. iOS - MySQL 的安装配置

    前言 提前下载好相关软件,且安装目录最好安装在全英文路径下.如果路径有中文名,那么可能会出现一些莫名其妙的问题. 提前准备好的软件: mysql-5.7.17-macos10.12-x86_64.dm ...

  10. Mybatis if test 中int判断非空的坑

    Mybatis 中,alarmType 是int类型.如果alarmType 为0的话,条件判断返回结果为false,其它值的话,返回true. <if test="alarmType ...