org.spiffyui.client.rest
Class RESTOptions

java.lang.Object
  extended by org.spiffyui.client.rest.RESTOptions

public final class RESTOptions
extends java.lang.Object

This Java Bean provides options for making REST calls.

All of the set methods in this bean support chaining so it is possible to call new RESTOptions().setURL("/api/foo").setCallback(this).


Constructor Summary
RESTOptions()
           
 
Method Summary
 RESTCallback getCallback()
          Get the callback for when this request is completed.
 JSONValue getData()
           Get the JSON data sent to the server during the REST request.
 java.lang.String getDataString()
           Get the JSON data sent to the server during the REST request as a string.
 java.lang.String getEtag()
          Get the etag for this REST request.
 java.util.Map<java.lang.String,java.lang.String> getHeaders()
           Set the HTTP headers map for this request.
 RESTility.HTTPMethod getMethod()
          Get the method of this REST request.
 java.lang.String getURL()
          Get the URL for this REST request.
 boolean isLoginRequest()
           Set if this request is a login request or not.
 RESTOptions setCallback(RESTCallback callback)
          Set the callback for this REST request.
 RESTOptions setData(JSONValue data)
           Set the data for this REST request.
 RESTOptions setEtag(java.lang.String etag)
           Set the etag for this REST request.
 RESTOptions setHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
           Set the HTTP headers for this REST request.
 RESTOptions setIsLoginRequest(boolean isLoginRequest)
          Set this REST request as a login request.
 RESTOptions setMethod(RESTility.HTTPMethod method)
          Set the REST request method.
 RESTOptions setShouldReplay(boolean shouldReplay)
           Set if this REST request should be replayed.
 RESTOptions setURL(java.lang.String url)
          Set the URL for this REST request.
 boolean shouldReplay()
           Set if this REST request should be replayed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RESTOptions

public RESTOptions()
Method Detail

getURL

public java.lang.String getURL()
Get the URL for this REST request.

Returns:
the full URL for this REST request including all parameters

setURL

public RESTOptions setURL(java.lang.String url)
Set the URL for this REST request.

Parameters:
url - the full URL for the request including all parameters
Returns:
the RESTOptions bean for method chaining

getData

public JSONValue getData()

Get the JSON data sent to the server during the REST request.

JSON data can only be passed for POST and PUT requests and will be ignored for all other request methods.

Returns:
the JSON data for this request

getDataString

public java.lang.String getDataString()

Get the JSON data sent to the server during the REST request as a string.

Returns:
the JSON data for this request as a string

setData

public RESTOptions setData(JSONValue data)

Set the data for this REST request.

JSON data can only be passed for POST and PUT requests and will be ignored for all other request methods.

Parameters:
data - the data to send to the server with this request
Returns:
the RESTOptions bean for method chaining

getMethod

public RESTility.HTTPMethod getMethod()
Get the method of this REST request.

Returns:
the REST request method

setMethod

public RESTOptions setMethod(RESTility.HTTPMethod method)
Set the REST request method.

Parameters:
method - the HTTP method for this REST request
Returns:
the RESTOptions bean for method chaining

getCallback

public RESTCallback getCallback()
Get the callback for when this request is completed.

Returns:
the callback for this REST request

setCallback

public RESTOptions setCallback(RESTCallback callback)
Set the callback for this REST request.

Parameters:
callback - the REST request callback
Returns:
the RESTOptions bean for method chaining

isLoginRequest

public boolean isLoginRequest()

Set if this request is a login request or not.

When the server returns a 401 as the response to a REST request and the application is following the Spiffy UI authentication recommendations then RESTility will handle the authentication and part of that authentication includes making further REST requests for the login. Those requests are handled specially since they are part of the authentication exchange.

By default this value is false. This value should only be true if this request is part of the login for a custom authentication handler.

Returns:
true if this is a login request and false otherwise

setIsLoginRequest

public RESTOptions setIsLoginRequest(boolean isLoginRequest)
Set this REST request as a login request. The default is false.

Parameters:
isLoginRequest - true if this is a login request and false otherwise
Returns:
the RESTOptions bean for method chaining

shouldReplay

public boolean shouldReplay()

Set if this REST request should be replayed.

When the client makes a REST request which results in a 401 RESTility must perform authentication and get a token before it can continue with the request. After the authentication completes successfully RESTility replays the original request and any requests which have come in during the authentication process so they can complete for the calling code transparent of any authentication requirements.

This value controls if the request should replay in that case. The default is true.

Returns:
the RESTOptions bean for method chaining

setShouldReplay

public RESTOptions setShouldReplay(boolean shouldReplay)

Set if this REST request should be replayed.

When the client makes a REST request which results in a 401 RESTility must perform authentication and get a token before it can continue with the request. After the authentication completes successfully RESTility replays the original request and any requests which have come in during the authentication process so they can complete for the calling code transparent of any authentication requirements.

This value controls if the request should replay in that case. The default is true.

Parameters:
shouldReplay - true if the request should replay and false otherwise
Returns:
the RESTOptions bean for method chaining

getEtag

public java.lang.String getEtag()
Get the etag for this REST request.

Returns:
the etag for this request

setEtag

public RESTOptions setEtag(java.lang.String etag)

Set the etag for this REST request.

Etags are a common mechanism for handling concurrency checking and RESTility handles them specially since they are part of the built in Spiffy UI optimistic concurrency mechanism.

The ETag set in this method will override the If-Match set in the headers map if it is present.

For more information see HTTP 1.1 header field definitions sections 14.19.

Parameters:
etag - the etag for this request
Returns:
the RESTOptions bean for method chaining
See Also:
ConcurrentRESTCallback

getHeaders

public java.util.Map<java.lang.String,java.lang.String> getHeaders()

Set the HTTP headers map for this request.

Returns:
the map of HTTP headers
See Also:
setEtag, getEtag

setHeaders

public RESTOptions setHeaders(java.util.Map<java.lang.String,java.lang.String> headers)

Set the HTTP headers for this REST request.

This method gives a client the option to specify defined and custom HTTP headers for the request request. These headers will override all values except for the following headers:

Parameters:
headers - the HTTP headers for this REST request
Returns:
the RESTOptions bean for method chaining