How to set the connection and read timeout with Jersey 2.x?(如何使用 Jersey 2.x 设置连接和读取超时?)
问题描述
在球衣 1 中,我们有一个函数 com.sun.jersey.api.client.Client 类中的 .lang.Integer%29" rel="noreferrer">setConnectTimeout.
In jersey 1 we had a function setConnectTimeout in the class com.sun.jersey.api.client.Client.
在 jersey 2 中,javax.ws.rs.client.Client 类用于缺少此功能的地方.
In jersey 2 the javax.ws.rs.client.Client class is used where this function is missing.
jersey 2.x中如何设置连接超时和读取超时?
How to set connection timeout and read timeout in jersey 2.x?
推荐答案
下面的代码在 Jersey 2.3.1 中适用于我(灵感在这里找到:https://stackoverflow.com/a/19541931/1617124)
The code below works for me in Jersey 2.3.1 (inspiration found here: https://stackoverflow.com/a/19541931/1617124)
public static void main(String[] args) {
Client client = ClientBuilder.newClient();
client.property(ClientProperties.CONNECT_TIMEOUT, 1000);
client.property(ClientProperties.READ_TIMEOUT, 1000);
WebTarget target = client.target("http://1.2.3.4:8080");
try {
String responseMsg = target.path("application.wadl").request().get(String.class);
System.out.println("responseMsg: " + responseMsg);
} catch (ProcessingException pe) {
pe.printStackTrace();
}
}
这篇关于如何使用 Jersey 2.x 设置连接和读取超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 Jersey 2.x 设置连接和读取超时?
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
