zoukankan      html  css  js  c++  java
  • 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 是复杂自定义类型。

        

    结束

  • 相关阅读:
    Windows各系统关闭更新(winXP/win2003/win7/win8/win2012/win10)
    SSH框架搭建与整合
    Servlet转发和重定向response.sendRedirecte()区别 (转)
    el 表达式用法(转)
    数组和集合(collection)调用syso输出时,结果不一致问题
    Java 接口和抽象类可以被new么?
    Dbutils
    dbutils使用---QueryRunner(query_update)、BeanListBeanHandler、MapListMapHandler、ScalarHandler
    Hadoop参数:fs.defaultFS、 dfs.name.dir 、 dfs.data.dir
    工厂设计模式(三种)详解
  • 原文地址:https://www.cnblogs.com/MrChuHello/p/webservice.html
Copyright © 2011-2022 走看看