Packagecom.esri.bacore.client
Classpublic class AbstractClient
InheritanceAbstractClient Inheritance Object
Subclasses BAClient

The AbstractClient is the base abstract HTTP client wrapper class.

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

AbstractTask


Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined 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
Protected Methods
 MethodDefined 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
Property Detail
concurrencyproperty
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:

See also

disableClientCachingproperty 
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.


Implementation
    public function get disableClientCaching():Boolean
    public function set disableClientCaching(value:Boolean):void
proxyURLproperty 
proxyURL:String

The URL to proxy the request through.


Implementation
    public function get proxyURL():String
    public function set proxyURL(value:String):void
requestTimeoutproperty 
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.

showBusyCursorproperty 
public var showBusyCursor:Boolean = false

If true, a busy cursor is displayed while a service is executing.

The default value is false.

tokenproperty 
token:String

Token for accessing a secure HTTP client.


Implementation
    public function get token():String
    public function set token(value:String):void
tokenProviderproperty 
tokenProvider:ITokenProvider

Provider responsible for updating the security token if the last one expires.


Implementation
    public function get tokenProvider():ITokenProvider
    public function set tokenProvider(value:ITokenProvider):void
urlproperty 
url:String

URL of the task.


Implementation
    public function get url():String
    public function set url(value:String):void
Constructor Detail
AbstractClient()Constructor
public function AbstractClient(url:Object = null)

Creates a new instance of the AbstractClient class.

Parameters
url:Object (default = null) — The base URL of the client.
Method Detail
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).

Returns
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

Returns
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.

Returns
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.

Returns
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.

Returns
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).

Returns
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).

Returns
AsyncToken — Async token associated with this request.