无法在JBoss上的Resteasy客户端上设置超时 [英] Cannot set timeout on Resteasy Client on JBoss
本文介绍了无法在JBoss上的Resteasy客户端上设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 JBoss EAP
服务器上创建一个休息客户端,我需要确保超时会在连接卡住时终止连接。
I am trying to create a rest client on a JBoss EAP
server, and I need to make sure that a timeout will end the connection if it gets stuck.
我的代码如下所示:
int timeout = 5000;
RequestConfig defaultRequestConfig = RequestConfig.custom().setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).setConnectTimeout(timeout).build();
HttpClientBuilder builder = HttpClientBuilder.create();
HttpClient httpClient = builder.setDefaultRequestConfig(defaultRequestConfig).build();
// Previous try
// HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
ClientExecutor executor = new ApacheHttpClient4Executor(httpClient);
ClientRequest cr = new ClientRequest("http://www.someserviceurl.com/", executor);
JSONObject jData = new JSONObject();
jData.put("param1", param1);
jData.put("param2", param2);
cr.accept("application/json");
cr.body("application/json", jData.toString());
ClientResponse<String> cres = cr.post(String.class);
目前这段代码没有超时,但只是永远陷入困境。我做错了什么?
Currently this code does not get a timeout, but just gets stuck forever. What am I doing wrong?
推荐答案
显然这是 RestEasy $ c $的已知问题c>已修复版本
3.0.9.Final
。
您可以看到错误报告此处。
要解决此问题,升级 RestEasy
或使用已弃用的 DefaultHttpClient
:
To fix it, upgrade RestEasy
or use the deprecated DefaultHttpClient
:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, timeout);
HttpConnectionParams.setSoTimeout(params, timeout);
ClientExecutor executor = new ApacheHttpClient4Executor(httpClient);
ClientRequest cr = new ClientRequest("http://www.someserviceurl.com/", executor);
这篇关于无法在JBoss上的Resteasy客户端上设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文