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 设置连接和读取超时?


基础教程推荐
- 验证是否调用了所有 getter 方法 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01