CXF-02: 使用CXF处理JavaBean式的复合类型和List集合类型

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集合类型的更多相关文章
- 关于很简单的设计模式,ui-dao-database,以及JavaBean和util工具类
关于很简单的设计模式,ui-dao-database,以及JavaBean和util工具类 24. 三 / J2EE / 没有评论 简单的j2ee设计模式, UI通过DAO层访问数据库或者xml文 ...
- 1067: spark.components:NavigatorContent 类型值的隐式强制指令的目标是非相关类型 String
1.错误描写叙述 此行的多个标记: -workId -1067: spark.components:NavigatorContent 类型值的隐式强制指令的目标是非相关类型 String. 2.错误原 ...
- scala中隐式转换之隐式转换调用类中本不存在的方法
/** * Created by root * Description : 隐式转换调用类中本不存在的方法 */ class Person(name : String){ def getPersonN ...
- javabean(实体类)转Map类型
javabean(实体类)转Map类型 从网上"風亦飞"的导出EXCEL的源代码提取出来的.认为非常好用.分享一下给大家,主要看beanToMap方法就OK了 /*以下是从poi导 ...
- 设计模式——懒汉式单例类PK饿汉式单例类
前言 我们都知道生活中好多小软件,有的支持多IP在线,有的仅仅局限于单个IP在线.为什么这样设计,在软件开发阶段就是,有需求就是发展.这就是软件开发的一个设计模式--懒汉式单例类和饿汉式单例类. 内容 ...
- 解决.Net MVC 中出现 非介入式客户端验证规则中的验证类型名称必须唯一。下列验证类型出现重复: required 的bug
最近在开动科技创新作品的开发,出现了一个让人很烦恼的错误,每次从浏览页跳转到编辑页时就会出现一下错误 非介入式客户端验证规则中的验证类型名称必须唯一.下列验证类型出现重复: required 上一下出 ...
- CXF学习(4) 处理无法自动转换的复合数据类型
只贴出服务端代码 1.Service接口类 package com.test.hello; import java.util.Map; import javax.jws.WebService; imp ...
- (二)CXF之用CXF官方工具生成客户端Client
一.CXF工具的下载与使用 登录CXF官网:http://cxf.apache.org/download.html 下载,本系列使用的是3.1.5版本: 添加path环境变量 二.案例 2.1 发布w ...
- css笔记02:选择器(标签式和类)
body { margin:; padding:; background:#000 url('images/backgrounds/star.png') no-repeat fixed; font: ...
随机推荐
- Android学习开发中如何保持API的兼容
Android学习开发中如何保持API的兼容: 1,采用良好的设计思路 在设计过程中,如果能按照下面的方式来进行设计,会让这个API生命更长久 面向用例的设计,收集用户建议,把自己模拟成用户,保证AP ...
- NLP+词法系列(一)︱中文分词技术小结、几大分词引擎的介绍与比较
笔者想说:觉得英文与中文分词有很大的区别,毕竟中文的表达方式跟英语有很大区别,而且语言组合形式丰富,如果把国外的内容强行搬过来用,不一样是最好的.所以这边看到有几家大牛都在中文分词以及NLP上越走越远 ...
- 在U-boot中添加以太网驱动
当定义CONFIG_CMD_NET和CONFIG_CMD_PING,编译之后执行ping命令,告警没有找到以太网. 因此,需要打开U-boot的网络功能, u-boot-sunxi-sunxi中没有找 ...
- 解决MyEclipse中的Building workspace问题
解决MyEclipse中的Building workspace问题 1.方法一 点击"Project",取消勾选"Build Automatically" 2. ...
- 利用PowerDesigner15在win7系统下对MySQL 进行反向工程(三)
利用PowerDesigner15在win7系统下对MySQL 进行反向工程 1.选择"数据库-->Generate Database...",查看数据库表的SQL语句 2. ...
- MyEclipse10+Flash Builder4+BlazeDS+Tomcat7配置J2EE Web项目报错(一)
1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...
- Linux命令之finger
Linux命令之finger youhaidong@youhaidong-ThinkPad-Edge-E545:~$ finger 程序"finger"尚未安装. 您可以使用以下命 ...
- Flex中对表格中某列的值进行数字格式化并求百分比
1.问题背景 一般的,需要对表格中某列的数值进行格式化,对该数值乘以100,并保留两位小数,添加"%" 2.实现实例 <?xml version="1.0" ...
- hibernate学习(一)配置,导包
框架的作用 学过javaWeb基础的已经对web层 jsp servlet ,service 层 ,dao层的jdbc .DBUtils 有了很深的了解 并编写代码实现某种功能 为了提高开发 ...
- java实现在线支付
国内电子商务系统实现的基本流程如下: 客户在系统内下订单 -> 系统根据订单生成支付宝接口url -> 客户通过url使用支付宝(网上银行)付款 -> 支付宝将客户的付款完成信息发送 ...