1

我正在尝试从 java axis2 Web 服务返回一个 XML 文档对象。当我试图在客户端获取 Document 对象时,它给了我这些异常。

org.apache.axis2.AxisFault: org.apache.axis2.AxisFault: Mapping qname not fond for the package: com.sun.org.apache.xerces.internal.dom
    at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
    at com.turnkey.DataCollectorStub.getData(DataCollectorStub.java:194)
    at com.turnkey.TestClient.main(TestClient.java:28)

我不能从 web 服务返回 Document 对象吗?该服务确实返回 XML 字符串。

下面是我正在使用的方法的伪代码

import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public Document getData(args)
    {
     String xmlSource = "/*XML string*/";
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     DocumentBuilder builder = factory.newDocumentBuilder();
     Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlSource)));
     return xmlDoc;
    }

顺便说一句,此方法在服务器端工作正常,但在客户端我无法接收 Document 对象

任何人都可以帮助我。

4

1 回答 1

0

简单的方法不用Document作返回值,因为axis2 在模式中找不到合适的导入。如果每次都生成 wsdl,则应将 import org.w3c.dom.Document 添加到 wsdl 模式(这是一个不方便的解决方案)。这就是为什么在我看来最好的方法返回特定实体

 public Credit[] getCreditList(){
            Credit[] credits = null;
            try {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder documentBuilder = factory.newDocumentBuilder();
                Document xmlDoc = documentBuilder.parse(XML_REAL_PATH);

                Element root = xmlDoc.getDocumentElement();

                List<Credit> creditsList = new ArrayList<>();

            NodeList creditNodes = root.getElementsByTagName(CREDIT);
            int countCreditNodes = creditNodes.getLength();

            for (int i = 0; i < countCreditNodes; i++) {
                Element creditElement = (Element) creditNodes.item(i);

                Credit credit = new Credit();

                Element child = (Element) creditElement.getElementsByTagName(OWNER).item(0);
                String owner = child.getFirstChild().getNodeValue();
                credit.setOwner(owner);

                //...
                creditsList.add(credit);
            }
            credits = creditsList.toArray(new Credit[creditsList.size()]);

        } catch (SAXException | IOException | ParserConfigurationException ex) {
            Logger.getLogger(CreditPayService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return credits;
}
于 2013-02-27T21:50:37.440 回答