【问题标题】:Getting 403: Forbidden when consuming SOAP service using apache cxf in java获取 403:在 java 中使用 apache cxf 使用 SOAP 服务时被禁止
【发布时间】:2016-07-12 11:28:52
【问题描述】:

在尝试使用 apache cxf 3.1.6 和 java 8 使用 SOAP 服务时,通过更改有效负载内容,我得到“200 OK”或“403 Forbidden”。

奇怪的是,如果我打印出有效负载并安装 SOAPUI,那么我总是得到 200 OK。

您是否遇到过类似的问题?如何解决?

【问题讨论】:

  • 表示连接不上端点,可能没有激活。

标签: java apache soap cxf


【解决方案1】:

所以你不会像我一样被困几天,摸不着头脑,思考到底为什么会发生这种情况,这里是问题的解释和解决方案。

出现问题是因为默认情况下 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 2021-08-13
    • 2012-06-28
    • 2016-07-21
    • 2013-11-13
    相关资源
    最近更新 更多