gpt4 book ai didi

java - Prolog SAXParserException 中不允许内容

转载 作者:IT老高 更新时间:2023-10-28 20:41:23 26 4
gpt4 key购买 nike

我正在尝试调用 Web 服务,但遇到了奇怪的行为。我们在我的服务器上运行了一个网络服务,但是代码不对我们开放,所以看不到墙后面发生了什么该服务的所有者公开了基于 Web 的测试客户端 UI,该 UI 在文本框中接受输入,并将显示对测试目的的响应。此输入框以下面提到的格式接受输入

<CONTENT>
<CONTENTID></CONTENTID>
<DOCUMENTID>DRI2</DOCUMENTID>
<LOCALECODE>en_US</LOCALECODE>
<LATEST_VERSION>false</LATEST_VERSION>
<INCREASEVIEWCOUNT>false</INCREASEVIEWCOUNT>
<ACTIVITY_TYPE></ACTIVITY_TYPE>
</CONTENT>

它在这个 UI 上工作正常,但是当我试图通过我的 java 代码调用这个 Web 服务时,它得到连接以及得到服务的授权,但是当我试图调用上述方法时,它给了我以下错误消息

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXParseException: Content is not allowed in prolog.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
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.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
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)
at com.inquira.imwows.generated.ContentServicesSoapBindingStub.getContentRecord(ContentServicesSoapBindingStub.java:262)
at com.inquira.prep.GetWebService.getcontentRecord(GetWebService.java:87)
at com.inquira.prep.TestWs.main(TestWs.java:13)

{http://xml.apache.org/axis/}hostname:umeshawasthi

org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
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)
at com.inquira.imwows.generated.ContentServicesSoapBindingStub.getContentRecord(ContentServicesSoapBindingStub.java:262)
at com.inquira.prep.GetWebService.getcontentRecord(GetWebService.java:87)
at com.inquira.prep.TestWs.main(TestWs.java:13)
Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLScanner.reportFatalError(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
... 11 more

下面是生成所需 XML 的代码

inputXml.append("<CONTENT>");
inputXml.append("<CONTENTID>").append("</CONTENTID>");
inputXml.append("<DOCUMENTID>").append("DRI2").append("</DOCUMENTID>");
inputXml.append("<LOCALECODE>").append("en_US").append("</LOCALECODE>");
inputXml.append("<LATEST_VERSION>").append("false").append("</LATEST_VERSION>");
inputXml.append("<INCREASEVIEWCOUNT>").append("false").append("</INCREASEVIEWCOUNT>");
inputXml.append("<ACTIVITY_TYPE>").append("</ACTIVITY_TYPE>");
inputXml.append("</CONTENT>");

生成的XML如下

<CONTENT><CONTENTID></CONTENTID><DOCUMENTID>DRI2</DOCUMENTID><LOCALECODE>en_US</LOCALECODE><LATEST_VERSION>false</LATEST_VERSION><INCREASEVIEWCOUNT>false</INCREASEVIEWCOUNT><ACTIVITY_TYPE></ACTIVITY_TYPE></CONTENT>

我什至对生成的字符串进行了计时,如下所示

inputXml.toString().trim().replaceFirst("^([\\W]+)<","<");

但无法找出问题所在,我确信输入 XML 中存在一些问题,因为它在相同 XML 的测试页面 UI 上工作发现

在这方面的任何帮助都非常有用

最佳答案

此错误可能与实际 XML 内容之前的字节顺序标记 (BOM) 有关。您需要解析返回的 String 并丢弃 BOM,这样 SAXParser 才能正确处理文档。

你会找到一个可能的解决方案here .

关于java - Prolog SAXParserException 中不允许内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4569123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com