|
Spiffy UI Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.spiffyui.client.rest.RESTility
public final class RESTility
A set of utilities for calling REST from GWT.
Nested Class Summary | |
---|---|
class |
RESTility.HTTPMethod
This is a helper type class so we can pass the HTTP method as a type safe object instead of a string. |
Field Summary | |
---|---|
static RESTility.HTTPMethod |
DELETE
This method represents an HTTP DELETE request |
static RESTility.HTTPMethod |
GET
This method represents an HTTP GET request |
static RESTility.HTTPMethod |
POST
This method represents an HTTP POST request |
static RESTility.HTTPMethod |
PUT
This method represents an HTTP PUT request |
Method Summary | |
---|---|
static void |
addLoginListener(RESTLoginCallBack callback)
Add login listeners |
static void |
callREST(RESTOptions options)
Make an HTTP call and get the results as a JSON object. |
static void |
callREST(java.lang.String url,
RESTCallback callback)
Make a rest call using an HTTP GET to the specified URL. |
static void |
callREST(java.lang.String url,
java.lang.String data,
RESTCallback callback)
Make a rest call using an HTTP GET to the specified URL including the specified data.. |
static void |
callREST(java.lang.String url,
java.lang.String data,
RESTility.HTTPMethod method,
RESTCallback callback)
Make an HTTP call and get the results as a JSON object. |
static void |
callREST(java.lang.String url,
java.lang.String data,
RESTility.HTTPMethod method,
RESTCallback callback,
boolean isLoginRequest,
boolean shouldReplay,
java.lang.String etag)
Make an HTTP call and get the results as a JSON object. |
static void |
callREST(java.lang.String url,
java.lang.String data,
RESTility.HTTPMethod method,
RESTCallback callback,
boolean isLoginRequest,
boolean shouldReplay,
java.lang.String etag,
java.util.Map<java.lang.String,java.lang.String> headers)
Make an HTTP call and get the results as a JSON object. |
static void |
callREST(java.lang.String url,
java.lang.String data,
RESTility.HTTPMethod method,
RESTCallback callback,
boolean isLoginRequest,
java.lang.String etag)
Make an HTTP call and get the results as a JSON object. |
static void |
callREST(java.lang.String url,
java.lang.String data,
RESTility.HTTPMethod method,
RESTCallback callback,
java.lang.String etag)
Make an HTTP call and get the results as a JSON object. |
static void |
callREST(java.lang.String url,
java.lang.String data,
RESTility.HTTPMethod method,
RESTCallback callback,
java.lang.String etag,
java.util.Map<java.lang.String,java.lang.String> headers)
Make an HTTP call and get the results as a JSON object. |
static void |
doLocalLogout()
Upon logout, delete cookie and clear out all member variables |
static void |
finishRESTCalls()
In some cases, like login, the original REST call returns an error and we need to run it again. |
static void |
fireLoginSuccess()
Fire the login success event to all listeners if it hasn't been fired already. |
static RESTAuthProvider |
getAuthProvider()
Gets the current auth provider which will be used for future REST calls. |
static java.lang.String |
getBestLocale()
Returns best matched locale |
static java.lang.String |
getFullAuthToken()
Returns user's full authentication token, prefixed with "X-OPAQUE" |
static java.util.List<RESTLoginCallBack> |
getLoginListeners()
|
static java.lang.String |
getSessionCookieName()
Gets the current name of the Spiffy UI session cookie. |
static java.lang.String |
getSessionCookiePath()
Get the path of the session cookie. |
static java.lang.String |
getTokenServerLogoutUrl()
Returns authentication server logout url |
static java.lang.String |
getTokenServerUrl()
Returns the authentication server url |
static java.lang.String |
getTokenType()
Returns user's authentication token type |
static java.lang.String |
getUsername()
Returns the name of the currently logged in user or null if the current user is not logged in. |
static java.lang.String |
getUserToken()
Returns user's authentication token |
static boolean |
hasUserLoggedIn()
Returns a boolean flag indicating whether user has logged in or not |
static void |
login(RESTCallback callback,
Response response,
java.lang.String url,
RESTException exception)
Make a login request using RESTility authentication framework. |
static void |
login(RESTCallback callback,
Response response,
java.lang.String url,
java.lang.String errorCode)
Make a login request using RESTility authentication framework. |
static RESTility.HTTPMethod |
parseString(java.lang.String method)
Returns HTTPMethod corresponding to method name. |
static void |
removeLoginListener(RESTLoginCallBack callback)
Remove login listeners |
static boolean |
requiresSecureCookies()
Determines if RESTility will force all cookies to require SSL. |
static void |
setAuthProvider(RESTAuthProvider authProvider)
Sets the authentication provider used for future REST requests. |
static void |
setBestLocale(java.lang.String locale)
We can't know the best locale until after the user logs in because we need to consider their locale from the identity vault. |
static void |
setRequireSecureCookies(boolean secure)
Sets if RESTility cookies should only be sent via SSL. |
static void |
setSessionCookieName(java.lang.String name)
Sets the name of the Spiffy UI session cookie. |
static void |
setSessionCookiePath(java.lang.String newPath)
Set the path for the Spiffy_Session cookie. |
static void |
setTokenServerLogoutURL(java.lang.String url)
Set the authentication server logout url in JavaScript memory and and saves it in a cookie. |
static void |
setTokenServerURL(java.lang.String url)
Set the authentication server url in JavaScript memory and and saves it in a cookie. |
static void |
setTokenType(java.lang.String type)
Set the type of token RESTility will pass. |
static void |
setUsername(java.lang.String username)
Set the user name in JavaScript memory and and saves it in a cookie. |
static void |
setUserToken(java.lang.String token)
Set the user token in JavaScript memory and and saves it in a cookie. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final RESTility.HTTPMethod GET
public static final RESTility.HTTPMethod PUT
public static final RESTility.HTTPMethod POST
public static final RESTility.HTTPMethod DELETE
Method Detail |
---|
public static void setAuthProvider(RESTAuthProvider authProvider)
Sets the authentication provider used for future REST requests.
By default authentication is provided by the AuthUtil class, but this class may be replaced to provide support for custom authentication schemes.
authProvider
- the new authentication providerAuthUtil
public static void setSessionCookieName(java.lang.String name)
Sets the name of the Spiffy UI session cookie.
Spiffy UI uses a local cookie to save the current user token. This cookie has
the name Spiffy_Session
by default. This method will change the
name of the cookie to something else.
Calling this method will not change the name of the cookie until a REST call is made which causes the cookie to be reset.
name
- the name of the cookie Spiffy UI session cookiepublic static java.lang.String getSessionCookieName()
public static void setRequireSecureCookies(boolean secure)
Sets if RESTility cookies should only be sent via SSL.
RESTility stores a small amount of information locally so users can refresh the page without logging out or resetting their locale. This information is sometimes stored in cookies. These cookies are normally not sent back to the server, but can be in some cases.
If your application is concerned with sercurity you might want to require all cookies are only sent via a secure connection (SSL). Set this method true to make all cookies stored be RESTility and Spiffy UI require an SSL connection before they are sent.
The default value of this field is false.
secure
- true if cookies should require SSL and false otherwisepublic static boolean requiresSecureCookies()
public static RESTAuthProvider getAuthProvider()
public static void login(RESTCallback callback, Response response, java.lang.String url, java.lang.String errorCode) throws RESTException
callback
- the rest callback called when the login is completeresponse
- the response from the server requiring the loginurl
- the URL of the authentication servererrorCode
- the error code from the server returned with the 401
RESTException
- if there was an exception when making the login requestpublic static void login(RESTCallback callback, Response response, java.lang.String url, RESTException exception) throws RESTException
callback
- the rest callback called when the login is completeresponse
- the response from the server requiring the loginurl
- the URL of the authentication serverexception
- the RESTException which prompted this login
RESTException
- if there was an exception when making the login requestpublic static RESTility.HTTPMethod parseString(java.lang.String method)
method
- a String representation of a http method
public static void doLocalLogout()
public static void finishRESTCalls()
public static void callREST(java.lang.String url, RESTCallback callback)
callback
- the callback to invokeurl
- the properly encoded REST url to callpublic static void callREST(java.lang.String url, java.lang.String data, RESTCallback callback)
url
- the properly encoded REST url to calldata
- the data to pass to the URLcallback
- the callback to invokepublic static void setUserToken(java.lang.String token)
token
- user tokenpublic static void setTokenServerURL(java.lang.String url)
url
- authentication server urlpublic static void fireLoginSuccess()
public static void setTokenType(java.lang.String type)
Set the type of token RESTility will pass.
Most of the time the token type is specified by the REST server and the client does not have to specify this value. This method is mostly used for testing.
type
- the token typepublic static void setUsername(java.lang.String username)
username
- user namepublic static void setTokenServerLogoutURL(java.lang.String url)
url
- authentication server logout urlpublic static void setBestLocale(java.lang.String locale)
locale
- the localepublic static void setSessionCookiePath(java.lang.String newPath)
Set the path for the Spiffy_Session cookie.
When Spiffy UI uses token based authentication it saves token and user information in a cookie named Spiffy_Session. This cookie allows the user to remain logged in after they refresh the page the reset JavaScript memory.
By default that cookie uses the path of the current page. If an application uses multiple pages it can make sense to use a more general path for this cookie to make it available to other URLs in the application.
The path must be set before the first authentication request. If it is called afterward the cookie path will not change.
newPath
- the new path for the cookie or null if the cookie should use the path of the current pagepublic static java.lang.String getSessionCookiePath()
public static boolean hasUserLoggedIn()
public static java.lang.String getFullAuthToken()
public static java.lang.String getUserToken()
public static java.lang.String getTokenType()
public static java.lang.String getTokenServerUrl()
public static java.lang.String getTokenServerLogoutUrl()
public static java.lang.String getUsername()
public static java.lang.String getBestLocale()
public static java.util.List<RESTLoginCallBack> getLoginListeners()
public static void callREST(java.lang.String url, java.lang.String data, RESTility.HTTPMethod method, RESTCallback callback)
url
- the properly encoded REST url to calldata
- the data to pass to the URLmethod
- the HTTP method, defaults to GETcallback
- the callback object for handling the request resultspublic static void callREST(java.lang.String url, java.lang.String data, RESTility.HTTPMethod method, RESTCallback callback, java.lang.String etag)
url
- the properly encoded REST url to calldata
- the data to pass to the URLmethod
- the HTTP method, defaults to GETcallback
- the callback object for handling the request resultsetag
- the option etag for this requestpublic static void callREST(java.lang.String url, java.lang.String data, RESTility.HTTPMethod method, RESTCallback callback, boolean isLoginRequest, java.lang.String etag)
url
- the properly encoded REST url to calldata
- the data to pass to the URLmethod
- the HTTP method, defaults to GETcallback
- the callback object for handling the request resultsisLoginRequest
- true if this is a request to login and false otherwiseetag
- the option etag for this requestpublic static void callREST(java.lang.String url, java.lang.String data, RESTility.HTTPMethod method, RESTCallback callback, java.lang.String etag, java.util.Map<java.lang.String,java.lang.String> headers)
Make an HTTP call and get the results as a JSON object. This method handles allows the caller to override any HTTP headers in the request.
By default RESTility sets two HTTP headers: Accept=application/json
and
Accept-Charset=UTF-8
. Other headers are added by the browser running this
application.
url
- the properly encoded REST url to calldata
- the data to pass to the URLmethod
- the HTTP method, defaults to GETcallback
- the callback object for handling the request resultsetag
- the option etag for this requestheaders
- a map containing the headers to the HTTP request. Any item
in this map will override the default headers.public static void callREST(java.lang.String url, java.lang.String data, RESTility.HTTPMethod method, RESTCallback callback, boolean isLoginRequest, boolean shouldReplay, java.lang.String etag)
url
- the properly encoded REST url to calldata
- the data to pass to the URLmethod
- the HTTP method, defaults to GETcallback
- the callback object for handling the request resultsisLoginRequest
- true if this is a request to login and false otherwiseshouldReplay
- true if this request should repeat after a login request
if this request returns a 401etag
- the option etag for this requestpublic static void callREST(java.lang.String url, java.lang.String data, RESTility.HTTPMethod method, RESTCallback callback, boolean isLoginRequest, boolean shouldReplay, java.lang.String etag, java.util.Map<java.lang.String,java.lang.String> headers)
Make an HTTP call and get the results as a JSON object. This method handles cases like login, error parsing, and configuration requests.
By default RESTility sets two HTTP headers: Accept=application/json
and
Accept-Charset=UTF-8
. Other headers are added by the browser running this
application.
url
- the properly encoded REST url to calldata
- the data to pass to the URLmethod
- the HTTP method, defaults to GETcallback
- the callback object for handling the request resultsisLoginRequest
- true if this is a request to login and false otherwiseshouldReplay
- true if this request should repeat after a login request
if this request returns a 401etag
- the option etag for this requestheaders
- a map containing the headers to the HTTP request. Any item
in this map will override the default headers.public static void callREST(RESTOptions options)
Make an HTTP call and get the results as a JSON object. This method handles cases like login, error parsing, and configuration requests.
options
- the options for the REST requestpublic static void addLoginListener(RESTLoginCallBack callback)
callback
- listeners to be addedpublic static void removeLoginListener(RESTLoginCallBack callback)
callback
- listeners to be removed
|
Spiffy UI Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |