/**
  * Resets the specified request, so that it can be sent again, after receiving the specified
  * error. If a problem is encountered with resetting the request, then an AmazonClientException is
  * thrown with the original error as the cause (not an error about being unable to reset the
  * stream).
  *
  * @param request The request being executed that failed and needs to be reset.
  * @param cause The original error that caused the request to fail.
  * @throws AmazonClientException If the request can't be reset.
  */
 private void resetRequestAfterError(Request<?> request, Exception cause)
     throws AmazonClientException {
   if (request.getContent() != null && request.getContent().markSupported()) {
     try {
       request.getContent().reset();
     } catch (IOException e) {
       // This exception comes from being unable to reset the input stream,
       // so throw the original, more meaningful exception
       throw new AmazonClientException(
           "Encountered an exception and couldn't reset the stream to retry", cause);
     }
   }
 }
  @Override
  public void beforeRequest(com.amazonaws.Request<?> request) {
    // TODO: factor in clockskew
    startTime = System.currentTimeMillis();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream is = request.getContent();
    int currentByte = 0;
    try {
      while ((currentByte = is.read()) != -1) {
        baos.write(currentByte);
      }

      contentLength = baos.size();
      request.setContent(new ByteArrayInputStream(baos.toByteArray()));
    } catch (IOException e) {
      Log.e(TAG, "Cannot read content of request");
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 3
0
  public static boolean usePayloadForQueryParameters(Request<?> request) {
    boolean requestIsPOST = HttpMethodName.POST.equals(request.getHttpMethod());
    boolean requestHasNoPayload = (request.getContent() == null);

    return requestIsPOST && requestHasNoPayload;
  }