Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Timeout for JAX-RS 2.0 / Resteasy Client on Jboss

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);
like image 412
Hadean Avatar asked Oct 16 '25 20:10

Hadean


1 Answers

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);
    }
like image 160
g.momo Avatar answered Oct 18 '25 13:10

g.momo