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

        

    结束

  • 相关阅读:
    『Python』装饰器
    『Yaml』配置文件读写包
    『Python CoolBook』数据结构和算法_字典比较&字典和集合
    『TensorFlow』滑动平均
    在ASP.NET 5中如何方便的添加前端库
    使用VS把ASP.NET 5的应用发布到Linux的Docker上
    CQRS及.NET中的参考资料
    ASP.NET Identity 3.0教程
    对ASP.NET 5和ASP.NET MVC 6应用程序进行集成测试
    Bootstrap看厌了?试试Metro UI CSS吧
  • 原文地址:https://www.cnblogs.com/MrChuHello/p/webservice.html
Copyright © 2020-2023  润新知