javax.ws.rs.client.Client, как настроить readTimeOut?
Переход от com.sun.jersey.api.client.Client к javax.ws.rs.client.Client, как мне настроить Client?
ОТ:
import com.sun.jersey.api.client.Client;
Client client = Client.create();
client.setReadTimeout(1000 * 60 * 20);
client.setConnectTimeout(1000 * 20);
webResource = client.resource("someWhereOverTheRainbow");
..etc.
TO:
import javax.ws.rs.client.*;
Client client = ClientBuilder.newClient();
// **now what?** client.getConfiguration().getProperties().put("isThisTheWayToDoIt", 1000 * 60 * 2);
WebTarget target = client.target("someWhereOverTheRainbow");
..etc.
Я использую javax.ws.rs-api-2.0.jar
1 ответ
Я предполагаю, что вы используете jax-rs-ri. Для этого вы можете использовать ClientProperties.CONNECT_TIMEOUT
а также ClientProperties.READ_TIMEOUT
,
Пример:
ClientConfig configuration = new ClientConfig();
configuration = configuration.property(ClientProperties.CONNECT_TIMEOUT, 1000);
configuration = configuration.property(ClientProperties.READ_TIMEOUT, 1000);
Client client = ClientBuilder.newClient(configuration);
WebTarget target = client.target(
"http://developer.github.com/v3/");
String content = target.request().get(String.class);
System.out.println(content);
РЕДАКТИРОВАТЬ:
Я прочитал документ API для ClientConfig.property. И @Gili прав.