JBoss tells us
http://docs.jboss.org/seam/3/rest/latest/reference/en-US/html/rest.client.html
that to set the timeout for a RestEASY ClientRequest we must create a custom ClientExecutor, then call deprecated static methods on ConnManagerParams. This seems rather hokey. Is there a better way? This is RestEASY 2.3.6.
Here is a clean working solution :-)
@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);
}
}
With RestEASY 3.12.1.Final, as explained by redhat website, I did it this way:
private Client clientBuilder() {
return new ResteasyClientBuilder()
.connectTimeout(2, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.build()
.register(ClientRestLoggingFilter.class)
.register(ObjectMapperContextResolver.class);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With