Search in sources :

Example 16 with Call

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);
}
Also used : Response(com.squareup.okhttp.Response) Call(com.squareup.okhttp.Call) Request(com.squareup.okhttp.Request) HttpUrl(com.squareup.okhttp.HttpUrl)

Example 17 with Call

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);
    }
}
Also used : Call(com.squareup.okhttp.Call) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OkHttpClient(com.squareup.okhttp.OkHttpClient) Request(com.squareup.okhttp.Request) Response(com.squareup.okhttp.Response) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectException(java.net.ConnectException)

Example 18 with Call

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());
}
Also used : Call(com.squareup.okhttp.Call) Type(java.lang.reflect.Type) HashMap(java.util.HashMap) TypeToken(com.google.gson.reflect.TypeToken)

Example 19 with Call

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();
}
Also used : Call(com.squareup.okhttp.Call) Type(java.lang.reflect.Type)

Example 20 with Call

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());
}
Also used : Call(com.squareup.okhttp.Call)

Aggregations

Call (com.squareup.okhttp.Call)46 Type (java.lang.reflect.Type)28 Request (com.squareup.okhttp.Request)13 Response (com.squareup.okhttp.Response)13 OkHttpClient (com.squareup.okhttp.OkHttpClient)9 PaymentDetails (jp.ne.paypay.model.PaymentDetails)8 RequestBody (com.squareup.okhttp.RequestBody)5 IOException (java.io.IOException)5 HttpUrl (com.squareup.okhttp.HttpUrl)4 HashMap (java.util.HashMap)4 ReverseCashbackDetails (jp.ne.paypay.model.ReverseCashbackDetails)4 TypeToken (com.google.gson.reflect.TypeToken)3 NotDataResponse (jp.ne.paypay.model.NotDataResponse)3 Base64 (org.apache.commons.codec.binary.Base64)3 Pair (jp.ne.paypay.Pair)2 Request (com.android.volley.Request)1 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)1 ApiCommandList (com.cloudera.api.swagger.model.ApiCommandList)1 ApiHost (com.cloudera.api.swagger.model.ApiHost)1 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)1