use of okhttp3.Address in project okhttp by square.
the class CallTest method connectTimeoutsAttemptsAlternateRoute.
/**
* Make a request with two routes. The first route will time out because it's connecting to a
* special address that never connects. The automatic retry will succeed.
*/
@Test
public void connectTimeoutsAttemptsAlternateRoute() throws Exception {
InetSocketAddress unreachableAddress = new InetSocketAddress("10.255.255.1", 8080);
RecordingProxySelector proxySelector = new RecordingProxySelector();
proxySelector.proxies.add(new Proxy(Proxy.Type.HTTP, unreachableAddress));
proxySelector.proxies.add(server.toProxyAddress());
server.enqueue(new MockResponse().setBody("success!"));
client = client.newBuilder().proxySelector(proxySelector).readTimeout(100, TimeUnit.MILLISECONDS).connectTimeout(100, TimeUnit.MILLISECONDS).build();
Request request = new Request.Builder().url("http://android.com/").build();
executeSynchronously(request).assertCode(200).assertBody("success!");
}
use of okhttp3.Address in project okhttp by square.
the class CallTest method httpsWithIpAddress.
@Test
public void httpsWithIpAddress() throws Exception {
String localIpAddress = InetAddress.getLoopbackAddress().getHostAddress();
// Create a certificate with an IP address in the subject alt name.
HeldCertificate heldCertificate = new HeldCertificate.Builder().commonName("example.com").subjectAlternativeName(localIpAddress).build();
SslClient sslClient = new SslClient.Builder().certificateChain(heldCertificate.keyPair, heldCertificate.certificate).addTrustedCertificate(heldCertificate.certificate).build();
// Use that certificate on the server and trust it on the client.
server.useHttps(sslClient.socketFactory, false);
client = client.newBuilder().sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(new RecordingHostnameVerifier()).protocols(Collections.singletonList(Protocol.HTTP_1_1)).build();
// Make a request.
server.enqueue(new MockResponse());
HttpUrl url = server.url("/").newBuilder().host(localIpAddress).build();
Request request = new Request.Builder().url(url).build();
executeSynchronously(request).assertCode(200);
// Confirm that the IP address was used in the host header.
RecordedRequest recordedRequest = server.takeRequest();
assertEquals(localIpAddress + ":" + server.getPort(), recordedRequest.getHeader("Host"));
}
use of okhttp3.Address in project ORCID-Source by ORCID.
the class Utils method getAddress.
public static Address getAddress() {
Address address = new Address();
address.setVisibility(Visibility.PUBLIC);
address.setCountry(new Country(Iso3166Country.ES));
return address;
}
use of okhttp3.Address in project ORCID-Source by ORCID.
the class PersonDetailsManagerReadOnlyImpl method getPersonDetails.
@Override
public Person getPersonDetails(String orcid) {
long lastModifiedTime = getLastModified(orcid);
Person person = new Person();
person.setName(recordNameManager.getRecordName(orcid, lastModifiedTime));
person.setBiography(biographyManager.getBiography(orcid, lastModifiedTime));
Addresses addresses = addressManager.getAddresses(orcid, lastModifiedTime);
if (addresses.getAddress() != null) {
Addresses filteredAddresses = new Addresses();
filteredAddresses.setAddress(new ArrayList<Address>(addresses.getAddress()));
person.setAddresses(filteredAddresses);
}
PersonExternalIdentifiers extIds = externalIdentifierManager.getExternalIdentifiers(orcid, lastModifiedTime);
if (extIds.getExternalIdentifiers() != null) {
PersonExternalIdentifiers filteredExtIds = new PersonExternalIdentifiers();
filteredExtIds.setExternalIdentifiers(new ArrayList<PersonExternalIdentifier>(extIds.getExternalIdentifiers()));
person.setExternalIdentifiers(filteredExtIds);
}
Keywords keywords = profileKeywordManager.getKeywords(orcid, lastModifiedTime);
if (keywords.getKeywords() != null) {
Keywords filteredKeywords = new Keywords();
filteredKeywords.setKeywords(new ArrayList<Keyword>(keywords.getKeywords()));
person.setKeywords(filteredKeywords);
}
OtherNames otherNames = otherNameManager.getOtherNames(orcid, lastModifiedTime);
if (otherNames.getOtherNames() != null) {
OtherNames filteredOtherNames = new OtherNames();
filteredOtherNames.setOtherNames(new ArrayList<OtherName>(otherNames.getOtherNames()));
person.setOtherNames(filteredOtherNames);
}
ResearcherUrls rUrls = researcherUrlManager.getResearcherUrls(orcid, lastModifiedTime);
if (rUrls.getResearcherUrls() != null) {
ResearcherUrls filteredRUrls = new ResearcherUrls();
filteredRUrls.setResearcherUrls(new ArrayList<ResearcherUrl>(rUrls.getResearcherUrls()));
person.setResearcherUrls(filteredRUrls);
}
Emails emails = emailManager.getEmails(orcid, lastModifiedTime);
if (emails.getEmails() != null) {
Emails filteredEmails = new Emails();
filteredEmails.setEmails(new ArrayList<Email>(emails.getEmails()));
person.setEmails(filteredEmails);
}
return person;
}
use of okhttp3.Address in project ORCID-Source by ORCID.
the class AddressesForm method toAddresses.
public Addresses toAddresses() {
Addresses result = new Addresses();
if (addresses != null) {
List<Address> addressList = new ArrayList<Address>();
for (AddressForm form : addresses) {
addressList.add(form.toAddress());
}
result.setAddress(addressList);
}
return result;
}
Aggregations