Example usage for com.squareup.okhttp OkHttpClient OkHttpClient

List of usage examples for com.squareup.okhttp OkHttpClient OkHttpClient

Introduction

In this page you can find the example usage for com.squareup.okhttp OkHttpClient OkHttpClient.

Prototype

public OkHttpClient() 

Source Link

Usage

From source file:org.addhen.smssync.net.BaseHttpClient.java

License:Open Source License

public BaseHttpClient(String url, Context context) {

    this.url = url;
    this.context = context;
    this.params = new ArrayList<>();
    this.header = new HashMap<>();

    httpClient = new OkHttpClient();
    httpClient.setConnectTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS);
    httpClient.setWriteTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS);
    httpClient.setReadTimeout(TIME_OUT_CONNECTION, TimeUnit.SECONDS);
}

From source file:org.alfresco.mobile.android.application.manager.NetworkSingleton.java

License:Apache License

private NetworkSingleton() {
    httpClient = new OkHttpClient();
    httpClient.setConnectionPool(new ConnectionPool(1, 100));
    URL.setURLStreamHandlerFactory(httpClient);
}

From source file:org.alfresco.mobile.android.application.managers.RenditionManagerImpl.java

License:Apache License

public void setSession(AlfrescoSession alfrescoSession) {
    this.session = alfrescoSession;
    if (picasso != null) {
        picasso.shutdown();//from  w w w  . j a  v  a 2  s .c om
    }

    OkHttpClient client = null;
    // Specific to detect if OKhttp is used
    try {
        Class.forName("org.alfresco.mobile.android.platform.network.MobileIronHttpInvoker");
        // OKhttp compatible with MobileIron ?
        client = new OkHttpClient();
    } catch (ClassNotFoundException e) {
        client = NetworkSingleton.getInstance().getHttpClient().clone();
    }
    ImageDownloader imageLoader = new ImageDownloader(client, alfrescoSession);
    Builder builder = new Builder(appContext);
    picasso = builder.downloader(imageLoader).build();
}

From source file:org.alfresco.mobile.android.platform.network.NetworkSingleton.java

License:Apache License

private NetworkSingleton() {
    httpClient = new OkHttpClient();
    httpClient.setConnectionPool(new ConnectionPool(1, 100));
    httpClient.setProtocols(Arrays.asList(Protocol.HTTP_11));
    URL.setURLStreamHandlerFactory(httpClient);
}

From source file:org.amahi.anywhere.server.ApiConnectionDetector.java

License:Open Source License

private OkHttpClient buildHttpClient() {
    OkHttpClient httpClient = new OkHttpClient();

    httpClient.setConnectTimeout(Connection.TIMEOUT, TimeUnit.SECONDS);

    return httpClient;
}

From source file:org.amahi.anywhere.server.ApiModule.java

License:Open Source License

@Provides
@Singleton
OkHttpClient provideHttpClient(Cache httpCache) {
    OkHttpClient httpClient = new OkHttpClient();

    httpClient.setCache(httpCache);

    return httpClient;
}

From source file:org.amahi.anywhere.util.FileDownloader.java

License:Open Source License

private InputStream buildRemoteFileStream(Uri remoteFileUri) {
    try {/*from w ww. ja v a  2s  . c  om*/
        URL remoteFileUrl = new URL(remoteFileUri.toString());

        return new OkHttpClient().open(remoteFileUrl).getInputStream();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.hadoop.hdfs.web.oauth2.ConfRefreshTokenBasedAccessTokenProvider.java

License:Apache License

void refresh() throws IOException {
    try {/*from w  w  w  .  jav a 2s  . c  o m*/
        OkHttpClient client = new OkHttpClient();
        client.setConnectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
        client.setReadTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);

        String bodyString = Utils.postBody(GRANT_TYPE, REFRESH_TOKEN, REFRESH_TOKEN, refreshToken, CLIENT_ID,
                clientId);

        RequestBody body = RequestBody.create(URLENCODED, bodyString);

        Request request = new Request.Builder().url(refreshURL).post(body).build();
        Response responseBody = client.newCall(request).execute();

        if (responseBody.code() != HttpStatus.SC_OK) {
            throw new IllegalArgumentException("Received invalid http response: " + responseBody.code()
                    + ", text = " + responseBody.toString());
        }

        Map<?, ?> response = READER.readValue(responseBody.body().string());

        String newExpiresIn = response.get(EXPIRES_IN).toString();
        accessTokenTimer.setExpiresIn(newExpiresIn);

        accessToken = response.get(ACCESS_TOKEN).toString();
    } catch (Exception e) {
        throw new IOException("Exception while refreshing access token", e);
    }
}

From source file:org.apache.hadoop.hdfs.web.oauth2.CredentialBasedAccessTokenProvider.java

License:Apache License

void refresh() throws IOException {
    try {//ww  w  .j  av  a  2 s  .  co m
        OkHttpClient client = new OkHttpClient();
        client.setConnectTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
        client.setReadTimeout(URLConnectionFactory.DEFAULT_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);

        String bodyString = Utils.postBody(CLIENT_SECRET, getCredential(), GRANT_TYPE, CLIENT_CREDENTIALS,
                CLIENT_ID, clientId);

        RequestBody body = RequestBody.create(URLENCODED, bodyString);

        Request request = new Request.Builder().url(refreshURL).post(body).build();
        Response responseBody = client.newCall(request).execute();

        if (responseBody.code() != HttpStatus.SC_OK) {
            throw new IllegalArgumentException("Received invalid http response: " + responseBody.code()
                    + ", text = " + responseBody.toString());
        }

        Map<?, ?> response = READER.readValue(responseBody.body().string());

        String newExpiresIn = response.get(EXPIRES_IN).toString();
        timer.setExpiresIn(newExpiresIn);

        accessToken = response.get(ACCESS_TOKEN).toString();

    } catch (Exception e) {
        throw new IOException("Unable to obtain access token from credential", e);
    }
}

From source file:org.apache.nifi.minifi.bootstrap.configuration.notifiers.TestRestChangeNotifier.java

License:Apache License

@BeforeClass
public static void setUp() throws InterruptedException, MalformedURLException {
    Properties properties = new Properties();
    restChangeNotifier = new RestChangeNotifier();
    restChangeNotifier.initialize(properties);
    restChangeNotifier.registerListener(mockChangeListener);
    restChangeNotifier.start();//ww w .  java 2s  . co m

    client = new OkHttpClient();

    url = restChangeNotifier.getURI().toURL().toString();
    Thread.sleep(1000);
}