Axis2Service客户端访问通用类集合List自定义类型

Axis2 服务四种客户端调用方式:

 1.AXIOMClient

 2.generating a client using ADB

 3.generating a client using XMLBeans

 4.generating a client using JiBX

http://axis.apache.org/axis2/java/core/ 官方

搜索了很多资料,没有找到合适的。不论是插件生成还是AXIOMClient使用起来都很麻烦。

service:

public interface TestService {
	public List<Person> findAll();
	public Person getWhere(List<Person> persons);//3.传入集合,返回对象
	public List<Person> getWheres(List<Person> persons);//4.传入集合,返回集合
	public Person getChild(Person p); //1.传入对象,返回对象
	public List<Person> getChildren(Person p);//2.传入对象,返回集合

}

要达成上面的目的应该能够满足大部分场景的使用。那么我们接下在这样做。

client:

1.传入对象,返回对象

 private static  void test01ParameterIsObjectReturnObject()
    {
//客户端调用要简单。传入下面的值就能调用服务方法
        //服务地址,命名空间,方法名,参数
     System.out.println("=====================test01[the parameter is a object and return a object] begin:");
        axis2Context.setFunctionName("getChild");
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("p", CreatePerson());
        axis2Context.setFunctionPrameters(map);
        Person person = Axis2Help.invoke(axis2Context, Person.class);
        System.out.println("the result:" + person.getName());
        System.out.println("=============================================================================end");
    }

 返回结果:

==========================================test01[the parameter is a object and return a object] begin:
the result:张三返回值
=============================================================================end

2.传入对象,返回集合

 private static  void test02ParameterIsObjectReturnList()
    {
        System.out.println("=====================test02[the parameter is a object and return list] begin:");
        axis2Context.setFunctionName("getChildren");
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("p", CreatePerson());
        axis2Context.setFunctionPrameters(map);
        List<Person> persons = Axis2Help.invokeForList(axis2Context, Person.class);
        System.out.println("the result persons.size():" + persons.size() );
        System.out.println("=============================================================================end");
    }

 返回结果:

==========================================test02[the parameter is a object and return list] begin:
the result persons.size():2
=============================================================================end

3.传入集合返回对象

 System.out.println("=====================test03[the parameter is list and return a object] begin:");
        axis2Context.setFunctionName("getWhere");
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("persons", CreatePersonList());
        axis2Context.setFunctionPrameters(map);
        Person person = Axis2Help.invoke(axis2Context, Person.class);
        System.out.println("the result:" + person.getName());
        System.out.println("=============================================================================end");

  返回结果:

=====================test03[the parameter is list and return a object] begin:
the result:张三:返回值
=============================================================================end

4.传入集合返回集合

 private static  void test04ParameterIsListReturnList()
    {
        System.out.println("=====================test04[the parameter is list and return a list] begin:");
        axis2Context.setFunctionName("getWheres");
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("persons", CreatePersonList());
        axis2Context.setFunctionPrameters(map);
        List<Person> persons = Axis2Help.invokeForList(axis2Context, Person.class);
        System.out.println("the result:" + persons.size());
        System.out.println("=============================================================================end");
    }

  返回结果:

==========================================test04[the parameter is list and return a list] begin:
the result:2
=============================================================================end

参数类型:Person 是复杂自定义类型。

 

    

结束

 

转载于:https://www.cnblogs.com/MrChuHello/p/webservice.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值