|
@ -1,11 +1,19 @@ |
|
|
package com.nivesh.production.bajajfd.api |
|
|
package com.nivesh.production.bajajfd.api |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
|
import com.nivesh.production.bajajfd.R |
|
|
import com.nivesh.production.bajajfd.interfaces.ApiInterface |
|
|
import com.nivesh.production.bajajfd.interfaces.ApiInterface |
|
|
import com.nivesh.production.bajajfd.util.Constants.Companion.BASE_URL |
|
|
import com.nivesh.production.bajajfd.util.Constants.Companion.BASE_URL |
|
|
import okhttp3.OkHttpClient |
|
|
import okhttp3.OkHttpClient |
|
|
import okhttp3.logging.HttpLoggingInterceptor |
|
|
import okhttp3.logging.HttpLoggingInterceptor |
|
|
import retrofit2.Retrofit |
|
|
import retrofit2.Retrofit |
|
|
import retrofit2.converter.gson.GsonConverterFactory |
|
|
import retrofit2.converter.gson.GsonConverterFactory |
|
|
|
|
|
import java.security.KeyStore |
|
|
|
|
|
import java.security.SecureRandom |
|
|
|
|
|
import java.util.* |
|
|
|
|
|
import java.util.concurrent.TimeUnit |
|
|
|
|
|
import javax.net.ssl.* |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApiClient { |
|
|
class ApiClient { |
|
|
companion object { |
|
|
companion object { |
|
@ -16,8 +24,25 @@ class ApiClient { |
|
|
logging.setLevel(HttpLoggingInterceptor.Level.BODY) |
|
|
logging.setLevel(HttpLoggingInterceptor.Level.BODY) |
|
|
//see the body of response |
|
|
//see the body of response |
|
|
//create client for retrofit |
|
|
//create client for retrofit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val trustManagerFactory: TrustManagerFactory = |
|
|
|
|
|
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()) |
|
|
|
|
|
trustManagerFactory.init(null as KeyStore?) |
|
|
|
|
|
val trustManagers: Array<TrustManager> = trustManagerFactory.getTrustManagers() |
|
|
|
|
|
check(!(trustManagers.size != 1 || trustManagers[0] !is X509TrustManager)) { |
|
|
|
|
|
"Unexpected default trust managers:" + Arrays.toString( |
|
|
|
|
|
trustManagers |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
val trustManager: X509TrustManager = trustManagers[0] as X509TrustManager |
|
|
|
|
|
val sslContext = SSLContext.getInstance("SSL") |
|
|
|
|
|
sslContext.init(null, arrayOf(trustManager), null) |
|
|
|
|
|
val sslSocketFactory: SSLSocketFactory = sslContext.socketFactory |
|
|
|
|
|
|
|
|
val client = OkHttpClient.Builder() |
|
|
val client = OkHttpClient.Builder() |
|
|
.addInterceptor(logging) |
|
|
.addInterceptor(logging) |
|
|
|
|
|
.sslSocketFactory(sslSocketFactory, trustManager) |
|
|
.retryOnConnectionFailure(true) |
|
|
.retryOnConnectionFailure(true) |
|
|
.build() |
|
|
.build() |
|
|
Retrofit.Builder() |
|
|
Retrofit.Builder() |
|
|