• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
BBCookieJar Class Reference

Support for OkHttp. More...

Inherits CookieJar.

Description

This class provides cookie support for the OkHttp HTTP framework with BBCustomInterceptor interceptor. The application can access cookies that are managed by the BlackBerry Dynamics Runtime via BBCookieJar API.

BBCustomInterceptor bbCustomInterceptor = new BBCustomInterceptor();
bbCustomInterceptor.setCookieJar(new BBCookieJar());
OkHttpClient httpClient = new OkHttpClient().newBuilder()
.addInterceptor(bbCustomInterceptor)
.build();

Note: It is required to call BBCustomInterceptor.setCookieJar to set BBCookieJar instead of OkHttpClient.Builder.cookieJar.

Application code can add additional cookies to HTTP requests by calling BBCookieJar.addCookie. The cookies from the HTTP responses are added to BBCookieJar by the runtime.

Although application code does not need to extend BBCookieJar, it can do so if it wishes to add cookies from CookieJar callbacks.

class AppCustomBBCookieJar extends BBCookieJar {
@Override
public void saveFromResponse(HttpUrl url, List<Cookie> cookies) {
// Cookies from the Response are already managed by BBCookieJar.
}
}
@Override
public List<Cookie> loadForRequest(HttpUrl url) {
// Add additional cookies.
return Arrays.asList(createCookies());
}
}

Public Member Functions

void addCookie (Cookie cookie)
 Adds an HTTP cookie. More...
 
List< Cookie > getCookies ()
 Returns all cookies contained in this CookieJar. More...
 
boolean clearExpired (Date date)
 Clears all expired cookies. More...
 
void clear ()
 Clears all cookies. More...
 

Member Function Documentation

◆ addCookie()

void addCookie ( Cookie  cookie)

Adds an HTTP cookie, replacing any existing equivalent cookie. If the given cookie has already expired it will not be added, and also existing equivalent cookie will be removed.

Parameters
cookieto be added

◆ getCookies()

List<Cookie> getCookies ( )

Returns all persistent and session cookies contained in this CookieJar.

Returns
all cookies

◆ clearExpired()

boolean clearExpired ( Date  date)

Removes all of the cookies in this CookieJar that have expired by the specified java.util.Date date.

Returns
true if any cookies were purged.

◆ clear()

void clear ( )

Removes all cookies including persistent cookies from this CookieJar.