use of okhttp3.Dns in project zipkin by openzipkin.
the class PseudoAddressRecordSet method create.
static Dns create(List<String> urls, Dns actualDns) {
Set<String> schemes = new LinkedHashSet<>();
Set<String> hosts = new LinkedHashSet<>();
Set<InetAddress> ipAddresses = new LinkedHashSet<>();
Set<Integer> ports = new LinkedHashSet<>();
for (String url : urls) {
HttpUrl httpUrl = HttpUrl.parse(url);
schemes.add(httpUrl.scheme());
// Kick out if we can't cheaply read the address
byte[] addressBytes = null;
try {
addressBytes = ipStringToBytes(httpUrl.host());
} catch (RuntimeException e) {
}
if (addressBytes != null) {
try {
ipAddresses.add(InetAddress.getByAddress(addressBytes));
} catch (UnknownHostException e) {
hosts.add(httpUrl.host());
}
} else {
hosts.add(httpUrl.host());
}
ports.add(httpUrl.port());
}
checkArgument(ports.size() == 1, "Only one port supported with multiple hosts %s", urls);
checkArgument(schemes.size() == 1 && schemes.iterator().next().equals("http"), "Only http supported with multiple hosts %s", urls);
if (hosts.isEmpty())
return new StaticDns(ipAddresses);
return new ConcatenatingDns(ipAddresses, hosts, actualDns);
}
use of okhttp3.Dns in project zipkin by openzipkin.
the class PseudoAddressRecordSetTest method concatenatesMixedIpLengths.
@Test
public void concatenatesMixedIpLengths() throws UnknownHostException {
Dns result = PseudoAddressRecordSet.create(asList("http://1.1.1.1:9200", "http://[2001:db8::c001]:9200"), underlying);
assertThat(result).isInstanceOf(PseudoAddressRecordSet.StaticDns.class);
assertThat(result.lookup("foo")).containsExactly(InetAddresses.forString("1.1.1.1"), InetAddresses.forString("2001:db8::c001"));
}
use of okhttp3.Dns in project zipkin by openzipkin.
the class ElasticsearchHttpStorage method http.
// hosts resolution might imply a network call, and we might make a new okhttp instance
@Memoized
HttpCall.Factory http() {
List<String> hosts = hostsSupplier().get();
if (hosts.isEmpty())
throw new IllegalArgumentException("no hosts configured");
OkHttpClient ok = hosts.size() == 1 ? client() : client().newBuilder().dns(PseudoAddressRecordSet.create(hosts, client().dns())).build();
ok.dispatcher().setMaxRequests(maxRequests());
ok.dispatcher().setMaxRequestsPerHost(maxRequests());
return new HttpCall.Factory(ok, HttpUrl.parse(hosts.get(0)));
}
use of okhttp3.Dns in project azure-sdk-for-java by Azure.
the class EndpointsInner method validateCustomDomainWithServiceResponseAsync.
/**
* Validates the custom domain mapping to ensure it maps to the correct CDN endpoint in DNS.
*
* @param resourceGroupName Name of the Resource group within the Azure subscription.
* @param profileName Name of the CDN profile which is unique within the resource group.
* @param endpointName Name of the endpoint under the profile which is unique globally.
* @param hostName The host name of the custom domain. Must be a domain name.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the ValidateCustomDomainOutputInner object
*/
public Observable<ServiceResponse<ValidateCustomDomainOutputInner>> validateCustomDomainWithServiceResponseAsync(String resourceGroupName, String profileName, String endpointName, String hostName) {
if (resourceGroupName == null) {
throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
}
if (profileName == null) {
throw new IllegalArgumentException("Parameter profileName is required and cannot be null.");
}
if (endpointName == null) {
throw new IllegalArgumentException("Parameter endpointName is required and cannot be null.");
}
if (this.client.subscriptionId() == null) {
throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
}
if (this.client.apiVersion() == null) {
throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
}
if (hostName == null) {
throw new IllegalArgumentException("Parameter hostName is required and cannot be null.");
}
ValidateCustomDomainInput customDomainProperties = new ValidateCustomDomainInput();
customDomainProperties.withHostName(hostName);
return service.validateCustomDomain(resourceGroupName, profileName, endpointName, this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), customDomainProperties, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<ValidateCustomDomainOutputInner>>>() {
@Override
public Observable<ServiceResponse<ValidateCustomDomainOutputInner>> call(Response<ResponseBody> response) {
try {
ServiceResponse<ValidateCustomDomainOutputInner> clientResponse = validateCustomDomainDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
use of okhttp3.Dns in project Signal-Android by WhisperSystems.
the class SubmitDebugLogRepository method uploadContent.
@WorkerThread
@NonNull
private String uploadContent(@NonNull String contentType, @NonNull RequestBody requestBody) throws IOException {
try {
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new StandardUserAgentInterceptor()).dns(SignalServiceNetworkAccess.DNS).build();
Response response = client.newCall(new Request.Builder().url(API_ENDPOINT).get().build()).execute();
ResponseBody body = response.body();
if (!response.isSuccessful() || body == null) {
throw new IOException("Unsuccessful response: " + response);
}
JSONObject json = new JSONObject(body.string());
String url = json.getString("url");
JSONObject fields = json.getJSONObject("fields");
String item = fields.getString("key");
MultipartBody.Builder post = new MultipartBody.Builder();
Iterator<String> keys = fields.keys();
post.addFormDataPart("Content-Type", contentType);
while (keys.hasNext()) {
String key = keys.next();
post.addFormDataPart(key, fields.getString(key));
}
post.addFormDataPart("file", "file", requestBody);
Response postResponse = client.newCall(new Request.Builder().url(url).post(post.build()).build()).execute();
if (!postResponse.isSuccessful()) {
throw new IOException("Bad response: " + postResponse);
}
return API_ENDPOINT + "/" + item;
} catch (JSONException e) {
Log.w(TAG, "Error during upload.", e);
throw new IOException(e);
}
}
Aggregations