WebService--xfire中对集合的配置和操作_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > WebService--xfire中对集合的配置和操作

WebService--xfire中对集合的配置和操作

 2012/4/24 17:13:39  fhuan123  程序员俱乐部  我要评论(0)
  • 摘要:xfire下载URL:http://xfire.codehaus.org/Download对xfire的各种方法映射和集合映射做一个总结,jar包就是xfire下面的所有。User类:packageorg.forever.entity;importjava.io.Serializable;publicclassUserimplementsSerializable{privatestaticfinallongserialVersionUID=1668097150623622102L
  • 标签:Web Service 配置 Webservice 操作

xfire下载URL:

http://xfire.codehaus.org/Download

?

对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;
	}

}

?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;
	}

}

?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>

?接口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.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映射:注意要想此文件和IHelloService类放入同一个包中!

<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>   

?客户端代码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();
		}
		
		
		
	}
}

?在运行客户端代码一定要引入业务接口的包,如果在一个项目里面就可以省略。

  • XFireZhuweiTest.zip (27.1 KB)
  • 下载次数: 0
发表评论
用户名: 匿名