Search in sources :

Example 21 with HttpUrl

use of okhttp3.HttpUrl in project okhttp by square.

the class NettyHttpClient method release.

private void release(HttpChannel httpChannel) {
    HttpUrl url;
    synchronized (this) {
        url = backlog.pop();
        if (url == null) {
            // There were no URLs in the backlog. Pool this channel for later.
            freeChannels.push(httpChannel);
            return;
        }
    }
    // We removed a URL from the backlog. Schedule it right away.
    httpChannel.sendRequest(url);
}
Also used : HttpUrl(okhttp3.HttpUrl)

Example 22 with HttpUrl

use of okhttp3.HttpUrl in project retrofit by square.

the class RetrofitTest method baseUrlStringPropagated.

@Test
public void baseUrlStringPropagated() {
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://example.com/").build();
    HttpUrl baseUrl = retrofit.baseUrl();
    assertThat(baseUrl).isEqualTo(HttpUrl.parse("http://example.com/"));
}
Also used : HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 23 with HttpUrl

use of okhttp3.HttpUrl in project retrofit by square.

the class Crawler method crawlPage.

public void crawlPage(HttpUrl url) {
    // Skip hosts that we've visited many times.
    AtomicInteger hostnameCount = new AtomicInteger();
    AtomicInteger previous = hostnames.putIfAbsent(url.host(), hostnameCount);
    if (previous != null)
        hostnameCount = previous;
    if (hostnameCount.incrementAndGet() > 100)
        return;
    // Asynchronously visit URL.
    pageService.get(url).enqueue(new Callback<Page>() {

        @Override
        public void onResponse(Call<Page> call, Response<Page> response) {
            if (!response.isSuccessful()) {
                System.out.println(call.request().url() + ": failed: " + response.code());
                return;
            }
            // Print this page's URL and title.
            Page page = response.body();
            HttpUrl base = response.raw().request().url();
            System.out.println(base + ": " + page.title);
            // Enqueue its links for visiting.
            for (String link : page.links) {
                HttpUrl linkUrl = base.resolve(link);
                if (linkUrl != null && !fetchedUrls.add(linkUrl)) {
                    crawlPage(linkUrl);
                }
            }
        }

        @Override
        public void onFailure(Call<Page> call, Throwable t) {
            System.out.println(call.request().url() + ": failed: " + t);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpUrl(okhttp3.HttpUrl)

Example 24 with HttpUrl

use of okhttp3.HttpUrl in project retrofit by square.

the class RetrofitTest method baseHttpUrlPropagated.

@Test
public void baseHttpUrlPropagated() {
    HttpUrl url = HttpUrl.parse("http://example.com/");
    Retrofit retrofit = new Retrofit.Builder().baseUrl(url).build();
    assertThat(retrofit.baseUrl()).isSameAs(url);
}
Also used : HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Example 25 with HttpUrl

use of okhttp3.HttpUrl in project retrofit by square.

the class RetrofitTest method cloneSharesStatefulInstances.

@Test
public void cloneSharesStatefulInstances() {
    CallAdapter.Factory callAdapter = mock(CallAdapter.Factory.class);
    Converter.Factory converter = mock(Converter.Factory.class);
    HttpUrl baseUrl = server.url("/");
    Executor executor = mock(Executor.class);
    okhttp3.Call.Factory callFactory = mock(okhttp3.Call.Factory.class);
    Retrofit one = new Retrofit.Builder().addCallAdapterFactory(callAdapter).addConverterFactory(converter).baseUrl(baseUrl).callbackExecutor(executor).callFactory(callFactory).build();
    CallAdapter.Factory callAdapter2 = mock(CallAdapter.Factory.class);
    Converter.Factory converter2 = mock(Converter.Factory.class);
    Retrofit two = one.newBuilder().addCallAdapterFactory(callAdapter2).addConverterFactory(converter2).build();
    assertEquals(one.callAdapterFactories().size() + 1, two.callAdapterFactories().size());
    assertThat(two.callAdapterFactories()).contains(callAdapter, callAdapter2);
    assertEquals(one.converterFactories().size() + 1, two.converterFactories().size());
    assertThat(two.converterFactories()).contains(converter, converter2);
    assertSame(baseUrl, two.baseUrl());
    assertSame(executor, two.callbackExecutor());
    assertSame(callFactory, two.callFactory());
}
Also used : Executor(java.util.concurrent.Executor) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Aggregations

HttpUrl (okhttp3.HttpUrl)72 Test (org.junit.Test)55 MockResponse (okhttp3.mockwebserver.MockResponse)53 Request (okhttp3.Request)28 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)25 IOException (java.io.IOException)20 Response (okhttp3.Response)17 MockWebServer (okhttp3.mockwebserver.MockWebServer)17 RequestBody (okhttp3.RequestBody)12 Moshi (com.squareup.moshi.Moshi)6 CookieManager (java.net.CookieManager)6 Call (retrofit2.Call)6 Callback (retrofit2.Callback)6 Response (retrofit2.Response)6 LoginFailedException (com.pokegoapi.exceptions.request.LoginFailedException)5 HttpCookie (java.net.HttpCookie)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 QueryRequest (zipkin.storage.QueryRequest)5 HashMap (java.util.HashMap)4