Search in sources :

Example 11 with Address

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!");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Proxy(java.net.Proxy) InetSocketAddress(java.net.InetSocketAddress) RecordingProxySelector(okhttp3.internal.http.RecordingProxySelector) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 12 with Address

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"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SslClient(okhttp3.internal.tls.SslClient) HeldCertificate(okhttp3.internal.tls.HeldCertificate) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Test(org.junit.Test)

Example 13 with Address

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;
}
Also used : OrganizationAddress(org.orcid.jaxb.model.common_v2.OrganizationAddress) Address(org.orcid.jaxb.model.record_v2.Address) Country(org.orcid.jaxb.model.common_v2.Country) Iso3166Country(org.orcid.jaxb.model.common_v2.Iso3166Country)

Example 14 with 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;
}
Also used : Keywords(org.orcid.jaxb.model.record_v2.Keywords) Email(org.orcid.jaxb.model.record_v2.Email) Address(org.orcid.jaxb.model.record_v2.Address) Keyword(org.orcid.jaxb.model.record_v2.Keyword) OtherNames(org.orcid.jaxb.model.record_v2.OtherNames) OtherName(org.orcid.jaxb.model.record_v2.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) Addresses(org.orcid.jaxb.model.record_v2.Addresses) PersonExternalIdentifiers(org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers) ResearcherUrls(org.orcid.jaxb.model.record_v2.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) Emails(org.orcid.jaxb.model.record_v2.Emails) Person(org.orcid.jaxb.model.record_v2.Person)

Example 15 with Address

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;
}
Also used : Addresses(org.orcid.jaxb.model.record_v2.Addresses) Address(org.orcid.jaxb.model.record_v2.Address) ArrayList(java.util.ArrayList)

Aggregations

Test (org.junit.Test)92 Address (org.orcid.jaxb.model.record_v2.Address)84 Keyword (org.orcid.jaxb.model.record_v2.Keyword)44 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)44 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)44 OtherName (org.orcid.jaxb.model.record_v2.OtherName)43 Addresses (org.orcid.jaxb.model.record_v2.Addresses)42 Email (org.orcid.jaxb.model.record_v2.Email)41 Biography (org.orcid.jaxb.model.record_v2.Biography)34 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)34 Emails (org.orcid.jaxb.model.record_v2.Emails)32 Keywords (org.orcid.jaxb.model.record_v2.Keywords)32 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)32 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)32 Name (org.orcid.jaxb.model.record_v2.Name)30 Person (org.orcid.jaxb.model.record_v2.Person)30 DBUnitTest (org.orcid.test.DBUnitTest)20 Response (javax.ws.rs.core.Response)18 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)18