com.nativex.common
Class Request

java.lang.Object
  extended by com.nativex.common.Request
Direct Known Subclasses:
GetImageRequest

public abstract class Request
extends Object

A basic request object to be used with ServerRequestManager.

Author:
Anton Donchev

Nested Class Summary
static class Request.HTTP_ACTION
          Enumerates the possible HTTP methods.
 
Field Summary
private  Integer actionType
           
static HttpClient defaultClient
          The field defaultClient should be used for testing purposes only.
private  boolean enableLogging
           
private  Request.HTTP_ACTION httpAction
           
private  HttpClient httpClient
           
private  OnRequestCompletedListener listener
           
private  String request
           
private  String requestType
           
private  String url
           
 
Constructor Summary
Request()
          Basic constructor.
Request(String url, String request, String requestType, Request.HTTP_ACTION action)
          Constructor that receives the request parameters.
 
Method Summary
 void executeListener(boolean succeded, Response response)
          Executes the listener set with setListener().
abstract  void generateRequest()
          Generates the request body.
abstract  Response generateResponse()
          Generates the proper type of response according to the request response.
 Integer getActionType()
           
 Map<String,String> getHeaders()
          Returns a list of extra HTTP headers to go along with this request.
 Request.HTTP_ACTION getHttpAction()
          Returns the request HTTP method.
 HttpClient getHttpClient()
           
 String getPrettyRequest()
          Prettifies the request body for debugging output.
 String getRequest()
          Returns the request body.
 String getRequestType()
          Returns the request type.
 String getUrl()
          Returns the request URL.
 boolean isLoggingEnabled()
           
 void postExecute()
           
protected  void postExecuteImmediatelyAfter()
           
 void preExecute()
           
protected  void preExecuteJustBefore()
           
 void setActionType(Integer type)
           
protected  void setHttpAction(Request.HTTP_ACTION httpAction)
          Sets the HTTP method.
 void setHttpClient(HttpClient httpClient)
           
 void setListener(OnRequestCompletedListener listener)
          Sets a listener that fires when the request is completed.
protected  void setLoggingEnabled(boolean isEnabled)
           
protected  void setRequest(String request)
          Sets the request body.
protected  void setRequestType(String requestType)
          Sets the request type.
protected  void setUrl(String url)
          Sets the request URL.
abstract  boolean shouldExecute()
          Checks if the request should be executed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultClient

public static HttpClient defaultClient
The field defaultClient should be used for testing purposes only.


url

private String url

request

private String request

requestType

private String requestType

httpAction

private Request.HTTP_ACTION httpAction

listener

private OnRequestCompletedListener listener

httpClient

private HttpClient httpClient

actionType

private Integer actionType

enableLogging

private boolean enableLogging
Constructor Detail

Request

public Request()
Basic constructor.


Request

public Request(String url,
               String request,
               String requestType,
               Request.HTTP_ACTION action)
Constructor that receives the request parameters.

Parameters:
url - String. The URL the request is made to.
request - String. The request body.
requestType - String. The request type.
action - Request.HTTP_ACTION. The HTTP method of the request.
Method Detail

getHttpClient

public HttpClient getHttpClient()

setHttpClient

public void setHttpClient(HttpClient httpClient)

getRequest

public String getRequest()
Returns the request body.

Returns:
String. The request body.

getPrettyRequest

public String getPrettyRequest()
Prettifies the request body for debugging output.

Returns:
String The request body, only prettier.

setRequest

protected void setRequest(String request)
Sets the request body.

Parameters:
request - String. The request body.

getUrl

public String getUrl()
Returns the request URL.

Returns:
String. The request URL.

setUrl

protected void setUrl(String url)
Sets the request URL.

Parameters:
url - String. The request URL.

getRequestType

public String getRequestType()
Returns the request type.

Returns:
String. The request type.

setRequestType

protected void setRequestType(String requestType)
Sets the request type.

Parameters:
requestType - String. The request type.

getHttpAction

public Request.HTTP_ACTION getHttpAction()
Returns the request HTTP method.

Returns:
Request.HTTP_ACTION. The HTTP method.

getHeaders

public Map<String,String> getHeaders()
Returns a list of extra HTTP headers to go along with this request. Override this method to add the request specific headers.


setHttpAction

protected void setHttpAction(Request.HTTP_ACTION httpAction)
Sets the HTTP method.

Parameters:
httpAction - Request.HTTP_ACTION. The HTTP method.

generateResponse

public abstract Response generateResponse()
Generates the proper type of response according to the request response.

Returns:
Response The type of the response expected from that request.

generateRequest

public abstract void generateRequest()
Generates the request body.


shouldExecute

public abstract boolean shouldExecute()
Checks if the request should be executed.

Returns:
Boolean. Returns true if the request should be executed or false when skipped.

setListener

public void setListener(OnRequestCompletedListener listener)
Sets a listener that fires when the request is completed.

Parameters:
listener - OnRequestCompletedListener. Listener that fires when the request is completed.

executeListener

public void executeListener(boolean succeded,
                            Response response)
Executes the listener set with setListener().

Parameters:
succeded - Boolean. Notifies if the request is successful.
response - Response. The response from the server.

preExecute

public void preExecute()

postExecute

public void postExecute()

setActionType

public void setActionType(Integer type)

getActionType

public Integer getActionType()

preExecuteJustBefore

protected void preExecuteJustBefore()

postExecuteImmediatelyAfter

protected void postExecuteImmediatelyAfter()

isLoggingEnabled

public boolean isLoggingEnabled()

setLoggingEnabled

protected void setLoggingEnabled(boolean isEnabled)