gpt4 book ai didi

resteasy - 在 RestEASY 中设置连接超时

转载 作者:行者123 更新时间:2023-12-05 05:26:43 27 4
gpt4 key购买 nike

JBoss 告诉我们

http://docs.jboss.org/seam/3/rest/latest/reference/en-US/html/rest.client.html

要为 RestEASY ClientRequest 设置超时,我们必须创建自定义 ClientExecutor,然后在 ConnManagerParams 上调用已弃用的静态方法。这似乎有点矫揉造作。有没有更好的办法?这是 RestEASY 2.3.6。

最佳答案

这是一个干净的工作解决方案:-)

@Singleton
public class RestEasyConfig {

@Inject
@MyConfig
private Integer httpClientMaxConnectionsPerRoute;

@Inject
@MyConfig
private Integer httpClientTimeoutMillis;

@Inject
@MyConfig
private Integer httpClientMaxTotalConnections;

@Produces
private ClientExecutor clientExecutor;

@PostConstruct
public void createExecutor() {
final BasicHttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, this.httpClientTimeoutMillis);

final SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));

final ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager(schemeRegistry);
connManager.setDefaultMaxPerRoute(this.httpClientMaxConnectionsPerRoute);
connManager.setMaxTotal(this.httpClientMaxTotalConnections);

final HttpClient httpClient = new DefaultHttpClient(connManager, params);

this.clientExecutor = new ApacheHttpClient4Executor(httpClient);
}

}

关于resteasy - 在 RestEASY 中设置连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24432204/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com