How to disable chunking in cxf webservice on server-side?

社会主义新天地 提交于 2019-12-21 20:39:44

问题


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.

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");

How can i do it?


回答1:


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?

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.



来源:https://stackoverflow.com/questions/31338504/how-to-disable-chunking-in-cxf-webservice-on-server-side

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!