Android Open Source - hello-pinnedcerts Retrofit Apache Client Builder






From Project

Back to project page hello-pinnedcerts.

License

The source code is released under:

Copyright (c) 2014 Ivan Ku?t Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwar...

If you think the Android project hello-pinnedcerts listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package co.infinum.https;
/*w  ww.  j  av a 2s  .  c o  m*/
import android.content.res.Resources;

import org.apache.http.client.CookieStore;
import org.apache.http.conn.scheme.SocketFactory;

import java.io.IOException;
import java.io.InputStream;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

import retrofit.client.ApacheClient;
import retrofit.client.Client;

/**
 * Builder for creating Apache HttpClient with pinned certificate that can be used with Retrofit.
 */
public class RetrofitApacheClientBuilder {

    protected HttpClientBuilder httpClientBuilder = new HttpClientBuilder();

    public RetrofitApacheClientBuilder setConnectionTimeout(int connectionTimeout) {
        httpClientBuilder.setConnectionTimeout(connectionTimeout);

        return this;
    }

    public RetrofitApacheClientBuilder setSocketTimeout(int socketTimeout) {
        httpClientBuilder.setSocketTimeout(socketTimeout);

        return this;
    }

    public RetrofitApacheClientBuilder setCookieStore(CookieStore cookieStore) {
        httpClientBuilder.setCookieStore(cookieStore);

        return this;
    }

    public RetrofitApacheClientBuilder pinCertificates(InputStream resourceStream, char[] password) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
        httpClientBuilder.pinCertificates(resourceStream, password);

        return this;
    }

    public RetrofitApacheClientBuilder pinCertificates(Resources resources, int certificateRawResource, char[] password) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException {
        httpClientBuilder.pinCertificates(resources, certificateRawResource, password);

        return this;
    }

    public RetrofitApacheClientBuilder ignoreCertificates() {
        httpClientBuilder.ignoreCertificates();

        return this;
    }

    public RetrofitApacheClientBuilder registerScheme(String name, SocketFactory factory, int port) {
        httpClientBuilder.registerScheme(name, factory, port);

        return this;
    }

    public RetrofitApacheClientBuilder setHttpPort(int port) {
        httpClientBuilder.setHttpPort(port);

        return this;
    }

    public RetrofitApacheClientBuilder setHttpsPort(int port) {
        httpClientBuilder.setHttpsPort(port);

        return this;
    }

    public Client.Provider build() {

        return new Client.Provider() {

            public Client get() {
                return new ApacheClient(httpClientBuilder.build());
            }
        };
    }
}




Java Source Code List

co.infinum.https.CustomTrustManager.java
co.infinum.https.HttpClientBuilder.java
co.infinum.https.IgnorantHttpClient.java
co.infinum.https.MainActivity.java
co.infinum.https.RetrofitApacheClientBuilder.java
co.infinum.https.RetrofitClientBuilder.java
co.infinum.https.retrofit.GitHubService.java
co.infinum.https.retrofit.Logger.java
co.infinum.https.retrofit.User.java