com.dropbox.client2.session
Class AbstractSession

java.lang.Object
  extended by com.dropbox.client2.session.AbstractSession
All Implemented Interfaces:
Session
Direct Known Subclasses:
AndroidAuthSession, WebAuthSession

public abstract class AbstractSession
extends java.lang.Object
implements Session

Keeps track of a logged in user and contains configuration options for the DropboxAPI. This is a base class to use for creating your own Sessions.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.dropbox.client2.session.Session
Session.AccessType, Session.ProxyInfo
 
Constructor Summary
AbstractSession(AppKeyPair appKeyPair, Session.AccessType type)
          Creates a new session with the given app key and secret, and access type.
AbstractSession(AppKeyPair appKeyPair, Session.AccessType type, AccessTokenPair accessTokenPair)
          Creates a new session with the given app key and secret, and access type.
 
Method Summary
 AccessTokenPair getAccessTokenPair()
          Returns the currently logged in user's access token and secret.
 Session.AccessType getAccessType()
          Returns what Dropbox access type to use (currently app folder or entire Dropbox).
 java.lang.String getAPIServer()
          Returns the Dropbox API server.
 AppKeyPair getAppKeyPair()
          Returns the app key and secret.
 java.lang.String getContentServer()
          Returns the Dropbox content server.
 org.apache.http.client.HttpClient getHttpClient()
          Will be called every time a request is made to Dropbox, in case you want to use a new client every time.
 java.util.Locale getLocale()
          Returns the locale to use.
 Session.ProxyInfo getProxyInfo()
          Will be called every time a request is made to Dropbox, in case the proxy changes between requests.
 java.lang.String getWebServer()
          Returns the Dropbox web server.
 boolean isLinked()
          Returns whether or not this session has a user's access token and secret.
 void setAccessTokenPair(AccessTokenPair accessTokenPair)
          Links the session with the given access token and secret.
 void setRequestTimeout(org.apache.http.client.methods.HttpUriRequest request)
          Will be called every time right before a request is sent to Dropbox.
 void sign(org.apache.http.HttpRequest request)
          Signs the request by using's OAuth's HTTP header authorization scheme and the PLAINTEXT signature method.
 void unlink()
          Unlinks the session by removing any stored access token and secret.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSession

public AbstractSession(AppKeyPair appKeyPair,
                       Session.AccessType type)
Creates a new session with the given app key and secret, and access type. The session will not be linked because it has no access token pair.


AbstractSession

public AbstractSession(AppKeyPair appKeyPair,
                       Session.AccessType type,
                       AccessTokenPair accessTokenPair)
Creates a new session with the given app key and secret, and access type. The session will be linked to the account corresponding to the given access token pair.

Method Detail

setAccessTokenPair

public void setAccessTokenPair(AccessTokenPair accessTokenPair)
Links the session with the given access token and secret.


getAppKeyPair

public AppKeyPair getAppKeyPair()
Description copied from interface: Session
Returns the app key and secret.

Specified by:
getAppKeyPair in interface Session

getAccessTokenPair

public AccessTokenPair getAccessTokenPair()
Description copied from interface: Session
Returns the currently logged in user's access token and secret.

Specified by:
getAccessTokenPair in interface Session

getAccessType

public Session.AccessType getAccessType()
Description copied from interface: Session
Returns what Dropbox access type to use (currently app folder or entire Dropbox).

Specified by:
getAccessType in interface Session

getLocale

public java.util.Locale getLocale()
Returns the locale to use. Must not return null. Currently, this is used for user-facing messages that are returned by the API. You should not cache this value, but instead get it every time from the system in case the locale changes.

The default implementation always returns Locale.ENLISH, but you are highly encouraged to localize your application and return the system locale instead. Note: as of the time this was written, Dropbox supports the de, en, es, fr, and ja locales - if you use a locale other than these, messages will be returned in English. However, it is good practice to pass along the correct locale as we will add more languages in the future.

Specified by:
getLocale in interface Session

isLinked

public boolean isLinked()
Description copied from interface: Session
Returns whether or not this session has a user's access token and secret.

Specified by:
isLinked in interface Session

unlink

public void unlink()
Description copied from interface: Session
Unlinks the session by removing any stored access token and secret.

Specified by:
unlink in interface Session

sign

public void sign(org.apache.http.HttpRequest request)
Signs the request by using's OAuth's HTTP header authorization scheme and the PLAINTEXT signature method. As such, this should only be used over secure connections (i.e. HTTPS). Using this over regular HTTP connections is completely insecure.

Specified by:
sign in interface Session
Parameters:
request - an HttpRequest.
See Also:
Session.sign(org.apache.http.HttpRequest)

getProxyInfo

public Session.ProxyInfo getProxyInfo()
Will be called every time a request is made to Dropbox, in case the proxy changes between requests. Return null if you do not want to use a proxy, or a Session.ProxyInfo object with a host and optionally a port set.

The default implementation always returns null.

Specified by:
getProxyInfo in interface Session

getHttpClient

public org.apache.http.client.HttpClient getHttpClient()
Will be called every time a request is made to Dropbox, in case you want to use a new client every time. However, it's highly recommended to create a client once and reuse it to take advantage of connection reuse.

The default implementation does all of this and more, including using a connection pool and killing connections after a timeout to use less battery power on mobile devices. It's unlikely that you'll want to change this behavior.

Specified by:
getHttpClient in interface Session

setRequestTimeout

public void setRequestTimeout(org.apache.http.client.methods.HttpUriRequest request)
Will be called every time right before a request is sent to Dropbox. It should set the socket and connection timeouts on the request if you want to override the default values. This is abstracted out to cope with signature changes in the Apache HttpClient libraries.

The default implementation always sets a 30 second timeout.

Specified by:
setRequestTimeout in interface Session

getAPIServer

public java.lang.String getAPIServer()
Description copied from interface: Session
Returns the Dropbox API server. Changing this will break things.

Specified by:
getAPIServer in interface Session

getContentServer

public java.lang.String getContentServer()
Description copied from interface: Session
Returns the Dropbox content server. Changing this will break things.

Specified by:
getContentServer in interface Session

getWebServer

public java.lang.String getWebServer()
Description copied from interface: Session
Returns the Dropbox web server. Changing this will break things.

Specified by:
getWebServer in interface Session