axis2的qname not fond for the package有关问题的解决

axis2的qname not fond for the package问题的解决

June 15, 2011 | 作者:白菜
在一个项目组,需要用到webservice,虽然现有的webservice组件为axis2,比较古老了,不过夜没办法,是个老项目。
不过AXIS2还算好用,就是还是复杂了一些。
在部署webservice的时候,我们可以通过这样的方法来在浏览器中测试
http://aiyooyoo.com/service/getStudentService/listStudent?unit=5
getStudentService为服务名,listStudent为方法名,而unit=5自然就是参数了。
在测试的时候,发现如果是基本类型的话,就能正常运行,但我这次需要的是一个list<student>的集合类型。
在浏览器中报错如下:
qname not fond for the package com.aiyooyoo.com.dbutil
很明显,我的代码里是有这个包的,刚开始怀疑是这种方法有局限性造成的,于是用代码写了个客户端进行测试,问题依然如此。现在就确实确实是返回类型的问题了,如果返回int等基本类型就正常。
查了下资料,发现AXIS2不支持集合,而axis1反倒支持,axis2需要用对象数组的方式来处理,为了已有类的通用性,想到了我可以再服务器端先把集合转换为字符串,再在客户端把字符串转换为集合,不就解决了吗。
于是,主要代码如下:
//集合转字符串
List list<Student>=new arrayList<Student>();
....
return list.toString();
//字符串转集合
JSONArray jsonArray = JSONArray.fromObject(jsonString);
  JSONObject jsonObject;
  Object pojoValue;
  List list = new ArrayList();
  for (int i = 0; i < jsonArray.size(); i++) {
   jsonObject = jsonArray.getJSONObject(i);
   pojoValue = JSONObject.toBean(jsonObject, Student.class);
   list.add(pojoValue);
  }
  return list;
}