How to disable chunking in cxf-jaxrs client

喜欢而已 提交于 2019-12-13 04:43:08

问题


I need to contact a proprietary http service, not supporting chunks. I started using as documented here so i create the client this way:

Client client = ClientBuilder.newBuilder().newClient();
WebTarget target = client.target("http://localhost:8080/rs");

The problem is how to configure the client, how to disable chunking. The way documented here doesn't work for me (wrong classes).

Thanks in advance


回答1:


Rather that using jaxrs standard Client you can use org.apache.cxf.jaxrs.client.WebClient part of cxf-rt-rs-client dependency.

WebClient client = WebClient.create("http://localhost:8080/rs");
WebClient.getConfig(client).getHttpConduit().getClient().setAllowChunking(false);



回答2:


If you'd like to continue to use the ClientBuilder etc, you can do this instead:

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import org.apache.cxf.jaxrs.client.WebClient;

Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target("https://www.example.com/");
target.request(); /* Must call this first to initialise the client in the target */
WebClient.getConfig(target).getHttpConduit().getClient().setAllowChunking(false);


来源:https://stackoverflow.com/questions/27315339/how-to-disable-chunking-in-cxf-jaxrs-client

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