コード例 #1
0
  /**
   * Handles a PUT request from a client. This method will provide a <code>ServerOperation</code>
   * object to the request handler. The <code>ServerOperation</code> object will handle the rest of
   * the request. It will also send replies and receive requests until the final reply should be
   * sent. When the final reply should be sent, this method will get the response code to use and
   * send the reply. The <code>ServerOperation</code> object will always reply with a
   * OBEX_HTTP_CONTINUE reply. It will only reply if further information is needed.
   *
   * @param type the type of request received; either 0x02 or 0x82
   * @throws IOException if an error occurred at the transport layer
   */
  private void handlePutRequest(int type) throws IOException {
    ServerOperation op = new ServerOperation(this, mInput, type, mMaxPacketLength, mListener);
    try {
      int response = -1;

      if ((op.finalBitSet) && !op.isValidBody()) {
        response = validateResponseCode(mListener.onDelete(op.requestHeader, op.replyHeader));
      } else {
        response = validateResponseCode(mListener.onPut(op));
      }
      if (response != ResponseCodes.OBEX_HTTP_OK && !op.isAborted) {
        op.sendReply(response);
      } else if (!op.isAborted) {
        // wait for the final bit
        while (!op.finalBitSet) {
          op.sendReply(ResponseCodes.OBEX_HTTP_CONTINUE);
        }
        op.sendReply(response);
      }
    } catch (Exception e) {
      /*To fix bugs in aborted cases,
       *(client abort file transfer prior to the last packet which has the end of body header,
       *internal error should not be sent because server has already replied with
       *OK response in "sendReply")
       */
      if (!op.isAborted) {
        sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null);
      }
    }
  }
コード例 #2
0
  /**
   * Handles a GET request from a client. This method will provide a <code>ServerOperation</code>
   * object to the request handler. The <code>ServerOperation</code> object will handle the rest of
   * the request. It will also send replies and receive requests until the final reply should be
   * sent. When the final reply should be sent, this method will get the response code to use and
   * send the reply. The <code>ServerOperation</code> object will always reply with a
   * OBEX_HTTP_CONTINUE reply. It will only reply if further information is needed.
   *
   * @param type the type of request received; either 0x03 or 0x83
   * @throws IOException if an error occurred at the transport layer
   */
  private void handleGetRequest(int type) throws IOException {
    ServerOperation op = new ServerOperation(this, mInput, type, mMaxPacketLength, mListener);
    try {
      int response = validateResponseCode(mListener.onGet(op));

      if (!op.isAborted) {
        op.sendReply(response);
      }
    } catch (Exception e) {
      sendResponse(ResponseCodes.OBEX_HTTP_INTERNAL_ERROR, null);
    }
  }