Search in sources :

Example 46 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project yyl_example by Relucent.

the class TraceInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    System.out.println("/==========TraceInterceptor==========");
    System.out.println("\nRequest:");
    System.out.println(request.method());
    System.out.println(request.url());
    System.out.println(request.headers());
    RequestBody requestBody = request.body();
    if (requestBody != null) {
        try (Buffer buffer = new Buffer()) {
            requestBody.writeTo(buffer);
            String content = buffer.readUtf8();
            System.out.println(content);
            requestBody = RequestBody.create(requestBody.contentType(), content);
        }
    }
    request = request.newBuilder().method(request.method(), requestBody).build();
    Response response = chain.proceed(request);
    MediaType mediaType = response.body().contentType();
    String content = response.body().string();
    System.out.println("\nResponse:");
    System.out.println(response.headers());
    System.out.println(content);
    System.out.println("==========TraceInterceptor==========/\n\n\n\n\n");
    return response.newBuilder().body(ResponseBody.create(mediaType, content)).build();
}
Also used : Buffer(okio.Buffer) Response(okhttp3.Response) Request(okhttp3.Request) MediaType(okhttp3.MediaType) RequestBody(okhttp3.RequestBody)

Example 47 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project cw-omnibus by commonsguy.

the class LoadThread method run.

@Override
public void run() {
    try {
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url(SO_URL).build();
        Response response = client.newCall(request).execute();
        if (response.isSuccessful()) {
            Reader in = response.body().charStream();
            BufferedReader reader = new BufferedReader(in);
            SOQuestions questions = new Gson().fromJson(reader, SOQuestions.class);
            reader.close();
            EventBus.getDefault().post(new QuestionsLoadedEvent(questions));
        } else {
            Log.e(getClass().getSimpleName(), response.toString());
        }
    } catch (Exception e) {
        Log.e(getClass().getSimpleName(), "Exception parsing JSON", e);
    }
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) Gson(com.google.gson.Gson)

Example 48 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project cw-omnibus by commonsguy.

the class Downloader method onHandleIntent.

@Override
public void onHandleIntent(Intent i) {
    mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    try {
        String filename = i.getData().getLastPathSegment();
        NotificationCompat.Builder builder = buildForeground(filename);
        final Notification notif = builder.build();
        startForeground(FOREGROUND_ID, notif);
        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
        root.mkdirs();
        File output = new File(root, filename);
        if (output.exists()) {
            output.delete();
        }
        final ProgressResponseBody.Listener progressListener = new ProgressResponseBody.Listener() {

            long lastUpdateTime = 0L;

            @Override
            public void onProgressChange(long bytesRead, long contentLength, boolean done) {
                long now = SystemClock.uptimeMillis();
                if (now - lastUpdateTime > 1000) {
                    notif.contentView.setProgressBar(android.R.id.progress, (int) contentLength, (int) bytesRead, false);
                    mgr.notify(FOREGROUND_ID, notif);
                    lastUpdateTime = now;
                }
            }
        };
        Interceptor nightTrain = new Interceptor() {

            @Override
            public Response intercept(Chain chain) throws IOException {
                Response original = chain.proceed(chain.request());
                Response.Builder b = original.newBuilder().body(new ProgressResponseBody(original.body(), progressListener));
                return (b.build());
            }
        };
        OkHttpClient client = new OkHttpClient.Builder().addNetworkInterceptor(nightTrain).build();
        Request request = new Request.Builder().url(i.getData().toString()).build();
        Response response = client.newCall(request).execute();
        String contentType = response.header("Content-type");
        BufferedSink sink = Okio.buffer(Okio.sink(new File(output.getPath())));
        sink.writeAll(response.body().source());
        sink.close();
        stopForeground(true);
        raiseNotification(contentType, output, null);
    } catch (IOException e2) {
        stopForeground(true);
        raiseNotification(null, null, e2);
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) BufferedSink(okio.BufferedSink) IOException(java.io.IOException) Notification(android.app.Notification) Response(okhttp3.Response) NotificationCompat(android.support.v4.app.NotificationCompat) File(java.io.File) Interceptor(okhttp3.Interceptor)

Example 49 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method decryptWithServiceResponseAsync.

/**
     * Decrypts a single block of encrypted data.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param keyName The name of the key.
     * @param keyVersion The version of the key.
     * @param algorithm algorithm identifier. Possible values include: 'RSA-OAEP', 'RSA1_5'
     * @param value the Base64Url value
     * @return the observable to the KeyOperationResult object
     */
public Observable<ServiceResponse<KeyOperationResult>> decryptWithServiceResponseAsync(String vaultBaseUrl, String keyName, String keyVersion, JsonWebKeyEncryptionAlgorithm algorithm, byte[] value) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (keyName == null) {
        throw new IllegalArgumentException("Parameter keyName is required and cannot be null.");
    }
    if (keyVersion == null) {
        throw new IllegalArgumentException("Parameter keyVersion is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (algorithm == null) {
        throw new IllegalArgumentException("Parameter algorithm is required and cannot be null.");
    }
    if (value == null) {
        throw new IllegalArgumentException("Parameter value is required and cannot be null.");
    }
    KeyOperationsParameters parameters = new KeyOperationsParameters();
    parameters.withAlgorithm(algorithm);
    parameters.withValue(value);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.decrypt(keyName, keyVersion, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<KeyOperationResult>>>() {

        @Override
        public Observable<ServiceResponse<KeyOperationResult>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<KeyOperationResult> clientResponse = decryptDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) KeyOperationResult(com.microsoft.azure.keyvault.models.KeyOperationResult) KeyOperationsParameters(com.microsoft.azure.keyvault.models.KeyOperationsParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 50 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method setSecretWithServiceResponseAsync.

/**
     * Sets a secret in a specified key vault.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param secretName The name of the secret.
     * @param value The value of the secret.
     * @param tags Application specific metadata in the form of key-value pairs.
     * @param contentType Type of the secret value such as a password.
     * @param secretAttributes The secret management attributes.
     * @return the observable to the SecretBundle object
     */
public Observable<ServiceResponse<SecretBundle>> setSecretWithServiceResponseAsync(String vaultBaseUrl, String secretName, String value, Map<String, String> tags, String contentType, SecretAttributes secretAttributes) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (secretName == null) {
        throw new IllegalArgumentException("Parameter secretName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (value == null) {
        throw new IllegalArgumentException("Parameter value is required and cannot be null.");
    }
    Validator.validate(tags);
    Validator.validate(secretAttributes);
    SecretSetParameters parameters = new SecretSetParameters();
    parameters.withValue(value);
    parameters.withTags(tags);
    parameters.withContentType(contentType);
    parameters.withSecretAttributes(secretAttributes);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.setSecret(secretName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<SecretBundle>>>() {

        @Override
        public Observable<ServiceResponse<SecretBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<SecretBundle> clientResponse = setSecretDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) SecretSetParameters(com.microsoft.azure.keyvault.models.SecretSetParameters) SecretBundle(com.microsoft.azure.keyvault.models.SecretBundle) ServiceResponse(com.microsoft.rest.ServiceResponse) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Aggregations

Response (okhttp3.Response)1083 Request (okhttp3.Request)814 IOException (java.io.IOException)434 Test (org.junit.Test)330 Response (retrofit2.Response)319 Call (okhttp3.Call)236 ResponseBody (okhttp3.ResponseBody)208 OkHttpClient (okhttp3.OkHttpClient)192 ServiceResponse (com.microsoft.rest.ServiceResponse)179 RequestBody (okhttp3.RequestBody)128 Observable (rx.Observable)116 Callback (okhttp3.Callback)111 MockResponse (okhttp3.mockwebserver.MockResponse)93 List (java.util.List)89 HttpUrl (okhttp3.HttpUrl)81 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)72 TypeToken (com.google.common.reflect.TypeToken)71 ArrayList (java.util.ArrayList)71 File (java.io.File)70 JSONObject (org.json.JSONObject)65