Java SOAP 消息不得包含文档类型声明 (DTD)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20549680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:43:01  来源:igfitidea点击:

SOAP message MUST NOT contain a Document Type Declaration(DTD)

javaweb-servicestomcatsoapaxis2

提问by Asiri Liyana Arachchi

I'm trying to understand ws-security signing and encryption. I've followed thisguide. As mentioned I've Installed rampart, have created the relevant *.aarfile successfully and deployed it in the tomcat servlet engine, added the org.bouncycastle.jce.provider.BouncyCastleProviderBouncy Castle security provider (necessary for the public-key cryptography features used in the example code) to JVM security configuration (the lib/security/java.securityfile), added the Bouncy Castle JAR to both Axis2 installation's lib directory and Axis2 server application's WEB-INF/libdirectory. (Which is the setup to run the given sample) But when running the example described, I am getting the following errors

我正在尝试了解 ws-security 签名和加密。我遵循了指南。如前所述,我已经安装了壁垒,*.aar成功创建了相关文件并将其部署在 tomcat servlet 引擎中,将org.bouncycastle.jce.provider.BouncyCastleProviderBouncy Castle 安全提供程序(示例代码中使用的公钥加密功能所必需)添加到 JVM 安全配置(lib/security/java.security文件),将 Bouncy Castle JAR 添加到 Axis2 安装的 lib 目录和 Axis2 服务器应用程序的WEB-INF/lib目录。(这是运行给定示例的设置)但是在运行所描述的示例时,我收到以下错误

 [java] Connecting to http://localhost:8080/axis2/services/library-signencr
 [java] Exception in thread "main" org.apache.axis2.AxisFault: SOAP message MUST NOT contain a Document Type Declaration(DTD)
 [java]     at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
 [java]     at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123)
 [java]     at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
 [java]     at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
 [java]     at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
 [java]     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
 [java]     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
 [java]     at com.sosnoski.ws.library.adb.LibrarySignencrStub.getBook(LibrarySignencrStub.java:205)
 [java]     at com.sosnoski.ws.library.adb.WebServiceClient.main(WebServiceClient.java:83)
 [java] Caused by: org.apache.axiom.om.OMException: SOAP message MUST NOT contain a Document Type Declaration(DTD)
 [java]     at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.createDTD(StAXSOAPModelBuilder.java:455)
 [java]     at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:282)
 [java]     at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:198)
 [java]     at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
 [java]     at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:140)
 [java]     at org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:686)
 [java]     at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:197)
 [java]     at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145)
 [java]     at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108)
 [java]     ... 7 more
 [java] Java Result: 1

How could I resolve this issue?

我该如何解决这个问题?

回答by Shil Nevado

I had the same problem with a webservice that has always worked but yesterday. That problem went out because in the code we wait an xml response but it gave an html error page. So the DOCUMENT TYPE (html page) was not what we expected in the code. And all of this happened because the server moved away!

我在昨天一直有效的网络服务上遇到了同样的问题。这个问题解决了,因为在代码中我们等待一个 xml 响应,但它给出了一个 html 错误页面。所以文档类型(html 页面)不是我们在代码中所期望的。而这一切都是因为服务器搬走了!

Sorry for answer so late, but I hope my answer will help another person in the future ^-^

很抱歉这么晚才回答,但我希望我的回答将来能帮助另一个人^-^