use of com.squareup.okhttp.Call in project apiman by apiman.
the class EnrichPre21ExportCommand method triggerExport.
private DownloadBean triggerExport() throws IOException {
HttpUrl triggerExportUrl = HttpUrl.parse(endpoint).newBuilder().addPathSegment("system").addPathSegment("export").addQueryParameter("download", "true").build();
Request triggerExportRequest = buildRequest(triggerExportUrl);
Call exportCall = client.newCall(triggerExportRequest);
Response exportResponse = exportCall.execute();
checkStatusOk(exportResponse);
return OBJECT_MAPPER.readValue(exportResponse.body().string(), DownloadBean.class);
}
use of com.squareup.okhttp.Call in project workbench by all-of-us.
the class Application method main.
public static void main(String[] args) throws Exception {
OkHttpClient client = new OkHttpClient();
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
String cronYamlPath = args[0];
String xml = new String(Files.readAllBytes(Paths.get(cronYamlPath)));
CronEntries cronEntries = new ObjectMapper(new YAMLFactory()).readValue(xml, CronEntries.class);
for (Cron cron : cronEntries.cron) {
Schedule schedule = parseCronSchedule(cron.schedule);
scheduledExecutorService.scheduleAtFixedRate(() -> {
Request request = new Request.Builder().addHeader("X-Appengine-Cron", "true").url(BASE_URL + cron.url).build();
Call call = client.newCall(request);
try {
Response response = call.execute();
log(response.toString());
hasServerStarted = true;
consecutiveConnectionFailures = 0;
} catch (ConnectException e) {
log(e.getMessage());
consecutiveConnectionFailures++;
} catch (IOException e) {
log(e.getMessage());
}
if (hasServerStarted && consecutiveConnectionFailures >= MAX_CONNECTION_FAILURES_BEFORE_EXIT) {
System.exit(0);
}
}, 0, schedule.period, schedule.timeUnit);
}
}
use of com.squareup.okhttp.Call in project components by Talend.
the class HadoopCMConfigurator method setAPIVersion.
private void setAPIVersion(ApiClient client) throws ApiException {
String requestPath = "/version";
String method = "GET";
Map<String, String> headerParams = new HashMap<String, String>();
String[] accepts = { "application/json" };
String accept = client.selectHeaderAccept(accepts);
if (accept != null)
headerParams.put("Accept", accept);
String[] contentTypes = new String[0];
String[] authNames = { "basic" };
String contentType = client.selectHeaderContentType(contentTypes);
headerParams.put("Content-Type", contentType);
Call c = client.buildCall(requestPath, method, null, null, headerParams, null, authNames, null);
Type returnType = (new TypeToken<String>() {
}).getType();
ApiResponse<String> version = client.execute(c, returnType);
if (version.getStatusCode() == 200) {
// highest version
client.setBasePath(client.getBasePath() + "/" + version.getData());
} else if (version.getStatusCode() == 404) {
// default version
client.setBasePath(client.getBasePath() + "/" + DEFAULT_API_VERSION);
} else {
// throw exception
throw new RuntimeException("Can't retrieve api version from " + client.getBasePath());
}
log.log(Level.INFO, "setAPIVersion, base path: " + client.getBasePath());
}
use of com.squareup.okhttp.Call in project concord by walmartlabs.
the class ConcordServerRule method getLog.
public byte[] getLog(String logFileName) throws ApiException {
Set<String> auths = client.getAuthentications().keySet();
String[] authNames = auths.toArray(new String[0]);
Call c = client.buildCall("/logs/" + logFileName, "GET", new ArrayList<>(), new ArrayList<>(), null, new HashMap<>(), new HashMap<>(), authNames, null);
Type t = new TypeToken<byte[]>() {
}.getType();
return client.<byte[]>execute(c, t).getData();
}
use of com.squareup.okhttp.Call in project concord by walmartlabs.
the class InventoryQueryIT method assertQuery.
private static void assertQuery(ApiClient client, String orgName, String inventoryName, String queryName, String contentType) throws Exception {
Set<String> auths = client.getAuthentications().keySet();
String[] authNames = auths.toArray(new String[0]);
String data = "select * from inventory_data";
Map<String, String> headerParams = new HashMap<>(Collections.singletonMap("Content-Type", contentType));
Call call = client.buildCall("/api/v1/org/" + orgName + "/inventory/" + inventoryName + "/query/" + queryName, "POST", new ArrayList<>(), new ArrayList<>(), data, headerParams, new HashMap<>(), authNames, null);
ApiResponse<Object> response = client.execute(call, CreateInventoryQueryResponse.class);
assertEquals(200, response.getStatusCode());
}
Aggregations