Search in sources :

Example 26 with Request

use of okhttp3.Request in project zipkin by openzipkin.

the class ElasticsearchHttpStorageTest method memoizesIndexTemplate.

@Test
public void memoizesIndexTemplate() throws Exception {
    es.enqueue(new MockResponse().setBody("{\"version\":{\"number\":\"2.4.0\"}}"));
    // get template
    es.enqueue(new MockResponse());
    // dependencies request
    es.enqueue(new MockResponse());
    // dependencies request
    es.enqueue(new MockResponse());
    long endTs = storage.indexNameFormatter().parseDate("2016-10-02");
    storage.spanStore().getDependencies(endTs, TimeUnit.DAYS.toMillis(1));
    storage.spanStore().getDependencies(endTs, TimeUnit.DAYS.toMillis(1));
    // get version
    es.takeRequest();
    // get template
    es.takeRequest();
    assertThat(es.takeRequest().getPath()).startsWith("/zipkin-2016-10-01,zipkin-2016-10-02/dependencylink/_search");
    assertThat(es.takeRequest().getPath()).startsWith("/zipkin-2016-10-01,zipkin-2016-10-02/dependencylink/_search");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 27 with Request

use of okhttp3.Request in project zipkin by openzipkin.

the class HttpBulkSpanIndexerTest method doesntWriteSpanId.

@Test
public void doesntWriteSpanId() throws Exception {
    es.enqueue(new MockResponse());
    indexer.add("test_zipkin_http-2016-10-01", TestObjects.LOTS_OF_SPANS[0], (Long) null);
    indexer.execute(callback);
    callback.get();
    RecordedRequest request = es.takeRequest();
    assertThat(request.getBody().readByteString().utf8()).doesNotContain("\"_id\"");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 28 with Request

use of okhttp3.Request in project Pokemap by omkarmoghe.

the class NetworkRequestLoggingInterceptor method convertRequestBodyToString.

private String convertRequestBodyToString(final Request request) {
    try {
        final Request copy = request.newBuilder().build();
        final Buffer buffer = new Buffer();
        copy.body().writeTo(buffer);
        return buffer.readUtf8();
    } catch (final IOException e) {
        e.printStackTrace();
        Log.e(TAG, "Failed to convert request body to string via convertRequestBodyToString(). Raised: " + e.getMessage());
        return null;
    }
}
Also used : Buffer(okio.Buffer) Request(okhttp3.Request) IOException(java.io.IOException)

Example 29 with Request

use of okhttp3.Request in project Pokemap by omkarmoghe.

the class NetworkRequestLoggingInterceptor method intercept.

@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
    final Request request = chain.request();
    // Log request
    Log.d(TAG, MessageFormat.format(REQUEST_SEND_LOG, request.method(), sanitize(request.url()), chain.connection(), request.headers()));
    if (request.method().compareToIgnoreCase("post") == 0)
        Log.d(TAG, MessageFormat.format(REQUEST_BODY_LOG, convertRequestBodyToString(request)));
    final long requestStart = System.currentTimeMillis();
    final Response response = chain.proceed(request);
    final long requestEnd = System.currentTimeMillis();
    final long responseTime = requestEnd - requestStart;
    // Log response
    Log.d(TAG, MessageFormat.format(RESPONSE_RECEIVE_LOG, responseTime, sanitize(response.request().url()), response.headers()));
    final String responseBodyString = response.body().string();
    if (responseBodyString.length() > 0)
        Log.d(TAG, MessageFormat.format(RESPONSE_BODY_LOG, responseBodyString.trim()));
    return response.newBuilder().body(ResponseBody.create(response.body().contentType(), responseBodyString)).build();
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request)

Example 30 with Request

use of okhttp3.Request in project android-oss by kickstarter.

the class ApiExceptionFactory method badRequestException.

@NonNull
public static ApiException badRequestException() {
    final ErrorEnvelope envelope = ErrorEnvelope.builder().errorMessages(Collections.singletonList("bad request")).httpCode(400).build();
    final ResponseBody body = ResponseBody.create(null, "");
    final retrofit2.Response<Observable<User>> response = retrofit2.Response.error(400, body);
    return new ApiException(envelope, response);
}
Also used : ErrorEnvelope(com.kickstarter.services.apiresponses.ErrorEnvelope) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) ApiException(com.kickstarter.services.ApiException) NonNull(android.support.annotation.NonNull)

Aggregations

Request (okhttp3.Request)1552 Response (okhttp3.Response)1090 Test (org.junit.Test)948 IOException (java.io.IOException)624 MockResponse (okhttp3.mockwebserver.MockResponse)560 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)556 OkHttpClient (okhttp3.OkHttpClient)343 RequestBody (okhttp3.RequestBody)281 Call (okhttp3.Call)255 ResponseBody (okhttp3.ResponseBody)252 HttpUrl (okhttp3.HttpUrl)186 Test (org.junit.jupiter.api.Test)158 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)142 Buffer (okio.Buffer)138 List (java.util.List)114 Callback (okhttp3.Callback)114 File (java.io.File)105 URI (java.net.URI)101 InputStream (java.io.InputStream)99 JSONObject (org.json.JSONObject)96