本文整理汇总了Java中com.franmontiel.persistentcookiejar.ClearableCookieJar类的典型用法代码示例。如果您正苦于以下问题:Java ClearableCookieJar类的具体用法?Java ClearableCookieJar怎么用?Java ClearableCookieJar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClearableCookieJar类属于com.franmontiel.persistentcookiejar包,在下文中一共展示了ClearableCookieJar类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Log.i(TAG, String.format("Using Kolibri %s version", BuildConfig.VERSION_NAME));
final DisplayMetrics lDisplayMetrics = getResources().getDisplayMetrics();
viewportWidthPixels = Math.round(lDisplayMetrics.widthPixels / lDisplayMetrics.density);
viewportHeightPixels = Math.round(lDisplayMetrics.heightPixels / lDisplayMetrics.density);
final ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(),
new SharedPrefsCookiePersistor(this));
instance = this;
netmetrixClient = new OkHttpClient.Builder().cookieJar(cookieJar).build();
}
示例2: init
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
/**
* @param context
* @param baseUrl
* @return
*/
public AntCloud init(Context context, String baseUrl) {
mManager = new AntCloudSubscription();
mHttpClientBuilder = new OkHttpClient.Builder();
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context));
mHttpClientBuilder.connectTimeout(timeout == 0 ? DEFAULT_TIMEOUT : timeout, TimeUnit.SECONDS);
mHttpClientBuilder.cookieJar(cookieJar);//添加cookie 持久化管理
addInterceptor(new LoggingInterceptor());//添加日志打印
mRetrofit = new Retrofit.Builder()
.client(mHttpClientBuilder.build())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(baseUrl)
.build();
return this;
}
示例3: HttpClient
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
private HttpClient() {
ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(Utils.getContext()));
//HttpsUtil.SSLParams sslParams = HttpsUtil.getSslSocketFactory(Utils.getContext(), R.raw.cer,STORE_PASS , STORE_ALIAS);
okHttpClient = new OkHttpClient.Builder()
.connectTimeout(10000L, TimeUnit.MILLISECONDS)
//.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
// .hostnameVerifier(HttpsUtil.getHostnameVerifier())
.addInterceptor(new LoggerInterceptor(null, true))
.cookieJar(cookieJar)
.build();
}
示例4: onCreate
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
@Override
public void onCreate()
{
super.onCreate();
ClearableCookieJar cookieJar1 = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext()));
HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);
// CookieJarImpl cookieJar1 = new CookieJarImpl(new MemoryCookieStore());
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(10000L, TimeUnit.MILLISECONDS)
.readTimeout(10000L, TimeUnit.MILLISECONDS)
.addInterceptor(new LoggerInterceptor("TAG"))
.cookieJar(cookieJar1)
.hostnameVerifier(new HostnameVerifier()
{
@Override
public boolean verify(String hostname, SSLSession session)
{
return true;
}
})
.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
.build();
OkHttpUtils.initClient(okHttpClient);
}
示例5: getRetrofit
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
public Retrofit getRetrofit() {
// 指定缓存路径,缓存大小 50Mb
Cache cache = new Cache(new File(mContext.getCacheDir(), "HttpCache"),
1024 * 1024 * 50);
// Cookie 持久化
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(mContext));
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cookieJar(cookieJar)
.cache(cache)
.addInterceptor(cacheControlInterceptor)
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.retryOnConnectionFailure(true);
// Log 拦截器
if (BuildConfig.DEBUG) {
builder = SdkManager.initInterceptor(builder);
}
return new Retrofit.Builder()
.baseUrl(IApi.API_BASE)
.client(builder.build())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
示例6: getRetrofit
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
public static Retrofit getRetrofit() {
if (sRetrofit == null) {
synchronized (RetrofitFactory.class) {
if (sRetrofit == null) {
// 指定缓存路径,缓存大小 50Mb
Cache cache = new Cache(new File(App.sAppContext.getCacheDir(), "HttpCache"),
1024 * 1024 * 50);
// Cookie 持久化
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(App.sAppContext));
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cookieJar(cookieJar)
.cache(cache)
.addInterceptor(cacheControlInterceptor)
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.retryOnConnectionFailure(true);
// Log 拦截器
if (BuildConfig.DEBUG) {
builder = SdkManager.initInterceptor(builder);
}
sRetrofit = new Retrofit.Builder()
.baseUrl(IApi.API_BASE)
.client(builder.build())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
}
}
return sRetrofit;
}
示例7: init
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
public void init(Context context, String dns, boolean sslOrTls) {
// init gson
gson = new GsonBuilder()
.setDateFormat("EEE, dd MMM yyyy HH:mm:ss Z")
.setPrettyPrinting()
.registerTypeAdapter(User.class, new UserSerializer())
.create();
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context));
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(CONNECT_TIMEOUT, TimeUnit.MINUTES)
.readTimeout(READ_TIMEOUT, TimeUnit.MINUTES)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.MINUTES)
.addInterceptor(interceptor)
//.addNetworkInterceptor(new StethoInterceptor())
.cookieJar(cookieJar)
.build();
apiInterface = new Retrofit.Builder()
.baseUrl("{protocol}://{dns}/traccar/rest/".replace("{protocol}", sslOrTls ? "https" : "http").replace("{dns}", dns))
.client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build().create(ApiInterface.class);
}
示例8: provideOkHttpClient
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
@Provides
@Singleton
public OkHttpClient provideOkHttpClient(ClearableCookieJar cookieJar, HttpLoggingInterceptor interceptor) {
return new OkHttpClient().newBuilder()
.connectTimeout(CONNECT_TIMEOUT, TimeUnit.MINUTES)
.readTimeout(READ_TIMEOUT, TimeUnit.MINUTES)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.MINUTES)
.cookieJar(cookieJar)
//.addInterceptor(interceptor)
.addNetworkInterceptor(new StethoInterceptor())
.build();
}
示例9: onCreate
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
//持久化存储cookie
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getApplicationContext()));
//log拦截器
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
//自定义OkHttp
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.connectTimeout(10000L, TimeUnit.MILLISECONDS)
.readTimeout(10000L, TimeUnit.MILLISECONDS)
.cookieJar(cookieJar) //设置开启cookie
.addInterceptor(logging) //设置开启log
.build();
mMyOkHttp = new MyOkHttp(okHttpClient);
//默认
// mMyOkHttp = new MyOkHttp();
mDownloadMgr = (DownloadMgr) new DownloadMgr.Builder()
.myOkHttp(mMyOkHttp)
.maxDownloadIngNum(5) //设置最大同时下载数量(不设置默认5)
.saveProgressBytes(50 * 1204) //设置每50kb触发一次saveProgress保存进度 (不能在onProgress每次都保存 过于频繁) 不设置默认50kb
.build();
mDownloadMgr.resumeTasks(); //恢复本地所有未完成的任务
}
示例10: getRetrofit
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
@NonNull
public static Retrofit getRetrofit() {
if (retrofit == null) {
synchronized (RetrofitFactory.class) {
if (retrofit == null) {
// 指定缓存路径,缓存大小 50Mb
Cache cache = new Cache(new File(InitApp.AppContext.getCacheDir(), "HttpCache"),
1024 * 1024 * 50);
// Cookie 持久化
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(InitApp.AppContext));
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cookieJar(cookieJar)
.cache(cache)
.addInterceptor(cacheControlInterceptor)
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
.retryOnConnectionFailure(true);
// Log 拦截器
if (BuildConfig.DEBUG) {
builder = SdkManager.initInterceptor(builder);
}
retrofit = new Retrofit.Builder()
.baseUrl(INewsApi.HOST)
.client(builder.build())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
}
}
return retrofit;
}
示例11: provideClearableCookieJar
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
@Provides
@Singleton
public ClearableCookieJar provideClearableCookieJar(Context context) {
return new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context));
}
示例12: getClearableCookieJar
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
@NonNull
public static ClearableCookieJar getClearableCookieJar() {
return mClearableCookieJar;
}
示例13: getOkClient
import com.franmontiel.persistentcookiejar.ClearableCookieJar; //导入依赖的package包/类
public static OkHttpClient getOkClient(Context c) {
if (client != null) {
return client;
}
final CertificatePinner certificatePinner = new CertificatePinner.Builder()
.add(API_HOSTNAME, "sha256/dVphPQ9xG7woPpEKXrNalw4eMUQ4Fw9r3OXTzxfuL5A=") //Fakultaet fuer Informatik
.add(API_HOSTNAME, "sha256/SwdQoHL7SB/6o12XsIhbQJ9bANVnbrJoHTLzlu/qXT0=") //Technische Universitaet Muenchen
.add(API_HOSTNAME, "sha256/VzL+FtAKvzb4N5igmFJyv83GD7CBK7Yyw+R6XdRRfmg=") //DFN-Verein PCA Global
.add(API_HOSTNAME, "sha256/0d4q5hyN8vpiOWYWPUxz1GC/xCjldYW+a/65pWMj0bY=") //Deutsche Telekom Root CA 2
.add(API_HOSTNAME, "sha256/YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=") //Let's Encrypt Authority X3
.add(API_HOSTNAME, "sha256/Vjs8r4z+80wjNcr1YKepWQboSIRi63WsWXhIMN+eWys=") //LE Cross Sign: DST Root CA X3
.add(API_HOSTNAME_NEW, "sha256/dVphPQ9xG7woPpEKXrNalw4eMUQ4Fw9r3OXTzxfuL5A=") //Fakultaet fuer Informatik
.add(API_HOSTNAME_NEW, "sha256/SwdQoHL7SB/6o12XsIhbQJ9bANVnbrJoHTLzlu/qXT0=") //Technische Universitaet Muenchen
.add(API_HOSTNAME_NEW, "sha256/VzL+FtAKvzb4N5igmFJyv83GD7CBK7Yyw+R6XdRRfmg=") //DFN-Verein PCA Global
.add(API_HOSTNAME_NEW, "sha256/0d4q5hyN8vpiOWYWPUxz1GC/xCjldYW+a/65pWMj0bY=") //Deutsche Telekom Root CA 2
.add(API_HOSTNAME_NEW, "sha256/YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg=") //Let's Encrypt Authority X3
.add(API_HOSTNAME_NEW, "sha256/Vjs8r4z+80wjNcr1YKepWQboSIRi63WsWXhIMN+eWys=") //LE Cross Sign: DST Root CA X3
.add(STUDYROOM_HOST, "sha256/dVphPQ9xG7woPpEKXrNalw4eMUQ4Fw9r3OXTzxfuL5A=") //wwwv2.tum.de
.add(STUDYROOM_HOST, "sha256/K64RzAqr/RSxwfpHN6fe0DcmdaIVmzAyi511ufYaK1s=") //wwwv4.tum.de
.add(STUDYROOM_HOST, "sha256/SwdQoHL7SB/6o12XsIhbQJ9bANVnbrJoHTLzlu/qXT0=") //Zertifizierungsstelle der TUM
.add(STUDYROOM_HOST, "sha256/VzL+FtAKvzb4N5igmFJyv83GD7CBK7Yyw+R6XdRRfmg=") //DFN-Verein PCA Global - G01
.add(STUDYROOM_HOST, "sha256/0d4q5hyN8vpiOWYWPUxz1GC/xCjldYW+a/65pWMj0bY=") //Deutsche Telekom Root CA 2
.build();
//We want to persist our cookies through app session
ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(c));
//Start building the http client
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.cookieJar(cookieJar)
.certificatePinner(certificatePinner);
//Add the device identifying header
builder.addInterceptor(Helper.getDeviceInterceptor(c));
builder.connectTimeout(Helper.HTTP_TIMEOUT, TimeUnit.MILLISECONDS);
builder.readTimeout(Helper.HTTP_TIMEOUT, TimeUnit.MILLISECONDS);
builder.addNetworkInterceptor(new TumHttpLoggingInterceptor(message -> Utils.logwithTag(TAG, message)));
//Save it to the static handle and return
client = builder.build();
return client;
}