Search in sources :

Example 76 with Response

use of com.squareup.okhttp.Response in project java by kubernetes-client.

the class PodLogs method streamNamespacedPodLog.

// Important note. You must close this stream or else you can leak connections.
public InputStream streamNamespacedPodLog(String namespace, String name, String container, Integer sinceSeconds, Integer tailLines, boolean timestamps) throws ApiException, IOException {
    Call call = coreClient.readNamespacedPodLogCall(name, namespace, container, true, null, "false", false, sinceSeconds, tailLines, timestamps, null, null);
    Response response = call.execute();
    if (!response.isSuccessful()) {
        throw new ApiException("Logs request failed: " + response.code());
    }
    return response.body().byteStream();
}
Also used : Response(com.squareup.okhttp.Response) Call(com.squareup.okhttp.Call)

Example 77 with Response

use of com.squareup.okhttp.Response in project java by kubernetes-client.

the class ProtoClient method delete.

/**
 * Delete a kubernetes API object using protocol buffer encoding.
 *
 * @param builder The builder for the response
 * @param path The path to call in the API server
 * @param deleteOptions optional deleteOptions
 * @return The response status
 */
public <T extends Message> ObjectOrStatus<T> delete(T.Builder builder, String path, DeleteOptions deleteOptions) throws ApiException, IOException {
    if (deleteOptions == null) {
        return delete(builder, path);
    }
    HashMap<String, String> headers = new HashMap<>();
    headers.put("Content-Type", MEDIA_TYPE);
    headers.put("Accept", MEDIA_TYPE);
    String[] localVarAuthNames = new String[] { "BearerToken" };
    Request request = apiClient.buildRequest(path, "DELETE", new ArrayList<Pair>(), new ArrayList<Pair>(), null, headers, new HashMap<String, Object>(), localVarAuthNames, null);
    byte[] bytes = encode(deleteOptions, "v1", "DeleteOptions");
    request = request.newBuilder().delete(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
    Response resp = apiClient.getHttpClient().newCall(request).execute();
    Unknown u = parse(resp.body().byteStream());
    resp.body().close();
    if (u.getTypeMeta().getApiVersion().equals("v1") && u.getTypeMeta().getKind().equals("Status")) {
        Status status = Status.newBuilder().mergeFrom(u.getRaw()).build();
        return new ObjectOrStatus(null, status);
    }
    return new ObjectOrStatus((T) builder.mergeFrom(u.getRaw()).build(), null);
}
Also used : Status(io.kubernetes.client.proto.Meta.Status) HashMap(java.util.HashMap) Request(com.squareup.okhttp.Request) Response(com.squareup.okhttp.Response) Unknown(io.kubernetes.client.proto.Runtime.Unknown)

Example 78 with Response

use of com.squareup.okhttp.Response in project sbt-android by scala-android.

the class OauthManager method handleResult.

public void handleResult(Uri data) {
    if (data == null)
        return;
    String code = data.getQueryParameter("code");
    if (code == null)
        return;
    try {
        // Trade our code for an access token.
        Request request = // 
        new Request.Builder().url(// 
        "https://github.com/login/oauth/access_token").header("Accept", // 
        "application/json").post(// 
        new FormEncodingBuilder().add("client_id", // 
        CLIENT_ID).add("client_secret", // 
        CLIENT_SECRET).add("code", // 
        code).build()).build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful()) {
            AccessTokenResponse accessTokenResponse = moshi.adapter(AccessTokenResponse.class).fromJson(response.body().string());
            if (accessTokenResponse != null && accessTokenResponse.access_token != null) {
                accessToken.set(accessTokenResponse.access_token);
            }
        }
    } catch (IOException e) {
        Timber.w(e, "Failed to get access token.");
    }
}
Also used : Response(com.squareup.okhttp.Response) FormEncodingBuilder(com.squareup.okhttp.FormEncodingBuilder) Request(com.squareup.okhttp.Request) FormEncodingBuilder(com.squareup.okhttp.FormEncodingBuilder) IOException(java.io.IOException)

Example 79 with Response

use of com.squareup.okhttp.Response in project incubator-heron by apache.

the class AppsV1beta1Controller method submit.

@Override
boolean submit(PackingPlan packingPlan) {
    final String topologyName = getTopologyName();
    if (!topologyName.equals(topologyName.toLowerCase())) {
        throw new TopologySubmissionException("K8S scheduler does not allow upper case topologies.");
    }
    final Resource containerResource = getContainerResource(packingPlan);
    // find the max number of instances in a container so we can open
    // enough ports if remote debugging is enabled.
    int numberOfInstances = 0;
    for (PackingPlan.ContainerPlan containerPlan : packingPlan.getContainers()) {
        numberOfInstances = Math.max(numberOfInstances, containerPlan.getInstances().size());
    }
    final V1beta1StatefulSet statefulSet = createStatefulSet(containerResource, numberOfInstances);
    try {
        final Response response = client.createNamespacedStatefulSetCall(getNamespace(), statefulSet, null, null, null).execute();
        if (!response.isSuccessful()) {
            LOG.log(Level.SEVERE, "Error creating topology message: " + response.message());
            KubernetesUtils.logResponseBodyIfPresent(LOG, response);
            // construct a message based on the k8s api server response
            throw new TopologySubmissionException(KubernetesUtils.errorMessageFromResponse(response));
        }
    } catch (IOException | ApiException e) {
        KubernetesUtils.logExceptionWithDetails(LOG, "Error creating topology", e);
        throw new TopologySubmissionException(e.getMessage());
    }
    return true;
}
Also used : TopologySubmissionException(com.twitter.heron.scheduler.TopologySubmissionException) Response(com.squareup.okhttp.Response) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) IOException(java.io.IOException) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) ApiException(io.kubernetes.client.ApiException)

Example 80 with Response

use of com.squareup.okhttp.Response in project xDrip by NightscoutFoundation.

the class GzipRequestInterceptor method sendFeedback.

public void sendFeedback(View myview) {
    final EditText contact = (EditText) findViewById(R.id.contactText);
    final EditText yourtext = (EditText) findViewById(R.id.yourText);
    final OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(10, TimeUnit.SECONDS);
    client.setReadTimeout(30, TimeUnit.SECONDS);
    client.setWriteTimeout(30, TimeUnit.SECONDS);
    client.interceptors().add(new GzipRequestInterceptor());
    if (yourtext.length() == 0) {
        toast("No text entered - cannot send blank");
        return;
    }
    if (contact.length() == 0) {
        toast("Without some contact info we cannot reply");
        askEmailAddress();
        return;
    }
    if (type_of_message.equals("Unknown")) {
        askType();
        return;
    }
    PersistentStore.setString(FEEDBACK_CONTACT_REFERENCE, contact.getText().toString());
    toast("Sending..");
    try {
        final RequestBody formBody = new FormEncodingBuilder().add("contact", contact.getText().toString()).add("body", JoH.getDeviceDetails() + "\n" + JoH.getVersionDetails() + "\n" + getBestCollectorHardwareName() + "\n===\n\n" + yourtext.getText().toString() + " \n\n===\nType: " + type_of_message + "\nLog data:\n\n" + log_data + "\n\n\nSent: " + JoH.dateTimeText(JoH.tsl())).add("rating", String.valueOf(myrating.getRating())).add("type", type_of_message).build();
        new Thread(new Runnable() {

            public void run() {
                try {
                    final Request request = new Request.Builder().url(send_url).post(formBody).build();
                    Log.i(TAG, "Sending feedback request");
                    final Response response = client.newCall(request).execute();
                    if (response.isSuccessful()) {
                        JoH.static_toast_long(response.body().string());
                        log_data = "";
                        // Home.toaststatic("Feedback sent successfully");
                        finish();
                    } else {
                        JoH.static_toast_short("Error sending feedback: " + response.message().toString());
                    }
                } catch (Exception e) {
                    Log.e(TAG, "Got exception in execute: " + e.toString());
                    JoH.static_toast_short("Error with network connection");
                }
            }
        }).start();
    } catch (Exception e) {
        JoH.static_toast_short(e.getMessage());
        Log.e(TAG, "General exception: " + e.toString());
    }
}
Also used : EditText(android.widget.EditText) Response(com.squareup.okhttp.Response) OkHttpClient(com.squareup.okhttp.OkHttpClient) Request(com.squareup.okhttp.Request) FormEncodingBuilder(com.squareup.okhttp.FormEncodingBuilder) IOException(java.io.IOException) RequestBody(com.squareup.okhttp.RequestBody)

Aggregations

Response (com.squareup.okhttp.Response)109 Request (com.squareup.okhttp.Request)75 IOException (java.io.IOException)70 OkHttpClient (com.squareup.okhttp.OkHttpClient)31 RequestBody (com.squareup.okhttp.RequestBody)23 JSONException (org.json.JSONException)16 JSONObject (org.json.JSONObject)15 FormEncodingBuilder (com.squareup.okhttp.FormEncodingBuilder)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)10 ApiCallException (org.eyeseetea.malariacare.domain.exception.ApiCallException)10 Callback (com.squareup.okhttp.Callback)9 SocketTimeoutException (java.net.SocketTimeoutException)8 File (java.io.File)7 ShowException (org.eyeseetea.malariacare.views.ShowException)7 Buffer (okio.Buffer)6 MediaType (com.squareup.okhttp.MediaType)5 InputStream (java.io.InputStream)5 HashMap (java.util.HashMap)5 Call (com.squareup.okhttp.Call)4 ApiException (io.kubernetes.client.ApiException)4