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;
}
}
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;
}
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;
}
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;
}
};
}
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();
}
Aggregations