xfire中对集合的配置
来源:互联网 发布:中译俄在线翻译软件 编辑:程序博客网 时间:2024/05/19 12:25
对xfire的各种方法映射和集合映射做一个总结,jar包就是xfire下面的所有。
User类:
- package org.forever.entity;
- import java.io.Serializable;
- public class User implements Serializable {
- private static final long serialVersionUID = 1668097150623622102L;
- private Integer id;
- private String username;
- private String password;
- public User() {
- }
- public User(Integer id, String username, String password) {
- super();
- this.id = id;
- this.username = username;
- this.password = password;
- }
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- public String getUsername() {
- return username;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- }
package org.forever.entity;import java.io.Serializable;public class User implements Serializable {private static final long serialVersionUID = 1668097150623622102L;private Integer id;private String username;private String password;public User() {}public User(Integer id, String username, String password) {super();this.id = id;this.username = username;this.password = password;}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}
PageInfo类:
- package org.forever.entity;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- /**
- * 说明各种集合类型的映射
- *
- * @author Administrator
- *
- */
- public class PageInfo {
- private int pageIndex = 0;
- private List<User> list = new ArrayList<User>();
- private Set<User> set = new HashSet<User>();
- private Map<String, User> map = new HashMap<String, User>();
- private User user = new User();
- public PageInfo() {
- }
- public int getPageIndex() {
- return pageIndex;
- }
- public void setPageIndex(int pageIndex) {
- this.pageIndex = pageIndex;
- }
- public List<User> getList() {
- return list;
- }
- public void setList(List<User> list) {
- this.list = list;
- }
- public Set<User> getSet() {
- return set;
- }
- public void setSet(Set<User> set) {
- this.set = set;
- }
- public Map<String, User> getMap() {
- return map;
- }
- public void setMap(Map<String, User> map) {
- this.map = map;
- }
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
- }
package org.forever.entity;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.Set;/** * 说明各种集合类型的映射 * * @author Administrator * */public class PageInfo {private int pageIndex = 0;private List<User> list = new ArrayList<User>();private Set<User> set = new HashSet<User>();private Map<String, User> map = new HashMap<String, User>();private User user = new User();public PageInfo() {}public int getPageIndex() {return pageIndex;}public void setPageIndex(int pageIndex) {this.pageIndex = pageIndex;}public List<User> getList() {return list;}public void setList(List<User> list) {this.list = list;}public Set<User> getSet() {return set;}public void setSet(Set<User> set) {this.set = set;}public Map<String, User> getMap() {return map;}public void setMap(Map<String, User> map) {this.map = map;}public User getUser() {return user;}public void setUser(User user) {this.user = user;}}
PageInfo.aegis.xml映射配置文件:
- <?xml version="1.0" encoding="UTF-8"?>
- <mappings xmlns:my="http://my.bjvsp.tongtech.com">
- <mapping name="PageInfo">
- <property name="list"
- componentType="org.forever.entity.User" />
- </mapping>
- <mapping name="PageInfo">
- <property name="set" componentType="org.forever.entity.User"></property>
- </mapping>
- <mapping name="PageInfo">
- <property name="map" keyType="java.lang.String" componentType="org.forever.entity.User"></property>
- </mapping>
- </mappings>
<?xml version="1.0" encoding="UTF-8"?><mappings xmlns:my="http://my.bjvsp.tongtech.com"><mapping name="PageInfo"><property name="list"componentType="org.forever.entity.User" /></mapping><mapping name="PageInfo"><property name="set" componentType="org.forever.entity.User"></property></mapping><mapping name="PageInfo"><property name="map" keyType="java.lang.String" componentType="org.forever.entity.User"></property></mapping></mappings>
接口IHelloService.java:
- package org.forever.webservice;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import org.forever.entity.PageInfo;
- import org.forever.entity.User;
- public interface IHelloService {
- public String sayHello(String content);
- public User get(User user);
- public List getAll(List list);
- public PageInfo getPage(User user,List list,Set set,Map map);
- }
package org.forever.webservice;import java.util.List;import java.util.Map;import java.util.Set;import org.forever.entity.PageInfo;import org.forever.entity.User;public interface IHelloService {public String sayHello(String content);public User get(User user);public List getAll(List list);public PageInfo getPage(User user,List list,Set set,Map map);}
接口实现:
- package org.forever.webservice.impl;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import org.forever.entity.PageInfo;
- import org.forever.entity.User;
- import org.forever.webservice.IHelloService;
- public class HelloServiceImpl implements IHelloService {
- public User get(User user) {
- System.out.println("HelloServiceImpl.get(user);");
- user.setUsername("sotry");
- return user;
- }
- public List getAll(List list) {
- System.out.println("HelloServiceImpl.getAll(List list);");
- list.add(new User(88, "唐平", "admin"));
- list.add(new User(99, "王维", "forever"));
- return list;
- }
- public String sayHello(String content) {
- System.out.println("HelloServiceImpl.sayHello(String content);");
- return content+"哦也";
- }
- public PageInfo getPage(User user, List list, Set set, Map map) {
- System.out.println("HelloServiceImpl.getPage()");
- user.setUsername("webService update username");
- list.add(new User(3, "admin", "admin"));
- set.add(new User(3, "admin", "admin"));
- map.put("key", new User(3, "admin", "admin"));
- PageInfo pageInfo = new PageInfo();
- pageInfo.setList(list);
- pageInfo.setSet(set);
- pageInfo.setMap(map);
- pageInfo.setUser(user);
- return pageInfo;
- }
- }
package org.forever.webservice.impl;import java.util.List;import java.util.Map;import java.util.Set;import org.forever.entity.PageInfo;import org.forever.entity.User;import org.forever.webservice.IHelloService;public class HelloServiceImpl implements IHelloService {public User get(User user) {System.out.println("HelloServiceImpl.get(user);");user.setUsername("sotry");return user;}public List getAll(List list) {System.out.println("HelloServiceImpl.getAll(List list);");list.add(new User(88, "唐平", "admin"));list.add(new User(99, "王维", "forever"));return list;}public String sayHello(String content) {System.out.println("HelloServiceImpl.sayHello(String content);");return content+"哦也";}public PageInfo getPage(User user, List list, Set set, Map map) {System.out.println("HelloServiceImpl.getPage()");user.setUsername("webService update username");list.add(new User(3, "admin", "admin"));set.add(new User(3, "admin", "admin"));map.put("key", new User(3, "admin", "admin"));PageInfo pageInfo = new PageInfo();pageInfo.setList(list);pageInfo.setSet(set);pageInfo.setMap(map);pageInfo.setUser(user);return pageInfo;}}
IHelloService.aegis.xml映射:
- <mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xfire.codehaus.org/schemas/1.0/mapping.xsd">
- <mapping>
- <method name="getAll">
- <parameter index="0" componentType="org.forever.entity.User"/>
- <return-type mappedName="userList" componentType="org.forever.entity.User" />
- </method>
- <method name="getPage">
- <parameter index="1" componentType="org.forever.entity.User"/>
- <parameter index="2" componentType="org.forever.entity.User"/>
- <!-- map映射失败 -->
- <parameter index="3" mappedName="userMap" keyType="java.lang.String" componentType="org.forever.entity.User"/>
- <return-type componentType="org.forever.entity.PageInfo" />
- </method>
- </mapping>
- </mappings>
<mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xfire.codehaus.org/schemas/1.0/mapping.xsd"> <mapping> <method name="getAll"> <parameter index="0" componentType="org.forever.entity.User"/> <return-type mappedName="userList" componentType="org.forever.entity.User" /> </method> <method name="getPage"> <parameter index="1" componentType="org.forever.entity.User"/> <parameter index="2" componentType="org.forever.entity.User"/> <!-- map映射失败 --> <parameter index="3" mappedName="userMap" keyType="java.lang.String" componentType="org.forever.entity.User"/> <return-type componentType="org.forever.entity.PageInfo" /> </method> </mapping> </mappings>
IHelloService.doc.xml应该可以不用写吧:
- <service>
- <documentation>
- Service which allows to search for books
- </documentation>
- <method name="get" parametersNumber="1" >
- <documentation>
- 根据所给的用户,填充名字
- </documentation>
- <parameter index="0">
- <documentation>
- 用户实体
- </documentation>
- </parameter>
- <return>
- <documentation>
- 带名字的实体
- </documentation>
- </return>
- </method>
- <method name="getAll" parametersNumber="1" >
- <documentation>
- 继续将传递过来的list进行填充
- </documentation>
- <parameter index="0">
- <documentation>
- 用户集合
- </documentation>
- </parameter>
- <return>
- <documentation>
- 用户集合
- </documentation>
- </return>
- </method>
- </service>
<service> <documentation> Service which allows to search for books </documentation> <method name="get" parametersNumber="1" > <documentation> 根据所给的用户,填充名字 </documentation> <parameter index="0"> <documentation> 用户实体 </documentation> </parameter> <return> <documentation> 带名字的实体 </documentation> </return> </method> <method name="getAll" parametersNumber="1" > <documentation> 继续将传递过来的list进行填充 </documentation> <parameter index="0"> <documentation> 用户集合 </documentation> </parameter> <return> <documentation> 用户集合 </documentation> </return> </method> </service>
客户端代码HelloClient类:
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import org.codehaus.xfire.client.Client;
- import org.codehaus.xfire.client.XFireProxyFactory;
- import org.codehaus.xfire.service.Service;
- import org.codehaus.xfire.service.binding.ObjectServiceFactory;
- import org.forever.entity.PageInfo;
- import org.forever.entity.User;
- import org.forever.webservice.IHelloService;
- public class HelloClient {
- public static void main(String[] args) {
- //创建服务
- Service service = new ObjectServiceFactory().create(IHelloService.class);
- //创建代理工厂
- XFireProxyFactory fireProxyFactory = new XFireProxyFactory();
- //服务地址
- try {
- IHelloService helloService = (IHelloService) fireProxyFactory.create(service, "http://127.0.0.1:8080/WebService/services/helloService");
- System.out.println(helloService.sayHello("我是神话"));
- User user = new User(1,"wrwr","wrwrwr");
- helloService.get(user);
- System.out.println(user.getUsername());
- List<User> users = new ArrayList<User>();
- users.add(new User(1,"wrwr","wrwrwr"));
- users.add(new User(1,"wrwr","wrwrwr"));
- users = helloService.getAll(users);
- System.out.println(users.size());
- System.out.println("***************************");
- PageInfo pageInfo = helloService.getPage(new User(), new ArrayList(),new HashSet<User>(),new HashMap<String, User>());
- System.out.println("客户端交互完成");
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- System.out.println("使用client交互:");
- Object[] results;
- try {
- Client client = new Client(new URL(
- "http://127.0.0.1:8080/WebService/services/helloService?wsdl"));
- results = client
- .invoke("sayHello", new Object[] {"我来了哈"});
- System.out.println(results[0]);
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
import java.net.MalformedURLException;import java.net.URL;import java.util.ArrayList;import java.util.HashMap;import java.util.HashSet;import java.util.List;import org.codehaus.xfire.client.Client;import org.codehaus.xfire.client.XFireProxyFactory;import org.codehaus.xfire.service.Service;import org.codehaus.xfire.service.binding.ObjectServiceFactory;import org.forever.entity.PageInfo;import org.forever.entity.User;import org.forever.webservice.IHelloService;public class HelloClient {public static void main(String[] args) {//创建服务Service service = new ObjectServiceFactory().create(IHelloService.class);//创建代理工厂XFireProxyFactory fireProxyFactory = new XFireProxyFactory();//服务地址try {IHelloService helloService = (IHelloService) fireProxyFactory.create(service, "http://127.0.0.1:8080/WebService/services/helloService");System.out.println(helloService.sayHello("我是神话"));User user = new User(1,"wrwr","wrwrwr");helloService.get(user);System.out.println(user.getUsername());List<User> users = new ArrayList<User>();users.add(new User(1,"wrwr","wrwrwr"));users.add(new User(1,"wrwr","wrwrwr"));users = helloService.getAll(users);System.out.println(users.size());System.out.println("***************************");PageInfo pageInfo = helloService.getPage(new User(), new ArrayList(),new HashSet<User>(),new HashMap<String, User>());System.out.println("客户端交互完成");} catch (MalformedURLException e) {e.printStackTrace();}System.out.println("使用client交互:");Object[] results;try {Client client = new Client(new URL("http://127.0.0.1:8080/WebService/services/helloService?wsdl"));results = client .invoke("sayHello", new Object[] {"我来了哈"});System.out.println(results[0]);} catch (MalformedURLException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();}}}
在运行客户端代码一定要引入业务接口的包,如果在一个项目里面就可以省略。
- xfire中对集合的配置
- xfire 里的集合Mapping
- 在java中使用xfire实现webservice的配置
- XFire的应用:1、配置
- struts2 配置json格式数据( includeProperties中对list集合的正则配置)
- XFire对其配置文件的解析方式
- xfire配置
- 对Java中常用集合的操作
- java中对集合List的操作
- C#中对List集合的理解
- XFire的Web Service服务器端快速配置
- XFire的Web Servicep客户端快速配置
- Xfire的aegis绑定方式配置小结
- Xfire的aegis绑定方式配置
- Xfire的aegis绑定方式配置小结
- Xfire的aegis绑定方式配置小结
- XFire的Web Service服务器端快速配置
- Xfire的aegis绑定方式配置
- 聊移动互联网 别老拿手机游戏说事!
- 利用sub main ()对窗体启动控制,以及unload 和end结束窗体
- htmL 学习网站
- C# 冒泡排序
- 谁是HTML5新规则下的牺牲品?
- xfire中对集合的配置
- Excel技巧--F5
- REST接口POST方法发送文件到服务器(C#)
- 京东商城暂停所有地铁自提点:或因租金成本高
- SQL Server 2008连接字符串写法大全
- Convert、Parse、TryParse、(int)等区别
- .Net+EF连接Oracle 10、11 开发,ODAC安装配置与使用详解
- UML简介
- Linux下Bluetooth编程