Is replacing a ProxyFactory in a RESTEasy stream safe?

I developed the service in RESTEasy using ProxyFactory and ClientExecutor as follows:

PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
HttpParams params = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(params, 5000);
HttpConnectionParams.setSoTimeout(params, 5000);
ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);
MyClass client = ProxyFactory.create(MyClass.class, "http://www.example.com", clientExecutor);

It always worked perfectly. After RESTEasy abandoned ClientExecutor and ProxyFactory, they provided a new ResteasyClient for external connections, but I don’t know if this new ResteasyClient is thread safe. This is a new sample code from the documentation:

ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("http://example.com/base/uri");

SimpleClient simple = target.proxy(SimpleClient.class);

UPDATE: I used the code with ResteasyClient and I got a lot of errors like this:

javax.ws.rs.ProcessingException: Unable to invoke request

Called

java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. Make sure to release the connection before allocating another one.
+3
source share
2 answers

We use this:

    final ResteasyClient client = new ResteasyClientBuilder()
        .connectionPoolSize(10)
        .maxPooledPerRoute(5)
        .build();

, ( , ) RESTEasy ThreadSafeClientConnManager, , , , JavaDoc, PoolingHttpClientConnectionManager ( Http). RESTEasy 3.0.5. Final: https://issues.jboss.org/browse/RESTEASY-948

HTTP- .

+4

. HTTP- Apache. RestEasy 3.0.5.Final API

public static Object setupServiceProxy(@NotNull Class responseClass) {
    ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    ResteasyClientBuilder builder = new ResteasyClientBuilder().providerFactory(factory);
    ResteasyClient client = builder.httpEngine(setupHttpDefaults()).build();
    ResteasyWebTarget target = client.target(url);
    return target.proxy(responseClass);
}

public static ClientHttpEngine setupHttpDefaults() {
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
    DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
    HttpParams params = httpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, 30000);
    HttpConnectionParams.setSoTimeout(params, 30000);
    BasicHttpContext localContext = new BasicHttpContext();
    return new ApacheHttpClient4Engine(httpClient, localContext);
}
0

All Articles