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);
}
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/"));
}
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);
}
});
}
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);
}
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());
}
Aggregations