com.vodafone360.people.service.io
Class Request

java.lang.Object
  extended by com.vodafone360.people.service.io.Request

public class Request
extends java.lang.Object

Container class for Requests issued from client to People server via the transport layer. A request consists of a payload, an identifier for the engine responsible for handling this request, a request type and a request id which is generated on creation of the request.


Nested Class Summary
static class Request.Type
          Request types, these are based on the content requested from, or delivered to, the server, and whether the returned response contains a type identifier or not.
 
Field Summary
 boolean expired
          true if the request has expired
private  java.lang.String mApiMethodName
          Name of method on the backend.
private  byte mAuthenticationType
           Represents the authentication type that needs to be taken into account when executing this specific request.
private  long mAuthTimestamp
          The timestamp when the request's auth was calculated.
private  long mCreationTimestamp
          The timestamp when this request was created.
 EngineManager.EngineId mEngineId
          Handle of Engine associated with this RPG message.
private  long mExpiryDate
          The expiry date calculated when the request gets executed.
private  boolean mIsActive
          active flag - set to true once we have actually issued a request
private  boolean mIsFireAndForget
          If true, this method is a fire and forget method and will not expect any responses to come in.
private  java.util.Hashtable<java.lang.String,java.lang.Object> mParameters
           
private  int mRequestId
          RPG message request id.
private  long mTimeout
          The timeout set for the request. -1 if not set.
 Request.Type mType
          RPG Message type - as defined above.
static byte USE_API
           
static byte USE_BOTH
           
static byte USE_RPG
           
 
Constructor Summary
Request(java.lang.String apiMethodName, Request.Type type, EngineManager.EngineId engineId, boolean isFireAndForget, long timeout)
          Constructor used for constructing internal (RPG/API) requests.
Request(java.lang.String externalUrl, java.lang.String urlParams, EngineManager.EngineId engineId)
          Constructor used for constructing an external request used for fetching e.g. images.
 
Method Summary
 void addData(java.lang.String varName, java.lang.Boolean value)
          Create new NameValue and adds it to list of params
 void addData(java.lang.String varName, byte[] value)
          Adds byte array to parameter list
 void addData(java.lang.String name, java.util.Hashtable<java.lang.String,?> nv)
          Adds element to list of params
 void addData(java.lang.String varName, java.lang.Integer value)
          Create new NameValue and adds it to list of params
 void addData(java.lang.String name, java.util.List<java.lang.String> value)
          Adds element to list of params
 void addData(java.lang.String varName, java.lang.Long value)
          Create new NameValue and adds it to list of params
 void addData(java.lang.String varName, java.lang.String value)
          Create new NameValue and adds it to list of params
 void addData(java.lang.String name, java.util.Vector<java.lang.Object> value)
          Adds element to list of params
private  void calculateAuth()
          Calculate the Auth value for this Requester.
 void calculateExpiryDate()
          Calculates the expiry date based on the timeout.
 java.lang.String getApiMethodName()
          Returns the API call this request will use.
 java.lang.String getAuth()
          Gets the auth of this request.
 byte getAuthenticationType()
          Returns the authentication type of this request.
 long getAuthTimestamp()
          Gets the time stamp when this request's hash was calculated.
 long getCreationTimestamp()
          Gets the time stamp when this request was created.
 long getExpiryDate()
          Gets the calculated expiry date.
 int getRequestId()
          Gets the request ID of this request.
 long getTimeout()
          Gets the set timeout.
 boolean isActive()
          Is request active - i.e has it been issued
 boolean isFireAndForget()
          Returns true if the method is a fire and forget method.
private  byte[] makeBody()
          Creates the body of the request using the parameter list.
 void setActive(boolean isActive)
           Sets whether this request is active or not.
 void setRequestId(int requestId)
          Sets the request ID for this request.
 java.lang.String toString()
          Returns a description of the contents of this object
 void writeToOutputStream(java.io.OutputStream os, boolean writeRpgHeader)
          Serializes the request's data structure to the passed output stream enabling the connection to easily prepare one or multiple) requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mParameters

private java.util.Hashtable<java.lang.String,java.lang.Object> mParameters

mApiMethodName

private java.lang.String mApiMethodName
Name of method on the backend. E.g. identities/getavailableidentities.


mType

public Request.Type mType
RPG Message type - as defined above.


mEngineId

public EngineManager.EngineId mEngineId
Handle of Engine associated with this RPG message.


mIsActive

private boolean mIsActive
active flag - set to true once we have actually issued a request


mTimeout

private long mTimeout
The timeout set for the request. -1 if not set.


mExpiryDate

private long mExpiryDate
The expiry date calculated when the request gets executed.


expired

public boolean expired
true if the request has expired


mAuthTimestamp

private long mAuthTimestamp
The timestamp when the request's auth was calculated.


mCreationTimestamp

private long mCreationTimestamp
The timestamp when this request was created.


mAuthenticationType

private byte mAuthenticationType

Represents the authentication type that needs to be taken into account when executing this specific request. There are 3 types of authentication types:


USE_API

public static final byte USE_API
See Also:
Constant Field Values

USE_RPG

public static final byte USE_RPG
See Also:
Constant Field Values

USE_BOTH

public static final byte USE_BOTH
See Also:
Constant Field Values

mIsFireAndForget

private boolean mIsFireAndForget
If true, this method is a fire and forget method and will not expect any responses to come in. This fact can be used for removing requests from the queue as soon as they have been sent.


mRequestId

private int mRequestId
RPG message request id.

Constructor Detail

Request

public Request(java.lang.String apiMethodName,
               Request.Type type,
               EngineManager.EngineId engineId,
               boolean isFireAndForget,
               long timeout)
Constructor used for constructing internal (RPG/API) requests.

Parameters:
apiMethodName - The method name of the call, e.g. "identities/getavailableidentities".
type - RPG message type.
engId - The engine ID. Will be used for routing the response to this request back to the engine that can process it.
needsUserAuthentication - If true we need to authenticate this request by providing the session in the auth. This requires the user to be logged in.
isFireAndForget - True if the request is a fire and forget request.
timeout - the timeout in milliseconds before the request throws a timeout exception

Request

public Request(java.lang.String externalUrl,
               java.lang.String urlParams,
               EngineManager.EngineId engineId)
Constructor used for constructing an external request used for fetching e.g. images.

Parameters:
externalUrl - The external URL of the object to fetch.
urlParams - THe parameters to add to the URL of this request.
engineId - The ID of the engine that will be called back once the response for this request comes in.
Method Detail

isActive

public boolean isActive()
Is request active - i.e has it been issued

Returns:
true if request is active

setActive

public void setActive(boolean isActive)

Sets whether this request is active or not. An active request is a request that is currently being sent to the server and awaiting a response.

The reason is that an active request should not be sent twice.

Parameters:
isActive - True if the request is active, false otherwise.

toString

public java.lang.String toString()
Returns a description of the contents of this object

Overrides:
toString in class java.lang.Object
Returns:
The description

addData

public void addData(java.lang.String name,
                    java.util.Hashtable<java.lang.String,?> nv)
Adds element to list of params

Parameters:
name - key name for object to be added to parameter list
nv - object which will be added

addData

public void addData(java.lang.String name,
                    java.util.Vector<java.lang.Object> value)
Adds element to list of params

Parameters:
name - key name for object to be added to parameter list
value - object which will be added

addData

public void addData(java.lang.String name,
                    java.util.List<java.lang.String> value)
Adds element to list of params

Parameters:
name - key name for object to be added to parameter list
value - object which will be added

addData

public void addData(java.lang.String varName,
                    byte[] value)
Adds byte array to parameter list

Parameters:
varName - name
value - byte[] array to be added

addData

public void addData(java.lang.String varName,
                    java.lang.String value)
Create new NameValue and adds it to list of params

Parameters:
varName - name
value - string value

addData

public void addData(java.lang.String varName,
                    java.lang.Long value)
Create new NameValue and adds it to list of params

Parameters:
varName - name
value - Long value

addData

public void addData(java.lang.String varName,
                    java.lang.Integer value)
Create new NameValue and adds it to list of params

Parameters:
varName - name
value - Integer value

addData

public void addData(java.lang.String varName,
                    java.lang.Boolean value)
Create new NameValue and adds it to list of params

Parameters:
varName - name
value - Boolean value

getAuthenticationType

public byte getAuthenticationType()
Returns the authentication type of this request. This can be one of the following: USE_API, which must be used for authentication requests that need application authentication, USE_RPG, useful for requests against the API that need user authentication and want to profit from the mobile enhancements of the RPG, or USE_BOTH for requests that need to be able to be used on the API or RPG. These requests are for example the Terms and Conditions requests which need to be accessible from anywhere in the client.

Returns:
True if this method requires user authentication or a valid session to be more precise. False is returned if the method only needs application authentication.

getRequestId

public int getRequestId()
Gets the request ID of this request.

Returns:
The unique request ID for this request.

setRequestId

public void setRequestId(int requestId)
Sets the request ID for this request.

Parameters:
requestId - The request ID to set.

getAuthTimestamp

public long getAuthTimestamp()
Gets the time stamp when this request's hash was calculated.

Returns:
The time stamp representing the creation date of this request.

getCreationTimestamp

public long getCreationTimestamp()
Gets the time stamp when this request was created.

Returns:
The time stamp representing the creation date of this request.

getTimeout

public long getTimeout()
Gets the set timeout.

Returns:
the timeout in milliseconds, -1 if not set.

getExpiryDate

public long getExpiryDate()
Gets the calculated expiry date.

Returns:
the expiry date in milliseconds, -1 if not set.

getApiMethodName

public java.lang.String getApiMethodName()
Returns the API call this request will use.

Returns:
The API method name this request will call.

isFireAndForget

public boolean isFireAndForget()
Returns true if the method is a fire and forget method. Theses methods can be removed from the request queue as soon as they have been sent out.

Returns:
True if the request is fire and forget, false otherwise.

writeToOutputStream

public void writeToOutputStream(java.io.OutputStream os,
                                boolean writeRpgHeader)
Serializes the request's data structure to the passed output stream enabling the connection to easily prepare one or multiple) requests.

Parameters:
os - The output stream to serialise this request to.
writeRpgHeader - If true the RPG header is written.

makeBody

private byte[] makeBody()
                 throws java.io.IOException
Creates the body of the request using the parameter list.

Returns:
payload The hessian encoded payload of this request body.
Throws:
java.io.IOException - Thrown if anything goes wrong using the hessian encoder.

getAuth

public java.lang.String getAuth()
Gets the auth of this request. Prior to the the writeToOutputStream()-method must have been called.

Returns:
The auth of this request or null if it was not calculated before.

calculateAuth

private void calculateAuth()
Calculate the Auth value for this Requester. TODO: Throttle by timestamp/function to prevent automatic backend log out


calculateExpiryDate

public void calculateExpiryDate()
Calculates the expiry date based on the timeout. TODO: should have instead an execute() method to call when performing the request. it would set the request to active, calculates the expiry date, etc...



JavaDoc