Apache CXF实战之二 传输pojo对象

pojo对象,要有默认构造方法

package com.jing.cxf.vo;

import java.io.Serializable;

public class User implements Serializable{
     
	String name;
	String age;
	String sex;
	public User(){
		
	}
	
	public User(String name,String age,String sex){
		this.name=name;
		this.age=age;
		this.sex=sex;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Override
	public String toString() {
		return "User [name=" + name + ", age=" + age + ", sex=" + sex + "]";
	}
	
	
}

2.service接口

package com.jing.cxf;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.jing.cxf.vo.User;

@WebService  
public interface HelloWorld { 
	
    @WebMethod  
    String sayHi(@WebParam(name="name") String text);  
    
    @WebMethod  
    User getUser(@WebParam(name="username") String username);
      
} 

3.实现类:

package com.jing.cxf;

import com.jing.cxf.vo.User;

public class HelloWorldImpl implements HelloWorld {

	public String sayHi(String name) {  
        String msg = "Hello " + name + "!";  
        System.out.println(">>>>>>>>>>hello"+name);
        return msg;  
    }


	public User getUser(String username) {
		System.out.println(">>>>>>>>>请求的用户是:"+username);
		User user = new User(username,"18","男");
		return user;
	} 

}
4.spring.xml 和web.xml和上一篇一样。

运行test3看效果:

package com.jing.cxf;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.Test;

import com.jing.cxf.vo.User;

/**
 * @author jingguoqiang
 * @desc  org.apache.cxf jar包写的客户端
 */
public class ClientFangWen {
 
	/** 
	* @Description: 测试和spring集成,接口返回的是pojo    
	* @author: jingguoqiang
	* @date 2015-9-19 下午4:20:56 
	*/ 
	@Test
	public void test3() {  
		//jaxws代理工厂
        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();  
        //访问服务类接口 ,注意:必须是接口
        factory.setServiceClass(HelloWorld.class);  
        //访问地址
        factory.setAddress("http://localhost:8081/Zt/ws/HelloWorld"); 
        //得到服务类接口
        HelloWorld helloworld = (HelloWorld) factory.create();  
        User usr = helloworld.getUser("XIAOJING");  
        System.out.println("返回信息:"+usr);
    }  
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值