I want to set a request timeout for each invocation rest client. Currently I have this:
private Client clientBuilder() {
return new ResteasyClientBuilder()
.establishConnectionTimeout(2, TimeUnit.SECONDS)
.socketTimeout(10, TimeUnit.SECONDS)
.build()
.register(ClientRestLoggingFilter.class)
.register(ObjectMapperContextResolver.class);
}
Problem is, that probably don't work for other methods than get. Whats more, socket Timeout is not timeout for reading full response, but for individual packets. socketTimeout and connectionTimeout information
I am looking solution for RestEasy similar like following in jersey:
import org.glassfish.jersey.client.ClientProperties;
ClientConfig configuration = new ClientConfig();
configuration.property(ClientProperties.CONNECT_TIMEOUT, 1000);
configuration.property(ClientProperties.READ_TIMEOUT, 1000);
Client client = ClientBuilder.newClient(configuration);
As explained on jboss v7.3 by redhat website :
The following ClientBuilder specification-compliant methods replace certain deprecated RESTEasy methods:
The connectTimeout method replaces the establishConnectionTimeout method.
- The connectTimeout method determines how long the client must wait when making a new server connection.
The readTimeout method replaces the socketTimeout method.
- The readTimeout method determines how long the client must wait for a response from the server.
So this should be good for your case:
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