use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class HessianDecoder method decodeResponseByRequestType.
/**
*
* Parses the hashtables retrieved from the hessian payload that came from the server and
* returns a type for it.
*
* @param clist The list that will be populated with the data types.
* @param hash The hash table that contains the parsed date returned by the backend.
* @param type The type of the request that was sent, e.g. get contacts changes.
*
* @return The type of the response that was parsed (to be found in DecodedResponse.ResponseType).
*
*/
private int decodeResponseByRequestType(List<BaseDataType> clist, Hashtable<String, Object> hash, Request.Type type) {
int responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
switch(type) {
case CONTACT_CHANGES_OR_UPDATES:
responseType = DecodedResponse.ResponseType.GET_CONTACTCHANGES_RESPONSE.ordinal();
// create ContactChanges
ContactChanges contChanges = new ContactChanges();
contChanges = contChanges.createFromHashtable(hash);
clist.add(contChanges);
break;
case ADD_CONTACT:
clist.add(Contact.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.ADD_CONTACT_RESPONSE.ordinal();
break;
case SIGN_UP:
clist.add(Contact.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.SIGNUP_RESPONSE.ordinal();
break;
case RETRIEVE_PUBLIC_KEY:
// AA define new object type
clist.add(PublicKeyDetails.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.RETRIEVE_PUBLIC_KEY_RESPONSE.ordinal();
break;
case CONTACT_DELETE:
ContactListResponse cresp = new ContactListResponse();
cresp.createFromHashTable(hash);
// add ids
@SuppressWarnings("unchecked") Vector<Long> contactIds = (Vector<Long>) hash.get(KEY_CONTACT_ID_LIST);
if (contactIds != null) {
for (Long cid : contactIds) {
cresp.mContactIdList.add((cid).intValue());
}
}
clist.add(cresp);
responseType = DecodedResponse.ResponseType.DELETE_CONTACT_RESPONSE.ordinal();
break;
case CONTACT_DETAIL_DELETE:
ContactDetailDeletion cdel = new ContactDetailDeletion();
clist.add(cdel.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.DELETE_CONTACT_DETAIL_RESPONSE.ordinal();
break;
case CONTACT_GROUP_RELATION_LIST:
ItemList groupRelationList = new ItemList(ItemList.Type.contact_group_relation);
groupRelationList.populateFromHashtable(hash);
clist.add(groupRelationList);
responseType = DecodedResponse.ResponseType.GET_CONTACT_GROUP_RELATIONS_RESPONSE.ordinal();
break;
case CONTACT_GROUP_RELATIONS:
ItemList groupRelationsList = new ItemList(ItemList.Type.contact_group_relations);
groupRelationsList.populateFromHashtable(hash);
clist.add(groupRelationsList);
responseType = DecodedResponse.ResponseType.GET_CONTACT_GROUP_RELATIONS_RESPONSE.ordinal();
break;
case DELETE_CONTACT_GROUP_RELATIONS:
// The hessian data sent by the backend is of the form
// r{1}{0}Mt{0}{0}zz. The MicroHessianInput always skips the 2 bytes
// after the type. This doesn't seem to be handling the case where
// the type is of length zero. Due to this, after decoding, the hash
// doesn't contain any elements/keys. Due to this, we are hardcoding
// the status to true here.
StatusMsg statusMsg = new StatusMsg();
statusMsg.mStatus = true;
clist.add(statusMsg);
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case GROUP_LIST:
ItemList zyblist = new ItemList(ItemList.Type.group_privacy);
zyblist.populateFromHashtable(hash);
clist.add(zyblist);
responseType = DecodedResponse.ResponseType.GET_GROUPS_RESPONSE.ordinal();
break;
case ITEM_LIST_OF_LONGS:
ItemList listOfLongs = new ItemList(ItemList.Type.long_value);
listOfLongs.populateFromHashtable(hash);
clist.add(listOfLongs);
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case // TODO status and status list are used by many requests as a type. each request should have its own type however!
STATUS_LIST:
ItemList zybstatlist = new ItemList(ItemList.Type.status_msg);
zybstatlist.populateFromHashtable(hash);
clist.add(zybstatlist);
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case STATUS:
StatusMsg s = new StatusMsg();
s.mStatus = true;
clist.add(s);
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case TEXT_RESPONSE_ONLY:
Object val = hash.get("result");
if (val != null && val instanceof String) {
SimpleText txt = new SimpleText();
txt.addText((String) val);
clist.add(txt);
}
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case EXPECTING_STATUS_ONLY:
StatusMsg statMsg = new StatusMsg();
clist.add(statMsg.createFromHashtable(hash));
// TODO
responseType = DecodedResponse.ResponseType.UNKNOWN.ordinal();
break;
case PRESENCE_LIST:
PresenceList mPresenceList = new PresenceList();
mPresenceList.createFromHashtable(hash);
clist.add(mPresenceList);
responseType = DecodedResponse.ResponseType.GET_PRESENCE_RESPONSE.ordinal();
break;
case PUSH_MSG:
// parse content of RPG Push msg
parsePushMessage(clist, hash);
responseType = DecodedResponse.ResponseType.PUSH_MESSAGE.ordinal();
break;
case CREATE_CONVERSATION:
Conversation mConversation = new Conversation();
mConversation.createFromHashtable(hash);
clist.add(mConversation);
responseType = DecodedResponse.ResponseType.CREATE_CONVERSATION_RESPONSE.ordinal();
break;
case DELETE_IDENTITY:
IdentityDeletion mIdenitityDeletion = new IdentityDeletion();
clist.add(mIdenitityDeletion.createFromHashtable(hash));
responseType = DecodedResponse.ResponseType.DELETE_IDENTITY_RESPONSE.ordinal();
break;
default:
LogUtils.logE("HessianDecoder.decodeResponseByRequestType() Unhandled type[" + type.name() + "]");
}
return responseType;
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class PeopleTestConnectionThread method run.
public void run() {
Log.d("TAG", "PeopleTestConnectionThread.run");
while (mIsConnectionRunning) {
Log.d("TAG", "PeopleTestConnectionThread.run running");
List<Request> requests = QueueManager.getInstance().getRpgRequests();
if (requests.size() > 0) {
// report back to test frame work
Log.d("TAG", "PeopleTestConnectionThread.run report back");
Request req = requests.get(0);
mTestFramework.reportBackToFramework(req.getRequestId(), req.mEngineId);
} else {
try {
Log.d("TAG", "PeopleTestConnectionThread.run wait");
synchronized (mRunLock) {
if (mIsConnectionRunning) {
mRunLock.wait();
}
}
} catch (InterruptedException ie) {
Log.e(getClass().getName(), "Wait was interrupted: " + ie);
}
}
}
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class Presence method getPresenceList.
// function?
/**
* Retrieve current presence list
*
* @param engineId ID for Presence engine.
* @param recipientUserIdList List of user IDs.
*/
public static void getPresenceList(EngineId engineId, Map<String, List<String>> recipientUserIdList) {
if (LoginEngine.getSession() == null) {
LogUtils.logE("Presence.getPresenceList() No session, return");
return;
}
Request request = new Request(EMPTY, Request.Type.PRESENCE_LIST, engineId, false, Settings.API_REQUESTS_TIMEOUT_PRESENCE_LIST);
if (recipientUserIdList != null) {
// If not specified, then all presence information will be returned
request.addData("tos", ApiUtils.createHashTable(recipientUserIdList));
}
QueueManager.getInstance().addRequest(request);
QueueManager.getInstance().fireQueueStateChanged();
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class DecoderThread method run.
/**
* Thread's run function If the decoding queue contains any entries we
* decode the first response and add the decoded data to the response queue.
* If the decode queue is empty, the thread will become inactive. It is
* resumed when a raw data entry is added to the decode queue.
*/
public void run() {
LogUtils.logI("DecoderThread.run() [Start thread]");
while (mRunning) {
EngineId engineId = EngineId.UNDEFINED;
Type type = Type.PUSH_MSG;
int reqId = -1;
try {
if (mResponses.size() > 0) {
LogUtils.logI("DecoderThread.run() Decoding [" + mResponses.size() + "x] responses");
// Decode first entry in queue
RawResponse decode = mResponses.get(0);
reqId = decode.mReqId;
if (!decode.mIsPushMessage) {
// Attempt to get type from request
Request request = QueueManager.getInstance().getRequest(reqId);
if (request != null) {
type = request.mType;
engineId = request.mEngineId;
long backendResponseTime = decode.mTimeStamp - request.getAuthTimestamp();
LogUtils.logD("Backend response time was " + backendResponseTime + "ms");
} else {
type = Type.COMMON;
}
}
DecodedResponse response = mHessianDecoder.decodeHessianByteArray(reqId, decode.mData, type, decode.mIsCompressed, engineId);
// if we have a push message let's try to find out to which engine it should be routed
if ((response.getResponseType() == DecodedResponse.ResponseType.PUSH_MESSAGE.ordinal()) && (response.mDataTypes.get(0) != null)) {
// for push messages we have to override the engine id as it is parsed inside the hessian decoder
engineId = ((PushEvent) response.mDataTypes.get(0)).mEngineId;
response.mSource = engineId;
// TODO mSource should get the engineId inside the decoder once types for mDataTypes is out. see PAND-1805.
}
// the request ID.
if (type == Type.PUSH_MSG && reqId != 0 && engineId == EngineId.UNDEFINED) {
Request request = QueueManager.getInstance().getRequest(reqId);
if (request != null) {
engineId = request.mEngineId;
}
}
if (engineId == EngineId.UNDEFINED) {
LogUtils.logE("DecoderThread.run() Unknown engine for message with type[" + type.name() + "]");
// TODO: Throw Exception for undefined messages, as
// otherwise they might always remain on the Queue?
}
// Add data to response queue
HttpConnectionThread.logV("DecoderThread.run()", "Add message[" + decode.mReqId + "] to ResponseQueue for engine[" + engineId + "] with data [" + response.mDataTypes + "]");
mRespQueue.addToResponseQueue(response);
// Remove item from our list of responses.
mResponses.remove(0);
// be nice to the other threads
Thread.sleep(THREAD_SLEEP_TIME);
} else {
synchronized (this) {
// No waiting responses, so the thread should sleep.
try {
LogUtils.logV("DecoderThread.run() [Waiting for more responses]");
wait();
} catch (InterruptedException ie) {
// Do nothing
}
}
}
} catch (Throwable t) {
/*
* Keep thread running regardless of error. When something goes
* wrong we should remove response from queue and report error
* back to engine.
*/
if (mResponses.size() > 0) {
mResponses.remove(0);
}
if (type != Type.PUSH_MSG && engineId != EngineId.UNDEFINED) {
List<BaseDataType> list = new ArrayList<BaseDataType>();
// this error type was chosen to make engines remove request
// or retry
// we may consider using other error code later
ServerError error = new ServerError(ServerError.ErrorType.INTERNALERROR);
error.errorDescription = "Decoder thread was unable to decode server message";
list.add(error);
mRespQueue.addToResponseQueue(new DecodedResponse(reqId, list, engineId, DecodedResponse.ResponseType.SERVER_ERROR.ordinal()));
}
LogUtils.logE("DecoderThread.run() Throwable on reqId[" + reqId + "]", t);
}
}
LogUtils.logI("DecoderThread.run() [End thread]");
}
use of com.vodafone360.people.service.io.Request in project 360-Engine-for-Android by 360.
the class HttpConnectionThread method addToDecoder.
/**
* Adds a response to the response decoder.
*
* @param input The data of the response.
* @param reqIds The request IDs that a response was received for.
*/
private void addToDecoder(byte[] input, List<Integer> reqIds) {
if (input != null && mDecoder != null) {
int reqId = reqIds.size() > 0 ? reqIds.get(0) : 0;
mDecoder.addToDecode(new RawResponse(reqId, input, false, false));
logI("RpgHttpConnectionThread.handleApiResponse()", "Added response(s) to decoder: " + reqIds.toString());
}
}
Aggregations