Esempio n. 1
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);
    }
  }
Esempio n. 2
0
  /**
   * Send MSRP response
   *
   * @param code Response code
   * @param txId Transaction ID
   * @param headers MSRP headers
   * @throws NetworkException
   */
  private void sendMsrpResponse(String code, String txId, Hashtable<String, String> headers)
      throws NetworkException {
    ByteArrayOutputStream buffer = null;
    try {
      buffer = new ByteArrayOutputStream(4000);
      buffer.write(MsrpConstants.MSRP_HEADER.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write(txId.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write(code.getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.HEADER_TO_PATH.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_DOUBLE_POINT);
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write((headers.get(MsrpConstants.HEADER_FROM_PATH)).getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.HEADER_FROM_PATH.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_DOUBLE_POINT);
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write((headers.get(MsrpConstants.HEADER_TO_PATH)).getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.END_MSRP_MSG.getBytes(UTF8));
      buffer.write(txId.getBytes(UTF8));
      buffer.write(MsrpConstants.FLAG_LAST_CHUNK);
      buffer.write(NEW_LINE);

      connection.sendChunk(buffer.toByteArray());
    } catch (IOException e) {
      throw new NetworkException("Failed to send Msrp response!", e);

    } finally {
      CloseableUtils.tryToClose(buffer);
    }
  }
Esempio n. 3
0
  /**
   * Send MSRP REPORT request
   *
   * @param txId Transaction ID
   * @param headers MSRP headers
   * @throws NetworkException
   */
  private void sendMsrpReportRequest(
      String txId, Hashtable<String, String> headers, long lastByte, long totalSize)
      throws NetworkException {
    ByteArrayOutputStream buffer = null;
    try {
      // 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_REPORT).getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.HEADER_TO_PATH.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_DOUBLE_POINT);
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write(headers.get(MsrpConstants.HEADER_FROM_PATH).getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.HEADER_FROM_PATH.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_DOUBLE_POINT);
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write((headers.get(MsrpConstants.HEADER_TO_PATH)).getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.HEADER_MESSAGE_ID.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_DOUBLE_POINT);
      buffer.write(MsrpConstants.CHAR_SP);
      buffer.write((headers.get(MsrpConstants.HEADER_MESSAGE_ID)).getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.HEADER_BYTE_RANGE.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_DOUBLE_POINT);
      buffer.write(MsrpConstants.CHAR_SP);
      String byteRange = "1-" + lastByte + "/" + totalSize;
      buffer.write(byteRange.getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.HEADER_STATUS.getBytes(UTF8));
      buffer.write(MsrpConstants.CHAR_DOUBLE_POINT);
      buffer.write(MsrpConstants.CHAR_SP);
      String status = "000 200 OK";
      buffer.write(status.getBytes(UTF8));
      buffer.write(NEW_LINE);

      buffer.write(MsrpConstants.END_MSRP_MSG.getBytes(UTF8));
      buffer.write(txId.getBytes(UTF8));
      buffer.write(MsrpConstants.FLAG_LAST_CHUNK);
      buffer.write(NEW_LINE);

      // Send request
      mRequestTransaction = new RequestTransaction(mRcsSettings);
      connection.sendChunk(buffer.toByteArray());
    } catch (IOException e) {
      throw new NetworkException("Failed to send Msrp report request!", e);

    } finally {
      CloseableUtils.tryToClose(buffer);
    }
  }
Esempio n. 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);
    }
  }