我们正在开发Web服务解决方案。 webservice API为我们提供了几个调用,使用它们可以从Client WebService实现中检索SOAP响应。
实施基于AXIS框架。
当我们收到响应时,除了我们面临SAXParseException之外,所有API调用都能正常工作。
当我们尝试使用SOAP UI时,我们会获得针对此特定API的有效响应。但是当我们尝试Java项目时,我们得到了这个SAXParseException。 Java和SOAP UI项目都是使用相同的WSDL文件
创建的请查看下面的堆栈跟踪,并分享您在这里可能出错的拙见。
XML received:
2013-05-14 12:12:20,536 DEBUG http-bio-8080-exec-1 org.apache.axis.transport.http.HTTPSender - -----------------------------------------------
2013-05-14 12:12:20,536 DEBUG http-bio-8080-exec-1 org.apache.axis.SOAPPart - Enter: SOAPPart::getAsSOAPEnvelope()
2013-05-14 12:12:20,536 DEBUG http-bio-8080-exec-1 org.apache.axis.i18n.ProjectResourceBundle - org.apache.axis.i18n.resource::handleGetObject(currForm)
2013-05-14 12:12:20,536 DEBUG http-bio-8080-exec-1 org.apache.axis.SOAPPart - current form is FORM_INPUTSTREAM
2013-05-14 12:12:20,708 DEBUG http-bio-8080-exec-1 org.apache.axis.transport.http.HTTPSender - org.xml.sax.SAXParseException: The root element is required in a well-formed document.
2013-05-14 12:12:20,708 DEBUG http-bio-8080-exec-1 org.apache.axis.SOAPPart - Enter: SOAPPart ctor(FORM_FAULT)
2013-05-14 12:12:20,708 DEBUG http-bio-8080-exec-1 org.apache.axis.i18n.ProjectResourceBundle - org.apache.axis.i18n.resource::handleGetObject(setMsgForm)
2013-05-14 12:12:20,708 DEBUG http-bio-8080-exec-1 org.apache.axis.SOAPPart - Setting current message form to: FORM_FAULT (currentMessage is now org.apache.axis.AxisFault)
2013-05-14 12:12:20,708 DEBUG http-bio-8080-exec-1 org.apache.axis.SOAPPart - Exit: SOAPPart ctor()
2013-05-14 12:12:20,708 DEBUG http-bio-8080-exec-1 org.apache.axis.i18n.ProjectResourceBundle - org.apache.axis.i18n.resource::handleGetObject(toAxisFault00)
2013-05-14 12:12:20,740 DEBUG http-bio-8080-exec-1 org.apache.axis.enterprise - Mapping Exception to AxisFault
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXParseException: The root element is required in a well-formed document.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException: The root element is required in a well-formed document.
at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:1213)
at org.apache.xerces.framework.XMLDocumentScanner.reportFatalXMLError(XMLDocumentScanner.java:570)
at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.endOfInput(XMLDocumentScanner.java:790)
at org.apache.xerces.framework.XMLDocumentScanner.endOfInput(XMLDocumentScanner.java:418)
at org.apache.xerces.validators.common.XMLValidator.sendEndOfInputNotifications(XMLValidator.java:712)
at org.apache.xerces.readers.DefaultEntityHandler.changeReaders(DefaultEntityHandler.java:1031)
at org.apache.xerces.readers.XMLEntityReader.changeReaders(XMLEntityReader.java:168)
at org.apache.xerces.readers.AbstractCharReader.changeReaders(AbstractCharReader.java:150)
at org.apache.xerces.readers.AbstractCharReader.lookingAtChar(AbstractCharReader.java:217)
at org.apache.xerces.framework.XMLDocumentScanner$XMLDeclDispatcher.dispatch(XMLDocumentScanner.java:686)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
答案 0 :(得分:3)
似乎你没有响应的有效xml ......就像那样。
<?xml version="1.0"?>
<node1>
... bla, bla
</node1>
<node2>
... bla, bla
</node2>
<node_x>
... bla, bla
</node_x>
而不是......
<?xml version="1.0"?>
<node1>
<node2>
... bla, bla
</node2>
<node_x>
... bla, bla
</node_x>
</node1>
您应该嗅探网络流量以查看原始格式的内容。如果有人手工构建xml代码而不是使用众所周知的工具,我通常会遇到此错误。