作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要在服务器端的 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/
我是一名优秀的程序员,十分优秀!