Package | com.esri.bacore.client |
Class | public class AbstractClient |
Inheritance | AbstractClient Object |
Subclasses | BAClient |
An Abstract Client encapsulates an instance of the HTTPService and sends requests to it in the text mode. It is assumed that the result is returned as a JSON string.
The processResult
method is abstract and it should be implemented in subclasses.
See also
Property | Defined By | ||
---|---|---|---|
concurrency : String = multiple
Value that indicates how to handle multiple calls to the same task. | AbstractClient | ||
disableClientCaching : Boolean
If true, adds a timestamp parameter ("_ts") to the REST request to prevent the request from
being loaded from the browser's cache. | AbstractClient | ||
proxyURL : String
The URL to proxy the request through. | AbstractClient | ||
requestTimeout : Number = -1
The request timeout in seconds. | AbstractClient | ||
showBusyCursor : Boolean = false
If true, a busy cursor is displayed while a service is executing. | AbstractClient | ||
token : String
Token for accessing a secure HTTP client. | AbstractClient | ||
tokenProvider : ITokenProvider
Provider responsible for updating the security token if the last one expires. | AbstractClient | ||
url : String
URL of the task. | AbstractClient |
Method | Defined By | ||
---|---|---|---|
AbstractClient(url:Object = null)
Creates a new instance of the AbstractClient class. | AbstractClient | ||
combineUrl(baseUrl:String, urlSuffix:String):String [static]
Combines a base URL with a suffix. | AbstractClient | ||
dispatchEventOnTask(event:Event, asyncToken:AsyncToken):void [static]
Dispatches an event on the requester task associated with the given async token. | AbstractClient | ||
notifyOnError(error:Error, asyncToken:AsyncToken):void [static]
Creates fault event from an error and notifies async token responders using the
notifyOnFault method. | AbstractClient | ||
notifyOnFault(fault:*, asyncToken:AsyncToken):void [static]
Notifies async token responders on fault and dispatches the fault event on the requester task. | AbstractClient | ||
notifyOnResult(result:*, asyncToken:AsyncToken):void [static]
Notifies async token responders on result and dispatches an event on the requester task. | AbstractClient | ||
send(task:IEventDispatcher, logError:Function, urlSuffix:String, urlVariables:URLVariables, responder:IResponder, operation:Function, timeout:Number = -1, disableCaching:Boolean = false, url:String = null):AsyncToken
Sends a request to HTTP service. | AbstractClient |
Method | Defined By | ||
---|---|---|---|
changeServiceMethod(requestVars:URLVariables, queryVars:URLVariables):void
Changes a method to be used in the request. | AbstractClient | ||
collectVariables(urlVariables:URLVariables, requestVars:URLVariables, queryVars:URLVariables):void
Collects URL variables in two collections. | AbstractClient | ||
decodeResult(result:String, asyncToken:AsyncToken):Object
Decodes a result string to an object. | AbstractClient | ||
getErrorObject(decodedObject:Object):Fault
Gets error object from the decoded object. | AbstractClient | ||
isTokenExpired(fault:Fault):Boolean
Tests whether the security token is expired, invalid or absent. | AbstractClient | ||
prepareParametersForGET(requestVars:URLVariables):String
Converts request variables to a string for the GET method. | AbstractClient | ||
prepareUrl(baseUrl:String, urlSuffix:String):String
Prepares HTTP request URL combining it from a base URL and a suffix using the combineUrl method. | AbstractClient | ||
processResult(decodedObject:Object, asyncToken:AsyncToken):void
Processes the decoded object. | AbstractClient |
concurrency | property |
public var concurrency:String = multiple
Value that indicates how to handle multiple calls to the same task. The default
value is multiple
. The following values are permitted:
multiple
Existing requests are not cancelled and the developer is
responsible for ensuring the consistency of returned data by carefully
managing the event stream. This is the default value.single
Only a single request at a time is allowed on the task;
multiple requests generate a fault.last
Making a request cancels any existing request.See also
disableClientCaching | property |
disableClientCaching:Boolean
If true, adds a timestamp parameter ("_ts") to the REST request to prevent the request from being loaded from the browser's cache.
The default value is false
.
public function get disableClientCaching():Boolean
public function set disableClientCaching(value:Boolean):void
proxyURL | property |
proxyURL:String
The URL to proxy the request through.
public function get proxyURL():String
public function set proxyURL(value:String):void
requestTimeout | property |
public var requestTimeout:Number = -1
The request timeout in seconds. A value less than or equal to zero prevents request timeout.
The value of this variable is used as an initial value for the requestTimeout
property of a task when it is created.
The default value is -1
.
showBusyCursor | property |
public var showBusyCursor:Boolean = false
If true, a busy cursor is displayed while a service is executing.
The default value is false
.
token | property |
token:String
Token for accessing a secure HTTP client.
public function get token():String
public function set token(value:String):void
tokenProvider | property |
tokenProvider:ITokenProvider
Provider responsible for updating the security token if the last one expires.
public function get tokenProvider():ITokenProvider
public function set tokenProvider(value:ITokenProvider):void
url | property |
url:String
URL of the task.
public function get url():String
public function set url(value:String):void
AbstractClient | () | Constructor |
public function AbstractClient(url:Object = null)
Creates a new instance of the AbstractClient class.
Parametersurl:Object (default = null ) — The base URL of the client.
|
changeServiceMethod | () | method |
protected function changeServiceMethod(requestVars:URLVariables, queryVars:URLVariables):void
Changes a method to be used in the request. The default implementation switches the method to POST if an URL for GET method is too long (exceeds 2000 symbols) or a token parameter is specified.
Parameters
requestVars:URLVariables — Request variables.
| |
queryVars:URLVariables — Query variables.
|
collectVariables | () | method |
protected function collectVariables(urlVariables:URLVariables, requestVars:URLVariables, queryVars:URLVariables):void
Collects URL variables in two collections.
There are 3 sources of URL variables to collect: input variables, base URL variables, and proxy URL variables. The input variables are collected in the output request variables. Other variables are collected in the query variables. The time stamp (_ts) variable and the token variable are also collected if necessary.
This method can be overrided in subclasses in order to rearrange variables collected in the base implementation.
Parameters
urlVariables:URLVariables — Input variables.
| |
requestVars:URLVariables — Output request variables.
| |
queryVars:URLVariables — Output query variables.
|
combineUrl | () | method |
public static function combineUrl(baseUrl:String, urlSuffix:String):String
Combines a base URL with a suffix.
If the URL suffix is a valid HTTP or HTTPS URL, it is returned. If the base URL is empty, URL suffix is returned. In this case, it must be a valid HTTP URL. If the base URL ends with URL suffix in ignore case mode, the matching end part of the base URL is replaced with the URL suffix. In other cases, the URL is combined from the base URL and from the URL suffix separated with the slash '/'.
Parameters
baseUrl:String — The base URL.
| |
urlSuffix:String — URL suffix (can be null).
|
String — Combined URL.
|
decodeResult | () | method |
protected function decodeResult(result:String, asyncToken:AsyncToken):Object
Decodes a result string to an object. The base implementation decodes the result as JSON object.
Parameters
result:String — Result received from HTTP service.
| |
asyncToken:AsyncToken |
Object — Decoded object.
|
dispatchEventOnTask | () | method |
public static function dispatchEventOnTask(event:Event, asyncToken:AsyncToken):void
Dispatches an event on the requester task associated with the given async token.
The requester task should implement the IEventDispatcher
interface
and must be specified in the asyncToken.task
property.
Parameters
event:Event — An event to be dispatched or null.
| |
asyncToken:AsyncToken — Request async token.
|
getErrorObject | () | method |
protected function getErrorObject(decodedObject:Object):Fault
Gets error object from the decoded object. In the default implementation, the error object is recognized as the "error" property of the decoded object. Its value can be a string or an error object containing "code" and "message" properties and optional "details" array of string.
Parameters
decodedObject:Object — Decoded object.
|
Fault — An error object or null.
|
isTokenExpired | () | method |
protected function isTokenExpired(fault:Fault):Boolean
Tests whether the security token is expired, invalid or absent. The base method returns false.
Parameters
fault:Fault — An reason of fault.
|
Boolean — True if the fault reason is the expired or invalid or absent security token.
|
notifyOnError | () | method |
public static function notifyOnError(error:Error, asyncToken:AsyncToken):void
Creates fault event from an error and notifies async token responders using the
notifyOnFault
method.
Parameters
error:Error — An error object.
| |
asyncToken:AsyncToken — Request async token.
|
notifyOnFault | () | method |
public static function notifyOnFault(fault:*, asyncToken:AsyncToken):void
Notifies async token responders on fault and dispatches the fault event on the requester task.
The input fault
object is at first converted to an instance of the FaultEvent
type as follows. If it is an instance of the FaultEvent
type, no conversion is required.
If it is a string value, a new fault event having this value as the message is generated.
If it is an instance of the Fault
type, it is wrapped with a new fault event.
In other cases, a new fault event with the "Unknown type of fault object."
message is generated and the fault object is attached to the fault
parameter of the event as the rootCause
.
The FaultEvent.fault.content
property value is set to asyncToken.requestUrl
value to view a partially encoded human readable URL of the request.
The requester task should implement the IEventDispatcher
interface and
must be specified in the asyncToken.task
property.
The fault event message is also logged to the task logger if its error logging
function is assigned to the asyncToken.logError
property.
The signature of this function is logError(message:String):void;
Parameters
fault:* — An instance of the fault object.
| |
asyncToken:AsyncToken — Request async token.
|
notifyOnResult | () | method |
public static function notifyOnResult(result:*, asyncToken:AsyncToken):void
Notifies async token responders on result and dispatches an event on the requester task.
If the result
object is an event, this event is dispatched on
the requester task after notifying responders of the async token.
The requester task should implement the IEventDispatcher
interface and
must be specified in the asyncToken.task
property.
Parameters
result:* — An object to be passed to responder's result method.
| |
asyncToken:AsyncToken — Request async token.
|
prepareParametersForGET | () | method |
protected function prepareParametersForGET(requestVars:URLVariables):String
Converts request variables to a string for the GET method. Default
implementation just applies the toString
method to the request variables.
Parameters
requestVars:URLVariables — Request variables.
|
String — String representation of request parameters.
|
prepareUrl | () | method |
protected function prepareUrl(baseUrl:String, urlSuffix:String):String
Prepares HTTP request URL combining it from a base URL and a suffix using the combineUrl method.
Parameters
baseUrl:String — The base URL.
| |
urlSuffix:String — URL suffix (can be null).
|
String — HTTP request URL.
|
processResult | () | method |
protected function processResult(decodedObject:Object, asyncToken:AsyncToken):void
Processes the decoded object. The base method throws an error. The response handler can be received from the asyncToken.operation property. The asyncToken.task property contains the requester task which should be used as this object for the response handler.
Parameters
decodedObject:Object — Decoded object.
| |
asyncToken:AsyncToken — Async token associated with the request.
|
send | () | method |
public function send(task:IEventDispatcher, logError:Function, urlSuffix:String, urlVariables:URLVariables, responder:IResponder, operation:Function, timeout:Number = -1, disableCaching:Boolean = false, url:String = null):AsyncToken
Sends a request to HTTP service.
Parameters
task:IEventDispatcher — Requester task.
| |
logError:Function — Function logError(message:String):void .
| |
urlSuffix:String — URL suffix.
| |
urlVariables:URLVariables — URL variables.
| |
responder:IResponder — Responder object (can be null).
| |
operation:Function — Result handler function.
| |
timeout:Number (default = -1 ) — Request timeout (nonpositive value prevents request timeout).
| |
disableCaching:Boolean (default = false ) — Disable client caching.
| |
url:String (default = null ) — Base request URL (if this value is missing, the client URL is used).
|
AsyncToken — Async token associated with this request.
|