码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-07-23 19:43:57      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

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 是复杂自定义类型。

技术分享

 

技术分享

    

结束

 

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

标签:

原文地址:http://www.cnblogs.com/MrChuHello/p/webservice.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!