I am working on a design to create a generic rest client for our application for current and future integration's with multiple services (different external systems). Following is a high level diagram
I am thinking of creating a RestClient per external host, and Store them in a Map with Service name as Key and RestClient as value. Following is my RestClient(will be cached) class that wraps ResteasyWebTarget.
public class RestClient {
private ResteasyWebTarget target;
@Singleton
public class RestClientRepository {
private final Map<String, RestClient> repository =
new ConcurrentHashMap<String, RestClient>()
My default implementation will be using RestEasy. As my client code will be part of a webapp(multihtreaded environment). I will be using PoolingClientConnectionManager
ClientConnectionManager cm = new PoolingClientConnectionManager();
HttpClient httpClient = new DefaultHttpClient(cm);
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
ResteasyClient client = ((ResteasyClientBuilder) ResteasyClientBuilder
.newBuilder()).httpEngine(engine).build();
Is there a better solution than this approach?