コード例 #1
0
  /** Send the file transfer information */
  private void sendFileTransferInfo() {
    // Send File transfer Info
    String mime = CpimMessage.MIME_TYPE;
    String from = ImsModule.IMS_USER_PROFILE.getPublicUri();
    String to = ChatUtils.ANOMYNOUS_URI;
    String msgId = IdGenerator.getIdentifier();

    // Send file info in CPIM message
    String content =
        ChatUtils.buildCpimMessageWithImdn(
            from, to, msgId, fileInfo, FileTransferHttpInfoDocument.MIME_TYPE);

    // Send content
    chatSession.sendDataChunks(ChatUtils.generateMessageId(), content, mime);
    RichMessaging.getInstance()
        .updateFileTransferChatId(getSessionID(), chatSession.getContributionID(), msgId);
  }
コード例 #2
0
  /**
   * Prepare to send the info to terminating side
   *
   * @param result byte[] which contains the result of the 200 OK from the content server
   */
  private void sendResultToContact(byte[] result) {
    // Check if upload is cancelled
    if (uploadManager.isCancelled()) {
      return;
    }

    if (result != null && ChatUtils.parseFileTransferHttpDocument(result) != null) {
      fileInfo = new String(result);
      if (logger.isActivated()) {
        logger.debug("Upload done with success: " + fileInfo);
      }

      // Send the file transfer info via a chat message
      chatSession = (ChatSession) Core.getInstance().getImService().getSession(getChatSessionID());
      if (chatSession == null) {
        Vector<ChatSession> chatSessions =
            Core.getInstance().getImService().getImSessionsWith(participants.getList());
        try {
          chatSession = chatSessions.lastElement();
          setChatSessionID(chatSession.getSessionID());
          setContributionID(chatSession.getContributionID());
          if (logger.isActivated()) {
            logger.debug("Chat session found with participants");
          }
        } catch (NoSuchElementException nsee) {
          chatSession = null;
          if (logger.isActivated()) {
            logger.debug("No such Chat session found with participants");
          }
        }
      }
      if (chatSession != null) {
        // A chat session exists
        if (logger.isActivated()) {
          logger.debug("Send file transfer info via an existing chat session");
        }

        // Send file transfer info
        sendFileTransferInfo();

        // File transfered
        handleFileTransfered();
      } else {
        logger.debug("sendResultToContact error 1");
        // No chat error
        handleError(new FileSharingError(FileSharingError.NO_CHAT_SESSION));
      }
    } else {
      if (logger.isActivated()) {
        logger.debug("Upload has failed");
      }

      try {
        Thread.sleep(5 * 1000);
      } catch (InterruptedException e) {
        // Nothing to do
        logger.debug("sendResultToContact excepion in thread 1");
      }

      if (!uploadManager.isCancelled()) {
        logger.debug("Upload is cancelled123");
        try {
          Thread.sleep(10 * 1000);
        } catch (InterruptedException e) {
          // Nothing to do
          logger.debug("sendResultToContact excepion in thread 2");
        }
        if (!uploadManager.isCancelled()) {
          logger.debug("Upload is cancelled234");
          handleError(new FileSharingError(FileSharingError.MEDIA_UPLOAD_FAILED));
        }
      }

      // Upload error
    }
  }