JerseyClient属性()返回null

时间:2018-04-06 17:41:51

标签: java jersey jax-rs

我使用的是Jersey 2.25。

我尝试将connectTimeoutreadTimeout设置为客户端,但它返回null而不是Client实例。我是通过ClientBuilder.build()创建客户端的。

ClientBuilder builder = ClientBuilder.newBuilder();
    builder.sslContext(createSSLContext());
    Client client = builder.build();
    client = client.property("jersey.config.client.connectTimeout", 100); //returns null
    client = client.property("jersey.config.client.readTimeout", 100); //returns null

有没有理由期望property()返回null?怎么可能修好?

1 个答案:

答案 0 :(得分:3)

您无需重新分配client实例,只需调用从builder.build()返回的同一实例上的方法:

Client client = builder.build();
client.property(ClientProperties.CONNECT_TIMEOUT, 100);
client.property(ClientProperties.READ_TIMEOUT, 100);
...