3

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);
Hadean
  • 77
  • 1
  • 9

1 Answers1

4

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);
    }
g.momo
  • 536
  • 2
  • 7