客户端使用AXIS的CALL调用
二、遇到的问题
?
客户端传送String类型的XML内容的时候服务器段接受会遇到需要处理(目的是要传送XML格式的数据)
?
三、xml、OMElement、java对象之间转换
- import?java.io.ByteArrayInputStream;??
- ??
- import?org.apache.axiom.om.OMElement;??
- import?org.apache.axiom.om.impl.builder.StAXOMBuilder;??
- import?org.apache.axis2.databinding.utils.BeanUtil;??
- import?org.apache.axis2.engine.DefaultObjectSupplier;??
- import?org.dom4j.Document;??
- import?org.dom4j.DocumentHelper;??
- ??
- public?class?XMLUtil??
- {??
- ??????
- ????@SuppressWarnings("unchecked")??
- ????public?static??T?xmlToBean(String?xml,?Class?cls)??
- ????{??
- ????????T?object?=?null;??
- ????????try??
- ????????{??
- ????????????OMElement?omElement?=?new?StAXOMBuilder(new?ByteArrayInputStream(??
- ????????????????????xml.getBytes("UTF-8"))).getDocumentElement();??
- ????????????object?=?(T)?BeanUtil.processObject(omElement,?cls,?null,?true,??
- ????????????????????new?DefaultObjectSupplier());??
- ????????}??
- ????????catch?(Exception?e)??
- ????????{??
- ????????????e.printStackTrace();??
- ????????}??
- ????????return?object;??
- ????}??
- ??????
- ??????
- ????@SuppressWarnings("unchecked")??
- ????public?static??T?xmlToBean(String?xml,?String?elementName,?Class?cls)??
- ????{??
- ????????T?object?=?null;??
- ????????try??
- ????????{??
- ????????????Document?document?=?DocumentHelper.parseText(xml);??
- ????????????String?beanXml?=?document.getRootElement().element("Body").element(??
- ????????????????????elementName).asXML();??
- ????????????OMElement?omElement?=?new?StAXOMBuilder(new?ByteArrayInputStream(??
- ????????????????????beanXml.getBytes("UTF-8"))).getDocumentElement();??
- ??????????????
- ????????????object?=?(T)?BeanUtil.processObject(omElement,?cls,?null,?true,??
- ????????????????????new?DefaultObjectSupplier());??
- ????????}??
- ????????catch?(Exception?e)??
- ????????{??
- ????????????e.printStackTrace();??
- ????????}??
- ????????return?object;??
- ????}??
- } ?