Search in sources :

Example 1 with HttpClientBuilder

use of org.ow2.proactive.http.HttpClientBuilder in project scheduling by ow2-proactive.

the class AbstractRestFuncTestCase method getSession.

private String getSession(String schedulerUrl, String username, String password) throws Exception {
    String resourceUrl = getResourceUrl("login");
    HttpPost httpPost = new HttpPost(resourceUrl);
    StringBuilder buffer = new StringBuilder();
    buffer.append("username=").append(username).append("&password=").append(password);
    StringEntity entity = new StringEntity(buffer.toString());
    entity.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    httpPost.setEntity(entity);
    HttpResponse response = new HttpClientBuilder().insecure(true).useSystemProperties().build().execute(httpPost);
    String responseContent = EntityUtils.toString(response.getEntity());
    if (STATUS_OK != getStatusCode(response)) {
        throw new RuntimeException(String.format("Authentication error: %n%s", responseContent));
    } else {
        return responseContent;
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder)

Example 2 with HttpClientBuilder

use of org.ow2.proactive.http.HttpClientBuilder in project scheduling by ow2-proactive.

the class ProActiveVersionUtility method getProActiveServerVersion.

protected static String getProActiveServerVersion(ApplicationContext currentContext) {
    int timeout = (int) TimeUnit.SECONDS.toMillis(2);
    RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).build();
    try (CloseableHttpClient httpClient = new HttpClientBuilder().setDefaultRequestConfig(config).useSystemProperties().build()) {
        HttpGet getMethod = new HttpGet(currentContext.getResourceUrl("version"));
        HttpResponse response = httpClient.execute(getMethod);
        String jsonObject = handleResponse(response);
        if (jsonObject != null)
            return jsonObject;
    } catch (IOException ignore) {
    // ignore exception, default value will be used
    }
    return VERSION_UNDEFINED;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) IOException(java.io.IOException) CommonEntryPoint(org.ow2.proactive_grid_cloud_portal.cli.CommonEntryPoint)

Example 3 with HttpClientBuilder

use of org.ow2.proactive.http.HttpClientBuilder 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.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 4 with HttpClientBuilder

use of org.ow2.proactive.http.HttpClientBuilder in project scheduling by ow2-proactive.

the class RestFuncTHelper method restIsStarted.

private static Callable<Boolean> restIsStarted() {
    return new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            try {
                String resourceUrl = getResourceUrl("version");
                HttpClient client = new HttpClientBuilder().insecure(true).useSystemProperties().build();
                HttpResponse response = client.execute(new HttpGet(resourceUrl));
                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == HttpStatus.SC_OK) {
                    return true;
                }
            } catch (IOException e) {
            }
            return false;
        }
    };
}
Also used : HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) Callable(java.util.concurrent.Callable)

Example 5 with HttpClientBuilder

use of org.ow2.proactive.http.HttpClientBuilder 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());
    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)

Aggregations

HttpClientBuilder (org.ow2.proactive.http.HttpClientBuilder)6 HttpResponse (org.apache.http.HttpResponse)4 IOException (java.io.IOException)2 HttpClient (org.apache.http.client.HttpClient)2 HttpGet (org.apache.http.client.methods.HttpGet)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 Callable (java.util.concurrent.Callable)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 RequestConfig (org.apache.http.client.config.RequestConfig)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)1 StringEntity (org.apache.http.entity.StringEntity)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1 CommonHttpClientBuilder (org.ow2.proactive.http.CommonHttpClientBuilder)1 OctetStreamReader (org.ow2.proactive.scheduler.rest.readers.OctetStreamReader)1 TaskResultReader (org.ow2.proactive.scheduler.rest.readers.TaskResultReader)1 WildCardTypeReader (org.ow2.proactive.scheduler.rest.readers.WildCardTypeReader)1 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)1