javax.ws.rs.client.Client 如何配置readTimeOut? [英] javax.ws.rs.client.Client how to configure readTimeOut?

查看:61
本文介绍了javax.ws.rs.client.Client 如何配置readTimeOut?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

com.sun.jersey.api.client.Clientjavax.ws.rs.client.Client 我如何配置客户端?

Going from com.sun.jersey.api.client.Client to javax.ws.rs.client.Client how do I configure 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.

致:

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

推荐答案

我假设您正在使用 jax-rs-ri.为此,您可以使用 ClientProperties.CONNECT_TIMEOUTClientProperties.READ_TIMEOUT.

I assume you are using jax-rs-ri. For this, you can use ClientProperties.CONNECT_TIMEOUT and 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);

我阅读了ClientConfig.property.@Gili 是对的.

I read the API document for ClientConfig.property. And @Gili is right.

这篇关于javax.ws.rs.client.Client 如何配置readTimeOut?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆