use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project scheduling by ow2-proactive.
the class RMNodeClient method init.
@Override
public void init(ConnectionInfo connectionInfo) throws Exception {
HttpClient client = new HttpClientBuilder().insecure(connectionInfo.isInsecure()).useSystemProperties().build();
RMRestClient restApiClient = new RMRestClient(connectionInfo.getUrl(), new ApacheHttpClient4Engine(client));
this.rm = restApiClient.getRm();
this.connectionInfo = connectionInfo;
try {
String sid = rm.rmConnect(connectionInfo.getLogin(), connectionInfo.getPassword());
setSession(sid);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project scheduling by ow2-proactive.
the class DataSpaceClient method init.
public void init(String restServerUrl, ISchedulerClient client) {
this.httpEngine = new ApacheHttpClient4Engine(new HttpClientBuilder().disableContentCompression().insecure(client.getConnectionInfo().isInsecure()).useSystemProperties().build());
this.providerFactory = ResteasyProviderFactory.getInstance();
SchedulerRestClient.registerGzipEncoding(providerFactory);
this.restDataspaceUrl = restDataspaceUrl(restServerUrl);
this.sessionId = client.getSession();
if (log.isDebugEnabled()) {
log.debug("Error : trying to retrieve session from disconnected client.");
}
this.schedulerClient = client;
}
use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project dubbo by alibaba.
the class RestProtocol method doRefer.
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
if (connectionMonitor == null) {
connectionMonitor = new ConnectionMonitor();
}
// TODO more configs to add
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
// 20 is the default maxTotal of current PoolingClientConnectionManager
connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionMonitor.addConnectionManager(connectionManager);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)).setSocketTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)).build();
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
return Long.parseLong(value) * 1000;
}
}
// TODO constant
return 30 * 1000;
}
}).setDefaultRequestConfig(requestConfig).setDefaultSocketConfig(socketConfig).build();
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
clients.add(client);
client.register(RpcContextFilter.class);
for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
if (!StringUtils.isEmpty(clazz)) {
try {
client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
} catch (ClassNotFoundException e) {
throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
}
}
}
// TODO protocol
ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
return target.proxy(serviceType);
}
use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project java by wavefrontHQ.
the class AbstractAgent method createAgentService.
/**
* Create RESTeasy proxies for remote calls via HTTP.
*/
protected WavefrontAPI createAgentService() {
ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
factory.registerProvider(JsonNodeWriter.class);
if (!factory.getClasses().contains(ResteasyJackson2Provider.class)) {
factory.registerProvider(ResteasyJackson2Provider.class);
}
if (httpUserAgent == null) {
httpUserAgent = "Wavefront-Proxy/" + props.getString("build.version");
}
ClientHttpEngine httpEngine;
if (javaNetConnection) {
httpEngine = new JavaNetConnectionEngine() {
@Override
protected HttpURLConnection createConnection(ClientInvocation request) throws IOException {
HttpURLConnection connection = (HttpURLConnection) request.getUri().toURL().openConnection();
connection.setRequestProperty("User-Agent", httpUserAgent);
connection.setRequestMethod(request.getMethod());
// 5s
connection.setConnectTimeout(httpConnectTimeout);
// 60s
connection.setReadTimeout(httpRequestTimeout);
if (connection instanceof HttpsURLConnection) {
HttpsURLConnection secureConnection = (HttpsURLConnection) connection;
secureConnection.setSSLSocketFactory(new SSLSocketFactoryImpl(HttpsURLConnection.getDefaultSSLSocketFactory(), httpRequestTimeout));
}
return connection;
}
};
} else {
HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setUserAgent(httpUserAgent).setMaxConnTotal(httpMaxConnTotal).setMaxConnPerRoute(httpMaxConnPerRoute).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(httpRequestTimeout).build()).setSSLSocketFactory(new SSLConnectionSocketFactoryImpl(SSLConnectionSocketFactory.getSystemSocketFactory(), httpRequestTimeout)).setRetryHandler(new DefaultHttpRequestRetryHandler(httpAutoRetries, true)).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(httpConnectTimeout).setConnectionRequestTimeout(httpConnectTimeout).setSocketTimeout(httpRequestTimeout).build()).build();
final ApacheHttpClient4Engine apacheHttpClient4Engine = new ApacheHttpClient4Engine(httpClient, true);
// avoid using disk at all
apacheHttpClient4Engine.setFileUploadInMemoryThresholdLimit(100);
apacheHttpClient4Engine.setFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit.MB);
httpEngine = apacheHttpClient4Engine;
}
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(factory).register(GZIPDecodingInterceptor.class).register(gzipCompression ? GZIPEncodingInterceptor.class : DisableGZIPEncodingInterceptor.class).register(AcceptEncodingGZIPFilter.class).build();
ResteasyWebTarget target = client.target(server);
return target.proxy(WavefrontAPI.class);
}
use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project microservice_framework by CJSCommonPlatform.
the class CakeShopIT method before.
@Before
public void before() throws Exception {
final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
final CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
// Increase max total connection to 200
cm.setMaxTotal(200);
// Increase default max connection per route to 20
cm.setDefaultMaxPerRoute(20);
final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
client = new ResteasyClientBuilder().httpEngine(engine).build();
httpResponsePoller = new HttpResponsePoller();
}
Aggregations