/** Background processing */ public void run() { try { if (logger.isActivated()) { logger.info("Initiate a new HTTP group file transfer session as originating"); } // Upload the file to the HTTP server byte[] result = uploadManager.uploadFile(); sendResultToContact(result); } catch (Exception e) { if (logger.isActivated()) { logger.error("File transfer has failed", e); } // Unexpected error handleError(new FileSharingError(FileSharingError.UNEXPECTED_EXCEPTION, e.getMessage())); } }
/** * 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 } }
/** Pausing the transfer */ @Override public void pauseFileTransfer() { fileTransferPaused(); interruptSession(); uploadManager.getListener().httpTransferPaused(); }
@Override public void interrupt() { super.interrupt(); uploadManager.interrupt(); }