java - 获取 403 : Forbidden when consuming SOAP service using apache cxf in java

标签 java apache soap cxf

在尝试使用 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/

相关文章:

php - 强制域在不同的 UID 下运行 apache 在 SSL 下中断

php - 空查询附加到主 URL .htaccess 问题

c# - 将自定义命名空间添加到 WCF 中的 soap 信封

java - 当我尝试创建 Web 服务时,未发现类错误的序列化程序

java - 在 Spring WebFlux 中进行异步 SOAP 调用

java - 如何将十六进制字符串直接转换为字节数组?

java - 使用 Java 读取 XML

Java 可自定义嵌套 for 循环的数量

sleep - sleep 的目的是什么(long millis,int nanos)?

svn - 不同路径的 Apache