Beispiel #1
0
  /** Close the session */
  public void close() {
    if (sLogger.isActivated()) {
      sLogger.debug("Close session");
    }

    // Cancel transfer
    mCancelTransfer = true;

    // Close the connection
    if (connection != null) {
      connection.close();
    }

    // Unblock request transaction
    if (mRequestTransaction != null) {
      mRequestTransaction.terminate();
    }

    // Unblock report transaction
    if (mReportTransaction != null) {
      mReportTransaction.terminate();
    }

    // Unblock MSRP transaction
    if (mMsrpTransaction != null) {
      mMsrpTransaction.terminate();
    }
  }
Beispiel #2
0
  // Changed by Deutsche Telekom
  private void sendEmptyMsrpSendRequest(String txId, String to, String from, String msrpMsgId)
      throws NetworkException {
    ByteArrayOutputStream buffer = null;
    try {
      buffer = new ByteArrayOutputStream(4000);
      buffer.reset();
      buffer.write(MsrpConstants.MSRP_HEADER.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write(txId.getBytes(UTF8));
      buffer.write((" " + MsrpConstants.METHOD_SEND).getBytes(UTF8));
      buffer.write(NEW_LINE);

      String toHeader = MsrpConstants.HEADER_TO_PATH + ": " + to + MsrpConstants.NEW_LINE;
      buffer.write(toHeader.getBytes(UTF8));
      String fromHeader = MsrpConstants.HEADER_FROM_PATH + ": " + from + MsrpConstants.NEW_LINE;
      buffer.write(fromHeader.getBytes(UTF8));
      // Changed by Deutsche Telekom
      String msgIdHeader =
          MsrpConstants.HEADER_MESSAGE_ID + ": " + msrpMsgId + MsrpConstants.NEW_LINE;
      buffer.write(msgIdHeader.getBytes(UTF8));

      /* Write end of request */
      buffer.write(MsrpConstants.END_MSRP_MSG.getBytes(UTF8));
      buffer.write(txId.getBytes(UTF8));
      /* '$' -> last chunk */
      buffer.write(MsrpConstants.FLAG_LAST_CHUNK);
      buffer.write(NEW_LINE);

      mRequestTransaction = new RequestTransaction(mRcsSettings);
      connection.sendChunkImmediately(buffer.toByteArray());

      mRequestTransaction.waitResponse();
      if (!mRequestTransaction.isResponseReceived()) {
        throw new NetworkException("Failed to receive transaction response!");
      }
    } catch (IOException e) {
      throw new NetworkException("Failed to send empty Msrp send request!", e);

    } finally {
      CloseableUtils.tryToClose(buffer);
    }
  }
Beispiel #3
0
  /**
   * Receive MSRP response
   *
   * @param code Response code
   * @param txId Transaction ID
   * @param headers MSRP headers
   */
  public void receiveMsrpResponse(int code, String txId, Hashtable<String, String> headers) {
    // Consider media is established when we received something
    mIsEstablished = true;

    if (sLogger.isActivated()) {
      sLogger.info("Response received (code=" + code + ", transaction=" + txId + ")");
    }

    if (mFailureReportOption) {
      // Notify progress
      if (!mCancelTransfer && mProgress.size() > 0) {
        mMsrpEventListener.msrpTransferProgress(mProgress.elementAt(0), mTotalSize);
        mProgress.removeElementAt(0);
      }
    }

    // Notify request transaction
    if (mRequestTransaction != null) {
      mRequestTransaction.notifyResponse(code, headers);
    }

    // Notify MSRP transaction
    if (mMsrpTransaction != null) {
      mMsrpTransaction.handleResponse();
    }

    // Notify event listener
    if (code != 200) {
      // Changed by Deutsche Telekom
      String cpimMsgId = null;
      TypeMsrpChunk typeMsrpChunk = TypeMsrpChunk.Unknown;
      MsrpTransactionInfo msrpTransactionInfo = getMsrpTransactionInfo(txId);
      if (msrpTransactionInfo != null) {
        cpimMsgId = msrpTransactionInfo.mCpimMsgId;
        typeMsrpChunk = msrpTransactionInfo.mTypeMsrpChunk;
      }
      mMsrpEventListener.msrpTransferError(cpimMsgId, "error response " + code, typeMsrpChunk);

      // Changed by Deutsche Telekom
      // If an error is received it couldn't get any better nor worse; transaction has reached
      // final state
      removeMsrpTransactionInfo(txId);
    }

    // Don't remove transaction info in general from list as this could be a preliminary answer
  }
Beispiel #4
0
  // Changed by Deutsche Telekom
  private void sendMsrpSendRequest(
      String txId,
      String to,
      String from,
      String msrpMsgId,
      String contentType,
      int dataSize,
      byte data[],
      long firstByte,
      long lastByte,
      long totalSize)
      throws NetworkException {
    ByteArrayOutputStream buffer = null;
    try {
      boolean isLastChunk = (lastByte == totalSize);
      // Create request
      buffer = new ByteArrayOutputStream(4000);
      buffer.reset();
      buffer.write(MsrpConstants.MSRP_HEADER.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write(txId.getBytes(UTF8));
      buffer.write((" " + MsrpConstants.METHOD_SEND).getBytes(UTF8));
      buffer.write(NEW_LINE);

      String toHeader = MsrpConstants.HEADER_TO_PATH + ": " + to + MsrpConstants.NEW_LINE;
      buffer.write(toHeader.getBytes(UTF8));
      String fromHeader = MsrpConstants.HEADER_FROM_PATH + ": " + from + MsrpConstants.NEW_LINE;
      buffer.write(fromHeader.getBytes(UTF8));
      // Changed by Deutsche Telekom
      String msgIdHeader =
          MsrpConstants.HEADER_MESSAGE_ID + ": " + msrpMsgId + MsrpConstants.NEW_LINE;
      buffer.write(msgIdHeader.getBytes(UTF8));

      // Write byte range
      String byteRange =
          MsrpConstants.HEADER_BYTE_RANGE
              + ": "
              + firstByte
              + "-"
              + lastByte
              + "/"
              + totalSize
              + MsrpConstants.NEW_LINE;
      buffer.write(byteRange.getBytes(UTF8));

      // Write optional headers
      // Changed by Deutsche Telekom
      // According with GSMA guidelines
      if (mFailureReportOption) {
        String header = MsrpConstants.HEADER_FAILURE_REPORT + ": yes" + MsrpConstants.NEW_LINE;
        buffer.write(header.getBytes(UTF8));
      }
      if (mSuccessReportOption) {
        String header = MsrpConstants.HEADER_SUCCESS_REPORT + ": yes" + MsrpConstants.NEW_LINE;
        buffer.write(header.getBytes(UTF8));
      }

      // Write content type
      if (contentType != null) {
        String content =
            MsrpConstants.HEADER_CONTENT_TYPE + ": " + contentType + MsrpConstants.NEW_LINE;
        buffer.write(content.getBytes(UTF8));
      }

      // Write data
      if (data != null) {
        buffer.write(NEW_LINE);
        buffer.write(data, 0, dataSize);
        buffer.write(NEW_LINE);
      }

      // Write end of request
      buffer.write(MsrpConstants.END_MSRP_MSG.getBytes(UTF8));
      buffer.write(txId.getBytes(UTF8));
      if (isLastChunk) {
        // '$' -> last chunk
        buffer.write(MsrpConstants.FLAG_LAST_CHUNK);
      } else {
        // '+' -> more chunk
        buffer.write(MsrpConstants.FLAG_MORE_CHUNK);
      }
      buffer.write(NEW_LINE);

      // Send chunk
      if (mFailureReportOption) {
        if (mMsrpTransaction != null) {
          mMsrpTransaction.handleRequest();
          mRequestTransaction = null;
        } else {
          mRequestTransaction = new RequestTransaction(mRcsSettings);
        }
        connection.sendChunk(buffer.toByteArray());
        buffer.close();
        if (mRequestTransaction != null) {
          mRequestTransaction.waitResponse();
          if (!mRequestTransaction.isResponseReceived()) {
            throw new NetworkException("Failed to receive transaction response!");
          }
        }
      } else {
        connection.sendChunk(buffer.toByteArray());
        buffer.close();
        if (mMsrpTransaction != null) {
          mMsrpTransaction.handleRequest();
        }
      }
    } catch (IOException e) {
      throw new NetworkException("Failed to read chunk data!", e);

    } finally {
      CloseableUtils.tryToClose(buffer);
    }
  }