在尝试使用 apache cxf 3.1.6 和 java 8 使用 SOAP 服务时,通过更改负载内容,我得到“200 OK”或“403 Forbidden”。
奇怪的是,如果我打印出有效载荷并使用 SOAPUI,那么我总是得到 200 OK。
你遇到过类似的问题吗?如何解决?
最佳答案
所以您不会像我一样被困几天,挠头思考为什么会发生这种情况,这里是问题的解释和解决方案。
问题的发生是因为默认情况下 apach cxf 使用“分块”,一旦达到定义的阈值,它基本上会将小块数据发送到端点。这会导致 SOAP 消息在未完成的情况下被发送,从而导致“403”(假设服务器不支持“分块”)!解决方案是通过将 spring-config.xml 更改为以下内容来禁用“分块”:
<http-conf:conduit name="*.http-conduit">
<http-conf:client Connection="Keep-Alive"
MaxRetransmits="1"
AllowChunking="false" />
附加信息:
在 org.apache.cxf.transport.http.HTTPConduit 上,对于“准备”方法,这一点解释了所有内容:
// DELETE does not work and empty PUTs cause misleading exceptions
// if chunking is enabled
// TODO : ensure chunking can be enabled for non-empty PUTs - if requested
if (csPolicy.isAllowChunking()
&& isChunkingSupported(message, httpRequestMethod)) {
//TODO: The chunking mode be configured or at least some
// documented client constant.
//use -1 and allow the URL connection to pick a default value
isChunking = true;
chunkThreshold = csPolicy.getChunkingThreshold();
}
cookies.writeToMessageHeaders(message);
关于java - 获取 403 : Forbidden when consuming SOAP service using apache cxf in java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38327625/