Search in sources :

Example 6 with ApacheHttpClient4Engine

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);
    }
}
Also used : RMRestClient(org.ow2.proactive_grid_cloud_portal.rm.client.RMRestClient) HttpClient(org.apache.http.client.HttpClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) IOException(java.io.IOException) RestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.RestException) RMNodeException(org.ow2.proactive.resourcemanager.exception.RMNodeException)

Example 7 with ApacheHttpClient4Engine

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;
}
Also used : ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder)

Example 8 with ApacheHttpClient4Engine

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);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) SocketConfig(org.apache.http.config.SocketConfig) ConnectionKeepAliveStrategy(org.apache.http.conn.ConnectionKeepAliveStrategy) HeaderElement(org.apache.http.HeaderElement) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) BasicHeaderElementIterator(org.apache.http.message.BasicHeaderElementIterator) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) BasicHeaderElementIterator(org.apache.http.message.BasicHeaderElementIterator) HeaderElementIterator(org.apache.http.HeaderElementIterator) RpcException(com.alibaba.dubbo.rpc.RpcException) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)

Example 9 with ApacheHttpClient4Engine

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);
}
Also used : ResteasyJackson2Provider(org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) GZIPDecodingInterceptor(org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) ClientInvocation(org.jboss.resteasy.client.jaxrs.internal.ClientInvocation) IOException(java.io.IOException) AcceptEncodingGZIPFilter(org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPFilter) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) HttpURLConnection(java.net.HttpURLConnection) GZIPEncodingInterceptor(org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor) HttpClient(org.apache.http.client.HttpClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 10 with ApacheHttpClient4Engine

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();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpResponsePoller(uk.gov.justice.services.test.utils.core.http.HttpResponsePoller) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Before(org.junit.Before)

Aggregations

ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)15 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)11 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)8 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)7 HttpClient (org.apache.http.client.HttpClient)6 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)5 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)5 Test (org.junit.Test)4 Response (javax.ws.rs.core.Response)3 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)3 IOException (java.io.IOException)2 ProcessingException (javax.ws.rs.ProcessingException)2 HeaderElement (org.apache.http.HeaderElement)2 DefaultHttpRequestRetryHandler (org.apache.http.impl.client.DefaultHttpRequestRetryHandler)2 HttpContext (org.apache.http.protocol.HttpContext)2 HttpClientBuilder (org.keycloak.adapters.HttpClientBuilder)2 HttpClientBuilder (org.ow2.proactive.http.HttpClientBuilder)2 RpcException (com.alibaba.dubbo.rpc.RpcException)1 ServicesInterface (com.baeldung.client.ServicesInterface)1 SSLConnectionSocketFactoryImpl (com.wavefront.agent.SSLConnectionSocketFactoryImpl)1