gpt4 book ai didi

web-services - 如何在服务器端的 cxf webservice 中禁用分块?

转载 作者:行者123 更新时间:2023-12-04 04:52:39 27 4
gpt4 key购买 nike

我需要在服务器端的 cxf webservice 中禁用分块,因为一些客户端需要“Content-Length” header 作为响应。现在我可以看到“Transfer-Encoding”在服务器响应中被“分块”并且没有发送“Content-Length” header 。

我发现可以在 spring 的上下文中禁用 chunkins,如下所示:

<http-conf:conduit name="*.http-conduit">
<http-conf:client ReceiveTimeout=“300000“ AllowChunking="false"/>
</http-conf:conduit>

因为我是这样以编程方式创建服务的:

// media service
Object mediaService = new MediaService();
System.out.println("Starting media service #1 ...");
EndpointImpl mediaEP = (EndpointImpl)Endpoint.create(mediaService);
mediaEP.publish("http://localhost:8081/onvif/media_service");

我该怎么做?

最佳答案

实际上,您不能轻易指定不允许从服务器端进行分块。确实是客户端pb!据我了解,您的 ws 客户无法修改其代码以停用分块?

您必须这样做:编写一个 CXF 拦截器,在输出链的开头用某种缓冲区(ByteArrayOutputStream 或 CachedOutputStream)替换消息中的 servlet OutputStream,然后在链的末尾使用在响应中设置 Content-Length header 并将该数据复制到实际输出流。事实上,内容长度将强制框架不使用分块。

我以前做过一次。也许明天我会尝试向您发布此类拦截器的代码。

关于web-services - 如何在服务器端的 cxf webservice 中禁用分块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31338504/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com