如何在服务器端的CXF Web服务中禁用组块? [英] How to disable chunking in cxf webservice on server-side?

查看:110
本文介绍了如何在服务器端的CXF Web服务中禁用组块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些客户端需要 Content-Length标头作为响应,因此我需要在服务器端的cxf Web服务中禁用分块。现在,我可以看到服务器响应中的 Transfer-Encoding为块状,并且未发送 Content-Length标头。

I need to disable chunking in cxf webservice on server-side as some clients need 'Content-Length' header in response. Now i can see 'Transfer-Encoding' is 'chunked' in server response and no 'Content-Length' header is sent.

我发现可以将chunkins设置为在春天这样的环境中被禁用:

I've found that chunkins can be disabled in spring's context like this:

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

由于我正在以编程方式创建服务,如下所示:

Since i'm creating services programmatically like this:

// 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!据我了解,您有一个客户,他们的客户无法修改其代码以停用分块功能?

Actually, you can't easyly specified to not allow chuncking from server side. Indeed, it's a client pb! What I understand is that you have a client of your ws who can't modify his code to desactivate chunking?

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

You have to do that : write a CXF interceptor that would replace the servlets OutputStream in the message with a buffer of some sort (ByteArrayOutputStream or CachedOutputStream) at the beginning of the output chain and then at the end of the chain, use that to set the Content-Length header on the response and copy that data to the real output stream. Indeed, the content lenght will force the framework to not use the chunking.

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

I did it once before. I'll try to post you maybe tomorrow a code of such interceptor.

这篇关于如何在服务器端的CXF Web服务中禁用组块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆