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 设置连接和读取超时?
基础教程推荐
- 将 double 转换为 Int,向下舍入 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- JPA惰性列表上的流 2022-01-01
