Search in sources :

Example 11 with ApacheHttpClient4Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project scheduling by ow2-proactive.

the class SchedulerClient method init.

@Override
public void init(ConnectionInfo connectionInfo) throws Exception {
    HttpClient client = new HttpClientBuilder().insecure(connectionInfo.isInsecure()).useSystemProperties().build();
    SchedulerRestClient restApiClient = new SchedulerRestClient(connectionInfo.getUrl(), new ApacheHttpClient4Engine(client));
    ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    factory.register(new WildCardTypeReader());
    factory.register(new OctetStreamReader());
    factory.register(new TaskResultReader());
    SchedulerRestClient.registerGzipEncoding(factory);
    setApiClient(restApiClient);
    this.connectionInfo = connectionInfo;
    this.initialized = true;
    renewSession();
}
Also used : WildCardTypeReader(org.ow2.proactive.scheduler.rest.readers.WildCardTypeReader) TaskResultReader(org.ow2.proactive.scheduler.rest.readers.TaskResultReader) OctetStreamReader(org.ow2.proactive.scheduler.rest.readers.OctetStreamReader) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) SchedulerRestClient(org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Example 12 with ApacheHttpClient4Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project keycloak by keycloak.

the class AbstractKerberosTest method initHttpClient.

protected void initHttpClient(boolean useSpnego) {
    if (client != null) {
        cleanupApacheHttpClient();
    }
    DefaultHttpClient httpClient = (DefaultHttpClient) new HttpClientBuilder().disableCookieCache(false).build();
    httpClient.getAuthSchemes().register(AuthSchemes.SPNEGO, spnegoSchemeFactory);
    if (useSpnego) {
        Credentials fake = new Credentials() {

            @Override
            public String getPassword() {
                return null;
            }

            @Override
            public Principal getUserPrincipal() {
                return null;
            }
        };
        httpClient.getCredentialsProvider().setCredentials(new AuthScope(null, -1, null), fake);
    }
    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
    client = new ResteasyClientBuilder().httpEngine(engine).build();
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) AuthScope(org.apache.http.auth.AuthScope) HttpClientBuilder(org.keycloak.adapters.HttpClientBuilder) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Credentials(org.apache.http.auth.Credentials)

Example 13 with ApacheHttpClient4Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project keycloak by keycloak.

the class LoginPageTest method realmLocalizationMessagesAreNotCachedWithinTheTheme.

// KEYCLOAK-18590
@Test
public void realmLocalizationMessagesAreNotCachedWithinTheTheme() throws IOException {
    final String locale = Locale.ENGLISH.toLanguageTag();
    final String realmLocalizationMessageKey = "loginAccountTitle";
    final String realmLocalizationMessageValue = "Localization Test";
    try (CloseableHttpClient httpClient = (CloseableHttpClient) new HttpClientBuilder().build()) {
        ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
        testRealm().localization().saveRealmLocalizationText(locale, realmLocalizationMessageKey, realmLocalizationMessageValue);
        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        loginPage.open();
        try (Response responseWithLocalization = client.target(driver.getCurrentUrl()).request().acceptLanguage(locale).get()) {
            assertThat(responseWithLocalization.readEntity(String.class), Matchers.containsString(realmLocalizationMessageValue));
            testRealm().localization().deleteRealmLocalizationText(locale, realmLocalizationMessageKey);
            loginPage.open();
            try (Response responseWithoutLocalization = client.target(driver.getCurrentUrl()).request().acceptLanguage(locale).get()) {
                assertThat(responseWithoutLocalization.readEntity(String.class), Matchers.not(Matchers.containsString(realmLocalizationMessageValue)));
            }
        }
        client.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpClientBuilder(org.keycloak.adapters.HttpClientBuilder) Test(org.junit.Test)

Example 14 with ApacheHttpClient4Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project java by wavefrontHQ.

the class HttpClientTest method httpClientTimeoutsWork.

@Test(expected = ProcessingException.class)
public void httpClientTimeoutsWork() throws Exception {
    ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    factory.registerProvider(JsonNodeWriter.class);
    factory.registerProvider(ResteasyJackson2Provider.class);
    HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setMaxConnTotal(200).setMaxConnPerRoute(100).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(100).build()).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(60000).build()).setSSLSocketFactory(new LayeredConnectionSocketFactory() {

        @Override
        public Socket createLayeredSocket(Socket socket, String target, int port, HttpContext context) throws IOException, UnknownHostException {
            return SSLConnectionSocketFactory.getSystemSocketFactory().createLayeredSocket(socket, target, port, context);
        }

        @Override
        public Socket createSocket(HttpContext context) throws IOException {
            return SSLConnectionSocketFactory.getSystemSocketFactory().createSocket(context);
        }

        @Override
        public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException {
            assertTrue("Non-zero timeout passed to connect socket is expected", connectTimeout > 0);
            throw new ProcessingException("OK");
        }
    }).build();
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(new ApacheHttpClient4Engine(httpClient, true)).providerFactory(factory).build();
    SocketServerRunnable sr = new SocketServerRunnable();
    Thread serverThread = new Thread(sr);
    serverThread.start();
    ResteasyWebTarget target = client.target("https://localhost:" + sr.getPort());
    SimpleRESTEasyAPI proxy = target.proxy(SimpleRESTEasyAPI.class);
    proxy.search("resteasy");
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) LayeredConnectionSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory) InetSocketAddress(java.net.InetSocketAddress) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpContext(org.apache.http.protocol.HttpContext) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 15 with ApacheHttpClient4Engine

use of org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine in project java by wavefrontHQ.

the class APIContainer method createHttpEngine.

private ClientHttpEngine createHttpEngine() {
    HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setUserAgent(proxyConfig.getHttpUserAgent()).setMaxConnTotal(proxyConfig.getHttpMaxConnTotal()).setMaxConnPerRoute(proxyConfig.getHttpMaxConnPerRoute()).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(proxyConfig.getHttpRequestTimeout()).build()).setSSLSocketFactory(new SSLConnectionSocketFactoryImpl(SSLConnectionSocketFactory.getSystemSocketFactory(), proxyConfig.getHttpRequestTimeout())).setRetryHandler(new DefaultHttpRequestRetryHandler(proxyConfig.getHttpAutoRetries(), true) {

        @Override
        protected boolean handleAsIdempotent(HttpRequest request) {
            // by default, retry all http calls (submissions are idempotent).
            return true;
        }
    }).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(proxyConfig.getHttpConnectTimeout()).setConnectionRequestTimeout(proxyConfig.getHttpConnectTimeout()).setSocketTimeout(proxyConfig.getHttpRequestTimeout()).build()).build();
    final ApacheHttpClient4Engine httpEngine = new ApacheHttpClient4Engine(httpClient, true);
    // avoid using disk at all
    httpEngine.setFileUploadInMemoryThresholdLimit(100);
    httpEngine.setFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit.MB);
    return httpEngine;
}
Also used : HttpRequest(org.apache.http.HttpRequest) SSLConnectionSocketFactoryImpl(com.wavefront.agent.SSLConnectionSocketFactoryImpl) HttpClient(org.apache.http.client.HttpClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler)

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