|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.veriplace.web.VeriplaceState
public class VeriplaceState
Veriplace user, location, and permission information associated with the current HTTP request.
When you start processing a request, call Veriplace.open(HttpServletRequest, HttpServletResponse)
on the Veriplace object to obtain an instance of VeriplaceState. (The state object
is cached, so you can always obtain the same one by passing the same request to open().)
Whenever a method such as Veriplace.requireLocation(VeriplaceState) completes
successfully, it updates the properties of the VeriplaceState.
| Constructor Summary | |
|---|---|
VeriplaceState(Veriplace veriplace,
HttpServletRequest request,
HttpServletResponse response)
|
|
| Method Summary | |
|---|---|
java.lang.String |
getAllFields()
Creates HTML hidden form fields for all currently defined persistent attributes. |
java.util.Map<java.lang.String,java.lang.String[]> |
getCallbackParameters()
Returns the names and values of all HTTP query string or form parameters that will be preserved across a redirect and callback. |
static VeriplaceState |
getFromRequest(HttpServletRequest request)
Returns a VeriplaceState instance if one has previously been attached to the given HTTP request using Veriplace.open(HttpServletRequest, HttpServletResponse),
or null if there is none. |
Token |
getGetLocationPermissionToken()
Returns the current permission token for getting location, if any. |
VeriplaceException |
getLastErrorException()
Returns the last VeriplaceException that occurred for
the current request, or null if the last request was successful. |
Location |
getLocation()
Returns the Location object describing the last acquired
location of the current Veriplace user, or null if you have not acquired a location. |
java.lang.String |
getLocationMode()
See setLocationMode(String). |
LocationOptions |
getLocationOptions()
Gets a LocationOptions object which can be used to specify
optional properties of the next location request, such as location mode
and additional geographic queries. |
HttpServletRequest |
getRequest()
Returns the current HttpServletRequest. |
HttpServletResponse |
getResponse()
Returns the current HttpServletResponse. |
User |
getUser()
Returns the User object representing the current Veriplace
user, or null if the user has not yet been determined. |
java.lang.String |
getUserFields()
Creates HTML hidden form fields for the current user identity. |
Veriplace |
getVeriplace()
Returns the current Veriplace instance. |
boolean |
hasGetLocationPermission()
Returns true if you have obtained permission to get a user's location. |
boolean |
isAsynchronousRequestAllowed()
See setAsynchronousRequestAllowed(boolean). |
boolean |
isCallback()
Returns true if this request originated in a callback from the Veriplace website. |
boolean |
isError()
Returns true if the last request caused an error. |
boolean |
isUserInteractionAllowed()
See setUserInteractionAllowed(boolean). |
void |
requireGetLocationPermission()
Attempts to obtain permission to locate the current Veriplace user, if that permission isn't already present in the current state. |
void |
requireGetLocationPermissionImmediate()
Attempts to obtain permission to locate the current Veriplace user, if that permission isn't already present in the current state. |
void |
requireLocation()
Attempts to locate the current Veriplace user, if a location isn't already present in the current state. |
void |
requireLocation(long locationId)
Attempts to retrieve a previously retrieved location again, using its ID (from Location.getId()). |
void |
requireUser()
Attempts to acquire the current Veriplace user identifier, if it isn't already present in the current state. |
void |
requireUser(UserDiscoveryParameters parameters)
Attempts to acquire the current Veriplace user identifier using identifying information in UserDiscoveryParameters. |
void |
requireUserImmediate()
Attempts to acquire the current Veriplace user identifier, if it isn't already present in the current state, without providing any identifying properties and without redirecting. |
void |
setAsynchronousRequestAllowed(boolean asynchronousRequestAllowed)
Specifies whether the Veriplace client can perform location requests asynchronously using a background thread. |
void |
setCallbackParameter(java.lang.String name,
java.lang.Long value)
Specifies an additional HTTP parameter to be preserved across redirects and callbacks. |
void |
setCallbackParameter(java.lang.String name,
java.lang.String value)
Specifies an additional HTTP parameter to be preserved across redirects and callbacks. |
void |
setCallbackParameter(java.lang.String name,
java.lang.String[] values)
Specifies an additional HTTP parameter to be preserved across redirects and callbacks. |
void |
setGetLocationPermissionToken(Token token)
Specifies an access token for getting location. |
void |
setLocationMode(java.lang.String locationModeName)
Sets the location mode to be used for subsequent location requests on this state. |
void |
setLocationOptions(LocationOptions locationOptions)
Specifies a LocationOptions object whose properties will be used
for the next location request. |
void |
setUser(long userId)
Sets the current Veriplace user. |
void |
setUser(User user)
Sets the current Veriplace user. |
void |
setUserInteractionAllowed(boolean userInteractionAllowed)
Specifies whether the Veriplace server is allowed to prompt the end user to log in or to grant location permission. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public VeriplaceState(Veriplace veriplace,
HttpServletRequest request,
HttpServletResponse response)
| Method Detail |
|---|
public static VeriplaceState getFromRequest(HttpServletRequest request)
Veriplace.open(HttpServletRequest, HttpServletResponse),
or null if there is none.
public Veriplace getVeriplace()
Veriplace instance.
public HttpServletRequest getRequest()
HttpServletRequest.
public HttpServletResponse getResponse()
HttpServletResponse.
public User getUser()
User object representing the current Veriplace
user, or null if the user has not yet been determined. To discover the current user,
call Veriplace.requireUser(VeriplaceState).
public void setUser(User user)
Veriplace.requireUser(VeriplaceState) and stored the user
object for future reference.
setUser(long)public void setUser(long userId)
Veriplace.requireUser(VeriplaceState) and stored the user
object for future reference.
setUser(User)public Location getLocation()
Location object describing the last acquired
location of the current Veriplace user, or null if you have not acquired a location.
To acquire a location, call Veriplace.requireLocation(VeriplaceState).
public java.lang.String getLocationMode()
setLocationMode(String).
public void setLocationMode(java.lang.String locationModeName)
LocationMode for allowable values.
getLocationOptions()public LocationOptions getLocationOptions()
LocationOptions object which can be used to specify
optional properties of the next location request, such as location mode
and additional geographic queries.
public void setLocationOptions(LocationOptions locationOptions)
LocationOptions object whose properties will be used
for the next location request.
public boolean isUserInteractionAllowed()
setUserInteractionAllowed(boolean).
public void setUserInteractionAllowed(boolean userInteractionAllowed)
public boolean isAsynchronousRequestAllowed()
setAsynchronousRequestAllowed(boolean).
public void setAsynchronousRequestAllowed(boolean asynchronousRequestAllowed)
WaitingException by displaying a progress page. Setting
this flag to false causes the client to perform all requests on the main thread; it
will never throw a WaitingException in that case.
public boolean hasGetLocationPermission()
public boolean isCallback()
public boolean isError()
getLastErrorException()
to get the details of the error.
public VeriplaceException getLastErrorException()
VeriplaceException that occurred for
the current request, or null if the last request was successful. Note that a
WaitingException will not cause this property to be set, since it is not
really an error.
public java.util.Map<java.lang.String,java.lang.String[]> getCallbackParameters()
public void setCallbackParameter(java.lang.String name,
java.lang.String value)
public void setCallbackParameter(java.lang.String name,
java.lang.Long value)
public void setCallbackParameter(java.lang.String name,
java.lang.String[] values)
public Token getGetLocationPermissionToken()
public void setGetLocationPermissionToken(Token token)
Veriplace.requireGetLocationPermission(VeriplaceState).
public java.lang.String getUserFields()
public java.lang.String getAllFields()
public void requireUser()
throws RespondedException,
UserDiscoveryException,
UnexpectedException,
ServletException
getUser()
on the VeriplaceState to get the Veriplace User object.
If the user has already been acquired, or set explicitly with
setUser(com.veriplace.client.User), the method returns immediately. Otherwise, it
redirects to the Veriplace server to begin a user
discovery transaction. If the server can detect the current user without interaction,
it redirects immediately back to your application; otherwise it prompts the user to log
in (unless you have disabled this with setUserInteractionAllowed(boolean))
and redirects back once they have done so.
When your application receives the callback, it will be to the same URL and with the same HTTP parameters as the initial request, but with an additional token to indicate that the user is now available. You do not need to check for this token; just call requireUser() as you did before, and this time the method will return normally.
RespondedException - if the client has sent a redirect response; you should simply
stop handling the request and return in this case
UserDiscoveryException - if the current user could not be determined
UnexpectedException - if there was an unexpected I/O error or OAUth error from the server
ServletException
public void requireUser(UserDiscoveryParameters parameters)
throws RespondedException,
UserDiscoveryException,
UnexpectedException,
ServletException
UserDiscoveryParameters. In order to do this, you must
have specified an application token and token secret in your Veriplace client configuration
(see ClientFactory).
If the user has already been acquired, or set explicitly with
setUser(com.veriplace.client.User), the method returns immediately. Otherwise, it
submits a request to the Veriplace server which will either succeed or immediately fail;
there are no redirects. If the method returns with no exceptions, call getUser()
to get the user object.
parameters - the identifying properties of the desired user
RespondedException - can happen only if you've configured an automatic error response
page; return immediately in this case
UserDiscoveryException - if the user could not be found or your application lacks privileges
UnexpectedException - if there was an unexpected I/O error or OAUth error from the server
ServletException
public void requireUserImmediate()
throws UserDiscoveryNotPermittedException,
UnexpectedException,
ServletException
If the user has already been acquired, or set explicitly with
setUser(com.veriplace.client.User), the method returns immediately. Otherwise, it
submits a request to the Veriplace server which will either succeed or immediately fail; there
are no redirects.
If the method returns with no exceptions, call getUser() to get the user object.
UserDiscoveryNotPermittedException - if you do not have a valid user discovery access token
UnexpectedException - if there was an unexpected I/O error or OAUth error from the server
ServletException
public void requireGetLocationPermission()
throws RespondedException,
RequestDeniedException,
UnexpectedException,
ServletException
requireUser() or setUser(com.veriplace.client.User), then this calls
requireUser() first.
If this method returns with no exceptions, permission is now available. You can call
getGetLocationPermissionToken() to get the permisison token, if you need
to save it for future reuse. Note: if an asynchronous location request is
currently in progress, then getGetLocationPermissionToken() will return
null even though permission has been obtained, so make sure the value is non-null
before you try to do anything with the token.
Either the user discovery step or the permission step may cause a redirect to the Veriplace site. When Veriplace redirects back to your application, it will be to the same URL and with the same HTTP parameters as the initial request, but with an additional token to indicate that the permission is now available. You do not need to check for this token; just call requireGetLocationPermission(state) as you did before, and this time the method will return normally.
The Veriplace instance maintains a token cache containing the last known valid permission token for
each user, which it will try to reuse if you call requireLocation(). However,
it will not use this cache if you call requireGetLocationPermission separately from
requireLocation, because the token might have expired and there would be no way to know this
if you didn't go on to actually request a location. Therefore, requireGetLocationPermission
always asks the Veriplace server for a current permission.
RespondedException - if the client has sent a redirect response; you should simply
stop handling the request and return in this case
RequestDeniedException - if either the user discovery request or the permission request was
denied (check the subclass of the exception to see which one)
UnexpectedException - if there was an unexpected I/O error or OAUth error from the server
ServletException
public void requireGetLocationPermissionImmediate()
throws GetLocationNotPermittedException,
UserDiscoveryException,
UnexpectedException
requireUser() or setUser(com.veriplace.client.User).
This method will not perform any redirects and will not ask the user for permission if it wasn't
previously granted; it will simply fail in that case. If this method returns with no exceptions,
permission is now available. You can call getGetLocationPermissionToken()
to get the permission token, if you need to save it for future reuse.
The Veriplace instance maintains a token cache containing the last known valid permission token for
each user, which it will try to reuse if you call requireLocation(). However,
requireGetLocationPermissionImmediate does not use this cache; it always asks the Veriplace server
for a current permission.
GetLocationNotPermittedException - if the permission request was denied
UserDiscoveryException - if you did not provide a valid user
UnexpectedException - if there was an unexpected I/O error or OAUth error from the server
public void requireLocation()
throws RespondedException,
WaitingException,
RequestDeniedException,
UnexpectedException,
ServletException
requireUser() and/or requireGetLocationPermission()
first in the correct order.
If this method returns with no exceptions, call getLocation() on the
VeriplaceState to get the location data.
Either the user discovery step or the permission step may cause a redirect to the Veriplace site. When Veriplace redirects back to your application, it will be to the same URL and with the same HTTP parameters as the initial request, but with an additional token to indicate that the location is now available. You do not need to check for this token; just call requireLocation(state) as you did before, and this time the method will return normally.
Since it can take a noticeable amount of time to acquire location (if a new GPS fix is required),
by default all location requests are done asynchronously on a separate thread. This allows you
to give the user some feedback in the meantime, such as a "please wait" page. Veriplace handles
this by throwing a WaitingException, which contains a callback URL for continuing the
current request; if you display a page that automatically redirects to that URL after a few
seconds, your application will pick up where it left off, so that the next call to
requireLocation(state) will either acquire the result or throw another WaitingException.
(This process can be automated by designating a Waiting page ahead of time; see
StatusViewRenderer. If you use that approach, you will
never get a WaitingException.)
RespondedException - if the client has sent a redirect response; you should simply
stop handling the request and return in this case
RequestDeniedException - if either the user discovery request or the permission request was
denied (check the subclass of the exception to see which one)
WaitingException - if an asynchronous request is in progress and you should display
an intermediate status page
UnexpectedException - if there was an unexpected I/O error or OAUth error from the server
ServletException
public void requireLocation(long locationId)
throws RespondedException,
RequestDeniedException,
UnexpectedException,
ServletException
Location.getId()). If you haven't already identified the user
or obtained location permission, then this calls requireUser()
and/or requireGetLocationPermission() first in the correct order,
which may involve redirects. However, the location request itself happens synchronously
as a single server call.
If this method returns with no exceptions, call getLocation() to get the location data.
RespondedException - if the client has sent a redirect response; you should simply
stop handling the request and return in this case
RequestDeniedException - if either the user discovery request or the permission request was
denied (check the subclass of the exception to see which one)
UnexpectedException - if there was an unexpected I/O error or OAUth error from the server
ServletException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||