/** * 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); } }
/** * 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); } }