Jersey client.setChunkedEncodingSize(null) not working

百般思念 提交于 2019-12-11 07:43:27

问题


I am writing one client to measure Jersey, REST based web service performance. I have written some code to measure response time and to measure number of bytes sent from the server but response.getLength() method always returning -1.

In many QA forum I read that setting client.setChunkedEncodingSize(null) will work but even after setting this, I am getting -1.

From server side, I am sending response of type XML or JSON or protobuf depending upon parameters sent by client. For all of these response types, I am getting response length as -1.

My actual request looks like below:

WebResource webResourceQuery = client.resource(requestUrl);
ClientResponse response = webResourceQuery.header("Authorization", header)
                                          .accept(MediaType.APPLICATION_JSON)
                                          .get(ClientResponse.class);

From server side, I am not setting content-length explicitly. Can anyone please help me in getting content-length on client side?

Whole purpose of this experiment is to measure which response type is more efficient in terms of response time and amount of data sent/received.


回答1:


I ran in to the same problem: client.setChunkedEncodingSize(null); does not work.

This worked for me to actually disable chunked encoding:

client.getProperties().put(ApacheHttpClient4Config.PROPERTY_ENABLE_BUFFERING, true);


来源:https://stackoverflow.com/questions/25240253/jersey-client-setchunkedencodingsizenull-not-working

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