Example #1
0
 /** Background processing */
 public void run() {
   try {
     if (sLogger.isActivated()) {
       sLogger.info("Initiate a new HTTP upload ".concat(mUploadId));
     }
     /* Create fileIcon content is requested */
     MmContent fileIconContent = null;
     if (mFileIcon) {
       fileIconContent = FileTransferUtils.createFileicon(mFile.getUri(), mUploadId, mRcsSettings);
     }
     mUploadManager = new HttpUploadManager(mFile, fileIconContent, this, mUploadId, mRcsSettings);
     byte[] result = mUploadManager.uploadFile();
     storeResult(result);
   } catch (SecurityException e) {
     sLogger.error(
         "File icon creation has failed as the file is not accessible for HTTP uploadId "
             .concat(mUploadId),
         e);
     removeSession();
     mListener.handleUploadNotAllowedToSend();
   } catch (IOException e) {
     if (sLogger.isActivated()) {
       sLogger.debug(e.getMessage());
     }
     removeSession();
     mListener.handleUploadError(FileSharingError.MEDIA_UPLOAD_FAILED);
   } catch (FileAccessException e) {
     sLogger.error("Failed to initiate session for HTTP uploadId ".concat(mUploadId), e);
     removeSession();
     mListener.handleUploadError(FileSharingError.MEDIA_UPLOAD_FAILED);
   } catch (PayloadException e) {
     sLogger.error("Failed to initiate session for HTTP uploadId ".concat(mUploadId), e);
     removeSession();
     mListener.handleUploadError(FileSharingError.MEDIA_UPLOAD_FAILED);
   } catch (NetworkException e) {
     if (sLogger.isActivated()) {
       sLogger.debug(e.getMessage());
     }
     removeSession();
     mListener.handleUploadError(FileSharingError.MEDIA_UPLOAD_FAILED);
   } catch (RuntimeException e) {
     /*
      * Intentionally catch runtime exceptions as else it will abruptly end the thread and
      * eventually bring the whole system down, which is not intended.
      */
     sLogger.error("Failed to initiate session for HTTP uploadId ".concat(mUploadId), e);
     removeSession();
     mListener.handleUploadError(FileSharingError.MEDIA_UPLOAD_FAILED);
   }
 }
Example #2
0
  /**
   * Analyze the result
   *
   * @param result Byte array result
   * @throws PayloadException
   */
  private void storeResult(byte[] result) throws PayloadException {
    // Check if upload has been cancelled
    if (mUploadManager.isCancelled()) {
      return;
    }

    // Parse the result:
    // <?xml version="1.0" encoding="UTF-8"?>
    // <file>
    // <file-info type="thumbnail">
    // <file-size>6208</file-size>
    // <content-type>image/jpeg</content-type>
    // <data url = "https://ftcontentserver.rcs/download?id=001"
    // until="2014-08-13T17:42:10.000+02:00"/>
    // </file-info>
    //
    // <file-info type="file">
    // <file-size>1699846</file-size>
    // <file-name>IMG_20140805_134311.jpg</file-name>
    // <content-type>image/jpeg</content-type>
    // <data url = "https://ftcontentserver.rcs/download?id=abb"
    // until="2014-08-13T17:42:10.000+02:00"/>
    // </file-info>
    // </file>
    if (result != null) {
      mFileInfoDoc = FileTransferUtils.parseFileTransferHttpDocument(result, mRcsSettings);
    }
    if (mFileInfoDoc != null) {
      // File uploaded with success
      if (sLogger.isActivated()) {
        sLogger.debug("Upload done with success: ".concat(mFileInfoDoc.getUri().toString()));
      }

      removeSession();
      mListener.handleUploadTerminated(mFileInfoDoc);
    } else {
      // Upload error
      if (sLogger.isActivated()) {
        sLogger.debug("Upload has failed");
      }
      removeSession();
      // Notify listener
      mListener.handleUploadError(FileSharingError.MEDIA_UPLOAD_FAILED);
    }
  }