Search in sources :

Example 1 with ExternalResponseObject

use of com.vodafone360.people.datatypes.ExternalResponseObject in project 360-Engine-for-Android by 360.

the class HessianDecoder method parseExternalResponse.

private void parseExternalResponse(List<BaseDataType> clist, InputStream is, int tag) throws IOException {
    mMicroHessianInput.init(is);
    ExternalResponseObject resp = new ExternalResponseObject();
    // now we read and check the response code
    if (mMicroHessianInput.readInt(tag) != 200) {
        return;
    }
    try {
        resp.mMimeType = mMicroHessianInput.readString();
    } catch (IOException ioe) {
        LogUtils.logE("Failed to parse hessian string.");
        return;
    }
    // read data - could be gzipped
    try {
        resp.mBody = mMicroHessianInput.readBytes();
    } catch (IOException ioe) {
        LogUtils.logE("Failed to read bytes.");
        return;
    }
    LogUtils.logI("HessianDecoder.parseExternalResponse()" + " Parsed external object with length: " + resp.mBody.length);
    clist.add(resp);
}
Also used : ExternalResponseObject(com.vodafone360.people.datatypes.ExternalResponseObject) IOException(java.io.IOException)

Example 2 with ExternalResponseObject

use of com.vodafone360.people.datatypes.ExternalResponseObject in project 360-Engine-for-Android by 360.

the class ContentEngine method processCommsResponse.

/**
     * Processes the response Finds the matching contentobject for the repsonse
     * using the id of the response and sets its status to done. At last the
     * TransferComplete method of the ContentObject is called.
     * 
     * @param resp Response object that has been processed
     */
@Override
protected final void processCommsResponse(final DecodedResponse resp) {
    ContentObject co = requestContentObjectMatchTable.remove(resp.mReqId);
    if (co == null) {
        // check if we have an invalid response
        return;
    }
    List<BaseDataType> mDataTypes = resp.mDataTypes;
    // Sometimes it is null or empty
    if (mDataTypes == null || mDataTypes.size() == 0) {
        co.setTransferStatus(ContentObject.TransferStatus.ERROR);
        RuntimeException exc = new RuntimeException("Empty response returned");
        co.getTransferListener().transferError(co, exc);
        return;
    }
    Object data = mDataTypes.get(0);
    if (mDataTypes.get(0).getType() == BaseDataType.SERVER_ERROR_DATA_TYPE || mDataTypes.get(0).getType() == BaseDataType.SYSTEM_NOTIFICATION_DATA_TYPE) {
        co.setTransferStatus(ContentObject.TransferStatus.ERROR);
        RuntimeException exc = new RuntimeException(data.toString());
        co.getTransferListener().transferError(co, exc);
    } else {
        co.setTransferStatus(ContentObject.TransferStatus.DONE);
        co.setExtResponse((ExternalResponseObject) data);
        co.getTransferListener().transferComplete(co);
    }
}
Also used : BaseDataType(com.vodafone360.people.datatypes.BaseDataType) ExternalResponseObject(com.vodafone360.people.datatypes.ExternalResponseObject)

Example 3 with ExternalResponseObject

use of com.vodafone360.people.datatypes.ExternalResponseObject in project 360-Engine-for-Android by 360.

the class ThumbnailUtilsTest method generateExternalResponseObject.

/***
     * Creates a dummy ExternalResponseObject.
     *
     * @return Dummy ExternalResponseObject
     * @throws IOException Issue opening an Android resource.
     */
private ExternalResponseObject generateExternalResponseObject() throws IOException {
    /** Generate image byte array. **/
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    InputStream is = getContext().getResources().openRawResource(R.drawable.android_r2_background_pattern_black);
    int temp;
    while ((temp = is.read()) != -1) {
        os.write((char) temp);
    }
    /** Create a dummy ExternalResponseObject. **/
    ExternalResponseObject ero = new ExternalResponseObject();
    ero.mBody = null;
    ero.mBody = os.toByteArray();
    return ero;
}
Also used : ExternalResponseObject(com.vodafone360.people.datatypes.ExternalResponseObject) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with ExternalResponseObject

use of com.vodafone360.people.datatypes.ExternalResponseObject in project 360-Engine-for-Android by 360.

the class SyncMeEngine method processMeProfileThumbnailResponse.

/**
     * This method stores the thumbnail picture for the me profile
     * @param resp Response - normally contains ExternalResponseObject for the
     *            picture
     */
private void processMeProfileThumbnailResponse(final DecodedResponse resp) {
    if (resp.mDataTypes.size() == 0) {
        LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse():" + SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR);
        completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
        return;
    }
    Contact currentMeProfile = new Contact();
    ServiceStatus status = SyncMeDbUtils.fetchMeProfile(mDbHelper, currentMeProfile);
    if (status == ServiceStatus.SUCCESS) {
        if (resp.mReqId == null || resp.mReqId == 0) {
            if (resp.mDataTypes.get(0).getType() == BaseDataType.SYSTEM_NOTIFICATION_DATA_TYPE && ((SystemNotification) resp.mDataTypes.get(0)).getSysCode() == SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR) {
                LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse():" + SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR);
            }
            completeUiRequest(status);
            return;
        } else if (resp.mDataTypes.get(0).getType() == BaseDataType.SYSTEM_NOTIFICATION_DATA_TYPE) {
            if (((SystemNotification) resp.mDataTypes.get(0)).getSysCode() == SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR) {
                LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse():" + SystemNotification.SysNotificationCode.EXTERNAL_HTTP_ERROR);
            }
            completeUiRequest(status);
            return;
        }
        status = BaseEngine.getResponseStatus(BaseDataType.EXTERNAL_RESPONSE_OBJECT_DATA_TYPE, resp.mDataTypes);
        if (status != ServiceStatus.SUCCESS) {
            completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse() - Can't read response");
            return;
        }
        if (resp.mDataTypes == null || resp.mDataTypes.isEmpty()) {
            LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse() - Datatypes are null");
            completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            return;
        }
        // finally save the thumbnails
        ExternalResponseObject ext = (ExternalResponseObject) resp.mDataTypes.get(0);
        if (ext.mBody == null) {
            LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse() - no body");
            completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
            return;
        }
        try {
            ThumbnailUtils.saveExternalResponseObjectToFile(currentMeProfile.localContactID, ext);
            ContactSummaryTable.modifyPictureLoadedFlag(currentMeProfile.localContactID, true, mDbHelper.getWritableDatabase());
            mDbHelper.markMeProfileAvatarChanged();
        } catch (IOException e) {
            LogUtils.logE("SyncMeProfile processMeProfileThumbnailResponse()", e);
            completeUiRequest(ServiceStatus.ERROR_COMMS_BAD_RESPONSE);
        }
    }
    completeUiRequest(status);
}
Also used : SystemNotification(com.vodafone360.people.datatypes.SystemNotification) ExternalResponseObject(com.vodafone360.people.datatypes.ExternalResponseObject) ServiceStatus(com.vodafone360.people.service.ServiceStatus) IOException(java.io.IOException) Contact(com.vodafone360.people.datatypes.Contact)

Aggregations

ExternalResponseObject (com.vodafone360.people.datatypes.ExternalResponseObject)4 IOException (java.io.IOException)2 BaseDataType (com.vodafone360.people.datatypes.BaseDataType)1 Contact (com.vodafone360.people.datatypes.Contact)1 SystemNotification (com.vodafone360.people.datatypes.SystemNotification)1 ServiceStatus (com.vodafone360.people.service.ServiceStatus)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1