本文整理汇总了Java中com.franmontiel.persistentcookiejar.PersistentCookieJar类的典型用法代码示例。如果您正苦于以下问题:Java PersistentCookieJar类的具体用法?Java PersistentCookieJar怎么用?Java PersistentCookieJar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PersistentCookieJar类属于com.franmontiel.persistentcookiejar包,在下文中一共展示了PersistentCookieJar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的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.PersistentCookieJar; //导入依赖的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: ApiManager
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的package包/类
private ApiManager() {
cookieJar = new PersistentCookieJar(new SetCookieCache(),
new SharedPrefsCookiePersistor(Utils.getApp()));
OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
builder.readTimeout(30, TimeUnit.SECONDS);
builder.connectTimeout(29, TimeUnit.SECONDS);
builder.cookieJar(cookieJar);
builder.addInterceptor(new RequestInterceptor());
builder.addNetworkInterceptor(new NetworkInterceptor());
OkHttpClient okHttpClient = builder.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://" + domain)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
apiService = retrofit.create(ApiService.class);
}
示例4: init
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的package包/类
void init(String username, String password, Context context) {
this.username = username;
this.password = password;
cookieJar = new PersistentCookieJar(new SetCookieCache(),
new SharedPrefsCookiePersistor(context));
client = new OkHttpClient.Builder()
.cookieJar(cookieJar)
.build();
expireTime = 0;
}
示例5: HttpClient
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的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();
}
示例6: onCreate
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的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);
}
示例7: getRetrofit
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的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();
}
示例8: getRetrofit
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的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;
}
示例9: init
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的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);
}
示例10: onCreate
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
mContext = this;
mClearableCookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(this));
mDBHelper = new DBHelper(this);
mCredentials = Credentials.create();
mLoggedUser = User.create();
}
示例11: onCreate
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_fake);
tv = (TextView)findViewById(R.id.tv_01);
et = (EditText)findViewById(R.id.et_01);
fab = (FloatingActionButton)findViewById(R.id.fab);
toolbar = (Toolbar)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Cookies, for login
CookieJar cookiejar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(this));
OkHttpClient okHttpClient = new OkHttpClient.Builder().cookieJar(cookiejar).build();
service = new Retrofit.Builder().baseUrl(PunchcardService.END_POINT).client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create()).build().create(PunchcardService.class);
shanbayService = new Retrofit.Builder().baseUrl(ShanbayService.END_POINT)
.addConverterFactory(GsonConverterFactory.create()).build().create(ShanbayService.class);
// first login, then use the same http client to access other apis
service.login(new LoginRequest("leasunhy", "123456")).enqueue(new ToastFailureCallback<User>(fab) {
@Override
protected void onSuccess(Call<User> call, Response<User> response) {
getUserInfo();
}
});
// queryWord();
// getUserInfo();
// Register();
// getAllUser();
}
示例12: onCreate
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的package包/类
@Override
public void onCreate()
{
super.onCreate();//必须调用父类方法
Log.i("CREATE","application created....");
CookieJar cookiejar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(this));
OkHttpClient okHttpClient = new OkHttpClient.Builder().cookieJar(cookiejar).build();
service = new Retrofit.Builder().baseUrl(PunchcardService.END_POINT).client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create()).build().create(PunchcardService.class);
num = 0;
total = 10;
}
示例13: onCreate
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的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(); //恢复本地所有未完成的任务
}
示例14: getRetrofit
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的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;
}
示例15: getCookieJar
import com.franmontiel.persistentcookiejar.PersistentCookieJar; //导入依赖的package包/类
public CookieJar getCookieJar(){
if(this.cookieJar.get() == null){
this.cookieJar.compareAndSet(null,
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(this)));
}
return this.cookieJar.get();
}