Developer

Cookie Management

The library sets its own SAPCookieManager as the default cookie handler. Clients should be aware of this if a custom cookie handler uses the same mechanism. If a default CookieHandler is already set, the library copies every cookie from it to SAPCookieManager inside of the HttpConversationManager constructor.

SAPCookieManager is a singleton class that uses the android.webkit.CookieManager to handle and persist cookies from either a WebView or HttpURLConnection; this allows the same cookie manager to be used by WebView and native HTTP request processing.

All cookies are persisted automatically by the WebKit CookieManager. However, clients are required to create an instance of CookieSyncManager before calling SAPCookieManager.getInstance() for the first time and before instantiating the HttpConversationManager:
if (CookieSyncManager.getInstance() == null) 
   CookieSyncManager.createInstance(context); 
All cookies in all sessions are persisted, and removed when the client calls getInstance() for the first time.

The underlying cookie store acts as a proxy between the client and the WebKit CookieManager. It is not a full standalone implementation; its capabilities are limited by the WebKit cookie store.

The class' default CookiePolicy is ACCEPT_ALL, which you can change using SAPCookieManager.setPolicy(CookiePolicy).

Clients can get the cookie store from the manager, but the store cannot return all cookies or URIs, or remove a specific cookie. The list returned by the CookieStore.get(URI) includes restricted instances of cookies that contain only the name and value. To provide unified cookie handling both in WebView and HttpURLConnection, set the manager as the default handler:
CookieHandler.setDefault(SAPCookieManager.getInstance());