4

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.

1
  • I have the same issue, did you find an answer? Commented Nov 17, 2014 at 19:12

2 Answers 2

2

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);
    }

}
Sign up to request clarification or add additional context in comments.

Comments

2

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);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.