Android Open Source - android-rest-client Rest Client Configuration






From Project

Back to project page android-rest-client.

License

The source code is released under:

Apache License

If you think the Android project android-rest-client 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 com.dg.libs.rest;
// w  w  w .j a  v a2s  .c o m
import android.content.Context;
import com.araneaapps.android.libs.asyncrunners.models.AsyncRunners;
import com.dg.libs.rest.authentication.AuthenticationProvider;

public class RestClientConfiguration {

  private static Context applicationContext;
  private AuthenticationProvider authenticationProvider;
  int connectionTimeout;
  int socketTimeout;

  private RestClientConfiguration(AuthenticationProvider authenticationProvider, int connectionTimeout, int socketTimeout) {
    this.authenticationProvider = authenticationProvider;
    this.connectionTimeout = connectionTimeout;
    this.socketTimeout = socketTimeout;
  }


  private static RestClientConfiguration generateDefaultConfig() {
    return new ConfigurationBuilder().create();
  }

  private static RestClientConfiguration instance;

  public static void init(Context context) {
    applicationContext = context.getApplicationContext();
    AsyncRunners.init(applicationContext);
    instance = generateDefaultConfig();
  }
  public static void init(Context context, RestClientConfiguration restClientConfiguration) {
    applicationContext = context.getApplicationContext();
    AsyncRunners.init(applicationContext);
    instance = restClientConfiguration;
  }

  public static RestClientConfiguration get() {
    if (instance == null) {
      throw new IllegalStateException("You need to call Init on " + RestClientConfiguration.class + " First. Do it in your class extending application");
    }
    return instance;
  }


  public AuthenticationProvider getAuthenticationProvider() {
    return authenticationProvider;
  }

  public int getConnectionTimeout() {
    return connectionTimeout;
  }

  public int getSocketTimeout() {
    return socketTimeout;
  }

  public Context getContext() {
    return applicationContext;
  }

  public static class ConfigurationBuilder {
    private AuthenticationProvider authenticationProvider;
    private int connectionTimeout = 10000;
    private int socketTimeout = 20000;

    public ConfigurationBuilder setAuthenticationProvider(AuthenticationProvider authenticationProvider) {
      this.authenticationProvider = authenticationProvider;
      return this;
    }

    public ConfigurationBuilder setConnectionTimeout(int connectionTimeout) {
      this.connectionTimeout = connectionTimeout;
      return this;
    }

    public ConfigurationBuilder setSocketTimeout(int socketTimeout) {
      this.socketTimeout = socketTimeout;
      return this;
    }

    public RestClientConfiguration create() {
      return new RestClientConfiguration(authenticationProvider, connectionTimeout, socketTimeout);
    }
  }
}




Java Source Code List

com.dg.examples.restclientdemo.MainActivity.java
com.dg.examples.restclientdemo.app.App.java
com.dg.examples.restclientdemo.communication.RestConstants.java
com.dg.examples.restclientdemo.communication.parsers.BlogsGoogleParser.java
com.dg.examples.restclientdemo.communication.requests.BlogsGoogleRequest.java
com.dg.examples.restclientdemo.communication.requests.CustomHandlersRequest.java
com.dg.examples.restclientdemo.communication.requests.PatchRequest.java
com.dg.examples.restclientdemo.domain.EntriesModel.java
com.dg.examples.restclientdemo.domain.ResponseDataModel.java
com.dg.examples.restclientdemo.domain.ResponseModel.java
com.dg.libs.rest.HttpRequest.java
com.dg.libs.rest.RestClientConfiguration.java
com.dg.libs.rest.authentication.AuthenticationProvider.java
com.dg.libs.rest.authentication.TokenAuthenticationProvider.java
com.dg.libs.rest.callbacks.HttpCallback.java
com.dg.libs.rest.client.RequestMethod.java
com.dg.libs.rest.domain.ResponseStatus.java
com.dg.libs.rest.entities.CountingInputStreamEntity.java
com.dg.libs.rest.entities.UnicodeBOMInputStream.java
com.dg.libs.rest.exceptions.HttpException.java
com.dg.libs.rest.exceptions.ParseException.java
com.dg.libs.rest.handlers.BackgroundThreadResponseHandler.java
com.dg.libs.rest.handlers.DefaultResponseStatusHandler.java
com.dg.libs.rest.handlers.ResponseHandler.java
com.dg.libs.rest.handlers.ResponseStatusHandler.java
com.dg.libs.rest.handlers.UIThreadResponseHandler.java
com.dg.libs.rest.parsers.BaseJacksonMapperResponseParser.java
com.dg.libs.rest.parsers.FileHttpResponseParser.java
com.dg.libs.rest.parsers.HttpResponseParser.java
com.dg.libs.rest.parsers.NoResponseParser.java
com.dg.libs.rest.parsers.StringHttpResponseParser.java
com.dg.libs.rest.requests.RequestBodyUtils.java
com.dg.libs.rest.requests.RestClientRequest.java