简体   繁体   English

获取403:在Java中使用apache cxf消费SOAP服务时被禁止

[英]Getting 403: Forbidden when consuming SOAP service using apache cxf in java

While trying to consume a SOAP service using apache cxf 3.1.6 and java 8, by changing the payload content, I am getting either a '200 OK' or '403 Forbidden'. 在尝试使用apache cxf 3.1.6和java 8来使用SOAP服务时,通过更改有效内容,我得到的是“ 200 OK”或“ 403 Forbidden”。

The weird part is, if I print out the payload and put on SOAPUI, then I always get 200 OK. 奇怪的是,如果我打印出有效负载并放上SOAPUI,那么我总是得到200 OK。

Have you encountered a similar issue? 您是否遇到过类似的问题? how to solve this? 如何解决呢?

So you do not get stuck for days like me, scratching the head and thinking why on earth that is happening, here is the issue explained and the solution. 因此,您不会像我这样困扰几天,挠头并思考为什么发生这种情况,这是说明的问题和解决方案。

The issue happens because by default apach cxf uses "Chunking", which basically sends small chunks of data to the endpoint, once the defined threshold is reached. 发生此问题是因为默认情况下,apach cxf使用“ Chunking”,一旦达到定义的阈值,它将基本上将少量数据发送到端点。 That results in SOAP messages being sent while not complete, resulting in a '403' (assuming that the server does not support 'chunking')! 这导致SOAP消息在未完成时被发送,从而导致“ 403”(假设服务器不支持“分块”)! The solution is to disable "Chunking", by changing spring-config.xml to: 解决方案是通过将spring-config.xml更改为:来禁用“ Chunking”。

  <http-conf:conduit name="*.http-conduit">
<http-conf:client Connection="Keep-Alive"
                  MaxRetransmits="1"
                  AllowChunking="false" />

Additional info: 附加信息:

on org.apache.cxf.transport.http.HTTPConduit, for the "prepare" method there is this bit that explains all: 在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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM