Search in sources :

Example 36 with Call

use of zipkin2.Call in project okhttp by square.

the class HttpOverHttp2Test method sendRequestCookies.

@Test
public void sendRequestCookies() throws Exception {
    RecordingCookieJar cookieJar = new RecordingCookieJar();
    Cookie requestCookie = new Cookie.Builder().name("a").value("b").domain(server.getHostName()).build();
    cookieJar.enqueueRequestCookies(requestCookie);
    client = client.newBuilder().cookieJar(cookieJar).build();
    server.enqueue(new MockResponse());
    Call call = client.newCall(new Request.Builder().url(server.url("/")).build());
    Response response = call.execute();
    assertEquals("", response.body().string());
    RecordedRequest request = server.takeRequest();
    assertEquals("a=b", request.getHeader("Cookie"));
}
Also used : Cookie(okhttp3.Cookie) MockResponse(okhttp3.mockwebserver.MockResponse) Response(okhttp3.Response) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) RecordingCookieJar(okhttp3.RecordingCookieJar) MockResponse(okhttp3.mockwebserver.MockResponse) Call(okhttp3.Call) Request(okhttp3.Request) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 37 with Call

use of zipkin2.Call in project okhttp by square.

the class OkHttpURLConnection method connect.

@Override
public void connect() throws IOException {
    if (executed)
        return;
    Call call = buildCall();
    executed = true;
    call.enqueue(this);
    synchronized (lock) {
        try {
            while (connectPending && response == null && callFailure == null) {
                // Wait 'til the network interceptor is reached or the call fails.
                lock.wait();
            }
            if (callFailure != null) {
                throw propagate(callFailure);
            }
        } catch (InterruptedException e) {
            throw new InterruptedIOException();
        }
    }
}
Also used : Call(okhttp3.Call) InterruptedIOException(java.io.InterruptedIOException)

Example 38 with Call

use of zipkin2.Call in project okhttp by square.

the class OkHttpURLConnection method getResponse.

/**
   * Aggressively tries to get the final HTTP response, potentially making many HTTP requests in the
   * process in order to cope with redirects and authentication.
   */
private Response getResponse(boolean networkResponseOnError) throws IOException {
    synchronized (lock) {
        if (response != null)
            return response;
        if (callFailure != null) {
            if (networkResponseOnError && networkResponse != null)
                return networkResponse;
            throw propagate(callFailure);
        }
    }
    Call call = buildCall();
    networkInterceptor.proceed();
    OutputStreamRequestBody requestBody = (OutputStreamRequestBody) call.request().body();
    if (requestBody != null)
        requestBody.outputStream().close();
    if (executed) {
        synchronized (lock) {
            try {
                while (response == null && callFailure == null) {
                    // Wait until the response is returned or the call fails.
                    lock.wait();
                }
            } catch (InterruptedException e) {
                throw new InterruptedIOException();
            }
        }
    } else {
        executed = true;
        try {
            onResponse(call, call.execute());
        } catch (IOException e) {
            onFailure(call, e);
        }
    }
    synchronized (lock) {
        if (callFailure != null)
            throw propagate(callFailure);
        if (response != null)
            return response;
    }
    throw new AssertionError();
}
Also used : Call(okhttp3.Call) InterruptedIOException(java.io.InterruptedIOException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 39 with Call

use of zipkin2.Call in project WeexErosFramework by bmfe.

the class MultipleFileDownloader method execute.

public void execute() {
    if (mList == null)
        return;
    AxiosManager axiosManager = ManagerFactory.getManagerService(AxiosManager.class);
    for (final String url : mList) {
        final String fileName = createFileName(url);
        axiosManager.download(url, new FileCallBack(mPath, fileName) {

            @Override
            public void onError(Call call, Exception e, int id) {
                mSize++;
                Log.e("url", "error" + url);
                erros.add(new FileItem(new File(mPath, fileName).getAbsolutePath(), fileName));
                postResult(mSize);
            }

            @Override
            public void onResponse(File response, int id) {
                mSize++;
                Log.e("url", url);
                paths.add(new FileItem(new File(mPath, fileName).getAbsolutePath(), fileName));
                postResult(mSize);
            }
        });
    }
}
Also used : Call(okhttp3.Call) AxiosManager(com.benmu.framework.manager.impl.AxiosManager) FileCallBack(com.benmu.framework.http.okhttp.callback.FileCallBack) File(java.io.File)

Example 40 with Call

use of zipkin2.Call in project MVP by yuchengren.

the class OkHttpUtil method doRequest.

public String doRequest(Request request) throws Exception {
    Call call = mOkHttpClient.newCall(request);
    Response response = call.execute();
    if (response.code() != 200) {
        throw new RuntimeException("OkHttpUtil.doRequest(),response code is +" + response.code());
    }
    ResponseBody responseBody = response.body();
    if (responseBody == null) {
        throw new RuntimeException("OkHttpUtil.doRequest(),response.Body() is null!");
    }
    String responseBodyString = responseBody.string();
    if (responseBodyString == null) {
        throw new RuntimeException("OkHttpUtil.doRequest(),responseBody.string() is null!");
    }
    return responseBodyString;
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) ResponseBody(okhttp3.ResponseBody)

Aggregations

Call (okhttp3.Call)409 Response (okhttp3.Response)309 Request (okhttp3.Request)282 IOException (java.io.IOException)232 Call (retrofit2.Call)134 Callback (okhttp3.Callback)133 OkHttpClient (okhttp3.OkHttpClient)98 Test (org.junit.Test)88 ResponseBody (okhttp3.ResponseBody)76 RequestBody (okhttp3.RequestBody)58 Retrofit (retrofit2.Retrofit)48 Gson (com.google.gson.Gson)47 Response (retrofit2.Response)47 File (java.io.File)44 Headers (okhttp3.Headers)41 Callback (retrofit2.Callback)41 GsonBuilder (com.google.gson.GsonBuilder)40 JSONObject (org.json.JSONObject)39 MockResponse (okhttp3.mockwebserver.MockResponse)38 List (java.util.List)35