Search in sources :

Example 21 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Request in project zipkin by openzipkin.

the class HttpCallTest method propagatesOnDispatcherThreadWhenFatal.

@Test
public void propagatesOnDispatcherThreadWhenFatal() throws Exception {
    mws.enqueue(new MockResponse());
    http.newCall(request, b -> {
        throw new LinkageError();
    }).submit(callback);
    SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter();
    try {
        timeLimiter.callWithTimeout(callback::get, 100, TimeUnit.MILLISECONDS, true);
        failBecauseExceptionWasNotThrown(UncheckedTimeoutException.class);
    } catch (UncheckedTimeoutException expected) {
    }
}
Also used : Request(okhttp3.Request) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) OkHttpClient(okhttp3.OkHttpClient) Rule(org.junit.Rule) After(org.junit.After) MockWebServer(okhttp3.mockwebserver.MockWebServer) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) MockResponse(okhttp3.mockwebserver.MockResponse) CallbackCaptor(zipkin.internal.CallbackCaptor) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) MockResponse(okhttp3.mockwebserver.MockResponse) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Test(org.junit.Test)

Example 22 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Request in project zipkin by openzipkin.

the class HttpCallTest method executionException_conversionException.

@Test
public void executionException_conversionException() throws Exception {
    mws.enqueue(new MockResponse());
    http.newCall(request, b -> {
        throw new IllegalArgumentException("eeek");
    }).submit(callback);
    try {
        callback.get();
        failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException expected) {
        assertThat(expected).isInstanceOf(IllegalArgumentException.class);
    }
}
Also used : Request(okhttp3.Request) SimpleTimeLimiter(com.google.common.util.concurrent.SimpleTimeLimiter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) OkHttpClient(okhttp3.OkHttpClient) Rule(org.junit.Rule) After(org.junit.After) MockWebServer(okhttp3.mockwebserver.MockWebServer) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) MockResponse(okhttp3.mockwebserver.MockResponse) CallbackCaptor(zipkin.internal.CallbackCaptor) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 23 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.Request in project zipkin by openzipkin.

the class ElasticsearchHttpStorage method flush.

/** This is a blocking call, only used in tests. */
static void flush(HttpCall.Factory factory, String index) throws IOException {
    Request flushRequest = new Request.Builder().url(factory.baseUrl.newBuilder().addPathSegment(index).addPathSegment("_flush").build()).post(RequestBody.create(APPLICATION_JSON, "")).tag("flush-index").build();
    factory.execute(flushRequest, b -> null);
}
Also used : Request(okhttp3.Request)

Example 24 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.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 25 with Request

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.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)

Aggregations

Request (okhttp3.Request)3768 Response (okhttp3.Response)2288 IOException (java.io.IOException)1180 OkHttpClient (okhttp3.OkHttpClient)896 Test (org.junit.Test)754 RequestBody (okhttp3.RequestBody)665 Call (okhttp3.Call)537 HttpUrl (okhttp3.HttpUrl)528 ResponseBody (okhttp3.ResponseBody)421 Callback (okhttp3.Callback)290 InputStream (java.io.InputStream)207 Map (java.util.Map)207 JSONObject (org.json.JSONObject)205 MediaType (okhttp3.MediaType)193 HashMap (java.util.HashMap)178 List (java.util.List)176 ArrayList (java.util.ArrayList)157 File (java.io.File)152 Test (org.junit.jupiter.api.Test)147 Headers (okhttp3.Headers)134