T - Generic service result type which inherits ServiceResult
typepublic abstract class ServiceAgent<T extends ServiceResult>
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected ClientIdentity |
clientIdentity
client identity object for authentication
|
protected HttpMethod |
httpMethod
HttpMethod enum
|
protected OnCompleteListener<T> |
onCompleteListener
completion callback for service operation
|
protected T |
serviceResult
service result
|
protected java.lang.Class<T> |
serviceResultClass
class object of service result
|
protected java.net.URI |
serviceUri
service uri
|
| Constructor and Description |
|---|
ServiceAgent(java.lang.Class<T> objClass)
Initializes an instance of the
ServiceAgent class |
ServiceAgent(java.lang.Class<T> objClass,
HttpMethod httpMethod,
java.lang.Object state)
Initializes an instance of the
ServiceAgent class |
| Modifier and Type | Method and Description |
|---|---|
protected org.apache.http.client.methods.HttpRequestBase |
constructHttpRequest(java.lang.String token)
construct http request object
|
java.lang.String |
getContentType()
Gets the required content type used by Content-Type HTTP header.
|
protected byte[] |
getRequestBodyData()
Gets the byte array for HTTP request body.
|
T |
getServiceResult()
Gets service result
|
protected void |
handleException(java.lang.Exception ex)
handle unexpected exception
|
protected void |
handleException(java.lang.String errorMessage,
java.lang.Throwable cause)
handle specified exception message and
Throwable object |
protected void |
OnCompleteRequest()
A method can be overridden by sub classes.
|
protected void |
parseOutput(java.io.InputStream inputStream)
Parses the response from server.
|
protected boolean |
parseServiceResultRequired()
gets the flag to indicate whether service result are required to be
parsed.
|
void |
processRequest(OnCompleteListener<T> callback)
Send HTTP request and process response
|
protected void |
setServiceResult(T result)
Sets the service result object
|
protected HttpMethod httpMethod
protected T extends ServiceResult serviceResult
protected java.lang.Class<T extends ServiceResult> serviceResultClass
protected java.net.URI serviceUri
protected ClientIdentity clientIdentity
protected OnCompleteListener<T extends ServiceResult> onCompleteListener
public ServiceAgent(java.lang.Class<T> objClass) throws java.lang.Exception
ServiceAgent classobjClass - The class object for the generic typejava.lang.Exceptionpublic ServiceAgent(java.lang.Class<T> objClass, HttpMethod httpMethod, java.lang.Object state) throws java.lang.Exception
ServiceAgent classobjClass - The class object for the generic service result typehttpMethod - HttpMethod enumstate - user state objectjava.lang.Exceptionpublic T getServiceResult()
protected void setServiceResult(T result)
result - voidpublic java.lang.String getContentType()
protected boolean parseServiceResultRequired()
protected byte[] getRequestBodyData()
throws HawaiiException
HawaiiException - byte[]protected void parseOutput(java.io.InputStream inputStream)
inputStream - HawaiiException - voidpublic void processRequest(OnCompleteListener<T> callback)
callback - callback method after response has been processedprotected org.apache.http.client.methods.HttpRequestBase constructHttpRequest(java.lang.String token)
throws HawaiiException
token - access tokenHawaiiException - HttpRequestBaseprotected void handleException(java.lang.String errorMessage,
java.lang.Throwable cause)
Throwable objecterrorMessage - specified error messagecause - inner Throwable objectprotected void handleException(java.lang.Exception ex)
ex - unexpected exceptionprotected void OnCompleteRequest()