Search in sources :

Example 46 with ResteasyClient

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

the class SchedulerRestClient method createRestProxy.

private static SchedulerRestInterface createRestProxy(ResteasyProviderFactory provider, String restEndpointURL, ClientHttpEngine httpEngine) {
    ResteasyClient client = buildResteasyClient(provider);
    ResteasyWebTarget target = client.target(restEndpointURL);
    SchedulerRestInterface schedulerRestClient = target.proxy(SchedulerRestInterface.class);
    return createExceptionProxy(schedulerRestClient);
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface)

Example 47 with ResteasyClient

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

the class SchedulerRestClient method list.

public ListFile list(String sessionId, String dataspacePath, String pathname) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
    ResteasyClient client = buildResteasyClient(providerFactory);
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(pathname).queryParam("comp", "list");
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).get();
        if (response.getStatus() != HttpURLConnection.HTTP_OK) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("Cannot list the specified location: %s", pathname), response);
            }
        }
        return response.readEntity(ListFile.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Example 48 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project eap-additional-testsuite by jboss-set.

the class ApacheHttpClient431TestCase method createEngine.

@SuppressWarnings(value = "unchecked")
private ResteasyClient createEngine(Class engine) {
    RequestConfig reqConfig = // apache HttpClient specific
    RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).setConnectionRequestTimeout(5000).build();
    CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(reqConfig).setMaxConnTotal(3).build();
    final ClientHttpEngine executor;
    if (engine.isAssignableFrom(ApacheHttpClient43Engine.class)) {
        executor = new ApacheHttpClient43Engine(httpClient);
    } else {
        executor = new URLConnectionEngine();
    }
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(executor).build();
    return client;
}
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) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) URLConnectionEngine(org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)

Example 49 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project eap-additional-testsuite by jboss-set.

the class ApacheHttpClient43TestCase method createEngine.

@SuppressWarnings(value = "unchecked")
private ResteasyClient createEngine(Class engine) {
    RequestConfig reqConfig = // apache HttpClient specific
    RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).setConnectionRequestTimeout(5000).build();
    CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(reqConfig).setMaxConnTotal(3).build();
    final ClientHttpEngine executor;
    if (engine.isAssignableFrom(ApacheHttpClient43Engine.class)) {
        executor = new ApacheHttpClient43Engine(httpClient);
    } else {
        executor = new URLConnectionEngine();
    }
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(executor).build();
    return client;
}
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) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) URLConnectionEngine(org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)

Example 50 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project eap-additional-testsuite by jboss-set.

the class ApacheHttpClient43TestCase method testConnectionWithRequestBody.

public void testConnectionWithRequestBody(Class engine) throws InterruptedException {
    final ResteasyClient client = createEngine(engine);
    final ApacheHttpClient4Resource proxy = client.target("http://127.0.0.1:8080/" + ApacheHttpClient43TestCase.class.getSimpleName()).proxy(ApacheHttpClient4Resource.class);
    counter.set(0);
    Thread[] threads = new Thread[3];
    for (int i = 0; i < 3; i++) {
        threads[i] = new Thread() {

            @Override
            public void run() {
                for (int j = 0; j < 10; j++) {
                    String res = proxy.getData(String.valueOf(j));
                    Assert.assertNotNull("Response should not be null", res);
                    counter.incrementAndGet();
                }
            }
        };
    }
    for (int i = 0; i < 3; i++) {
        threads[i].start();
    }
    for (int i = 0; i < 3; i++) {
        threads[i].join();
    }
    Assert.assertEquals("Wrong count of requests", 30L, counter.get());
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ApacheHttpClient4Resource(org.jboss.additional.testsuite.jdkall.present.jaxrs.client.resource.ApacheHttpClient4Resource)

Aggregations

ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)66 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)42 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)28 Response (javax.ws.rs.core.Response)17 Test (org.junit.Test)14 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)10 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)8 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)7 ServicesInterface (com.baeldung.client.ServicesInterface)6 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)6 ProcessingException (javax.ws.rs.ProcessingException)5 IOException (java.io.IOException)4 Map (java.util.Map)4 WebTarget (javax.ws.rs.client.WebTarget)4 RequestConfig (org.apache.http.client.config.RequestConfig)4 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)4 ClientHttpEngine (org.jboss.resteasy.client.jaxrs.ClientHttpEngine)4 Locale (java.util.Locale)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ApacheHttpClient4Resource (org.jboss.additional.testsuite.jdkall.present.jaxrs.client.resource.ApacheHttpClient4Resource)3