com.amazonaws.Request.getHttpMethod()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中com.amazonaws.Request.getHttpMethod方法的一些代码示例,展示了Request.getHttpMethod的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getHttpMethod方法的具体详情如下:
包路径:com.amazonaws.Request
类名称:Request
方法名:getHttpMethod

Request.getHttpMethod介绍

[英]Returns the HTTP method (GET, POST, etc) to use when sending this request.
[中]返回发送此请求时要使用的HTTP方法(GET、POST等)。

代码示例

代码示例来源:origin: aws/aws-sdk-java

@Override
  public void beforeRequest(Request<?> request) {
    request.addHandlerContext(S3HandlerContextKeys.IS_PAYLOAD_SIGNING_ENABLED, true);
    if (request.getContent() == null && request.getHttpMethod() == HttpMethodName.POST) {
      request.setContent(new ByteArrayInputStream(new byte[0]));
    }
  }
}

代码示例来源:origin: aws/aws-sdk-java

private S3Signer createSigV2Signer(final Request<?> request,
                    final String bucketName,
                    final String key) {
  String resourcePath = "/" +
      ((bucketName != null) ? bucketName + "/" : "") +
      ((key != null) ? key : "");
  return new S3Signer(request.getHttpMethod().toString(), resourcePath);
}

代码示例来源:origin: aws/aws-sdk-java

@Override
  public void beforeRequest(Request<?> request) {
    if (request.getOriginalRequest() instanceof SearchRequest && request.getHttpMethod() == HttpMethodName.GET) {
      request.setHttpMethod(HttpMethodName.POST);
      final byte[] content = SdkHttpUtils.encodeParameters(request).getBytes();
      request.setContent(new ByteArrayInputStream(content));
      request.addHeader("Content-Type", "application/x-www-form-urlencoded");
      request.addHeader("Content-Length", Integer.toString(content.length));
      request.getParameters().clear();
    }
  }
}

代码示例来源:origin: aws/aws-sdk-java

private HttpRequestBase createApacheRequest(Request<?> request, String uri, String encodedParams) throws FakeIOException {
  switch (request.getHttpMethod()) {
    case HEAD:
      return new HttpHead(uri);
    case GET:
      return wrapEntity(request, new HttpGetWithBody(uri), encodedParams);
    case DELETE:
      return new HttpDelete(uri);
    case OPTIONS:
      return new HttpOptions(uri);
    case PATCH:
      return wrapEntity(request, new HttpPatch(uri), encodedParams);
    case POST:
      return wrapEntity(request, new HttpPost(uri), encodedParams);
    case PUT:
      return wrapEntity(request, new HttpPut(uri), encodedParams);
    default:
      throw new SdkClientException("Unknown HTTP method name: " + request.getHttpMethod());
  }
}

代码示例来源:origin: aws/aws-sdk-java

/**
 * Adapts an SDK {@link Request} object to a Netty {@link HttpRequest}.
 */
public static HttpRequest adapt(Request<?> sdkRequest) {
  String uri = uriFrom(sdkRequest);
  HttpMethod method = toNettyHttpMethod(sdkRequest.getHttpMethod());
  DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, uri, new DefaultHttpHeaders());
  for (Map.Entry<String, String> header : sdkRequest.getHeaders().entrySet()) {
    request.headers().add(header.getKey(), resolveValue(header.getValue()));
  }
  return request;
}

代码示例来源:origin: aws/aws-sdk-java

private void addRequestConfig(final HttpRequestBase base,
               final Request<?> request,
               final HttpClientSettings settings) {
  final RequestConfig.Builder requestConfigBuilder = RequestConfig
      .custom()
      .setConnectionRequestTimeout(settings.getConnectionPoolRequestTimeout())
      .setConnectTimeout(settings.getConnectionTimeout())
      .setSocketTimeout(settings.getSocketTimeout())
      .setLocalAddress(settings.getLocalAddress());
  /*
   * Enable 100-continue support for PUT operations, since this is
   * where we're potentially uploading large amounts of data and want
   * to find out as early as possible if an operation will fail. We
   * don't want to do this for all operations since it will cause
   * extra latency in the network interaction.
   */
  if (HttpMethodName.PUT == request.getHttpMethod() && settings.isUseExpectContinue()) {
    requestConfigBuilder.setExpectContinueEnabled(true);
  }
  addProxyConfig(requestConfigBuilder, settings);
  base.setConfig(requestConfigBuilder.build());
}

代码示例来源:origin: aws/aws-sdk-java

String encodedParams) throws FakeIOException {
if (HttpMethodName.POST == request.getHttpMethod()) {

代码示例来源:origin: aws/aws-sdk-java

|| httpResponse.getRequest().getHttpMethod() == HttpMethodName.HEAD) {
return createExceptionFromHeaders(httpResponse, null);

代码示例来源:origin: aws/aws-sdk-java

@Override
public HttpRequestBase create(final Request<?> request,
               final HttpClientSettings settings)
    throws
    FakeIOException {
  URI endpoint = request.getEndpoint();
  /*
   * HttpClient cannot handle url in pattern of "http://host//path", so we
   * have to escape the double-slash between endpoint and resource-path
   * into "/%2F"
   */
  String uri = SdkHttpUtils.appendUri(endpoint.toString(), request
      .getResourcePath(), true);
  String encodedParams = SdkHttpUtils.encodeParameters(request);
  /*
   * For all non-POST requests, and any POST requests that already have a
   * payload, we put the encoded params directly in the URI, otherwise,
   * we'll put them in the POST request's payload.
   */
  boolean requestHasNoPayload = request.getContent() != null;
  boolean requestIsPost = request.getHttpMethod() == HttpMethodName.POST;
  boolean putParamsInUri = !requestIsPost || requestHasNoPayload;
  if (encodedParams != null && putParamsInUri) {
    uri += "?" + encodedParams;
  }
  final HttpRequestBase base = createApacheRequest(request, uri, encodedParams);
  addHeadersToRequest(base, request);
  addRequestConfig(base, request, settings);
  return base;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * @return the {@link HttpMethodName}
 */
public HttpMethodName getHttpMethod() {
  return request.getHttpMethod();
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * @param request the request.
 * @return true if request is post and request has no payload.
 */
public static boolean usePayloadForQueryParameters(Request<?> request) {
  final boolean requestIsPOST = HttpMethodName.POST.equals(request.getHttpMethod());
  final boolean requestHasNoPayload = (request.getContent() == null);
  return requestIsPOST && requestHasNoPayload;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

private S3Signer createSigV2Signer(final Request<?> request,
                  final String bucketName,
                  final String key) {
  final String resourcePath = "/" +
      ((bucketName != null) ? bucketName + "/" : "") +
      ((key != null) ? key : "");
  return new S3Signer(request.getHttpMethod().toString(), resourcePath);
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

private HttpRequestBase createApacheRequest(Request<?> request, String uri, String encodedParams) throws FakeIOException {
  switch (request.getHttpMethod()) {
    case HEAD:
      return new HttpHead(uri);
    case GET:
      return wrapEntity(request, new HttpGetWithBody(uri), encodedParams);
    case DELETE:
      return new HttpDelete(uri);
    case OPTIONS:
      return new HttpOptions(uri);
    case PATCH:
      return wrapEntity(request, new HttpPatch(uri), encodedParams);
    case POST:
      return wrapEntity(request, new HttpPost(uri), encodedParams);
    case PUT:
      return wrapEntity(request, new HttpPut(uri), encodedParams);
    default:
      throw new SdkClientException("Unknown HTTP method name: " + request.getHttpMethod());
  }
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreateRequest() {
  final String bucketName = "bucket";
  final String key = "key";
  final File file = new File(key);
  final HttpMethodName method = HttpMethodName.PUT;
  final PutObjectRequest originalRequest = new PutObjectRequest(bucketName, key, file);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  assertEquals(String.format("%s.s3.amazonaws.com", bucketName),
      request.getEndpoint().getHost());
  assertEquals(method, request.getHttpMethod());
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreatePutObjectRequestWithSpecialCharacterKeys() {
  final String bucketName = "bucket";
  final String key = "key%^!@#*()";
  final File file = new File(key);
  final HttpMethodName method = HttpMethodName.PUT;
  final PutObjectRequest originalRequest = new PutObjectRequest(bucketName, key, file);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  assertEquals(String.format("%s.s3.amazonaws.com", bucketName),
      request.getEndpoint().getHost());
  assertEquals(method, request.getHttpMethod());
  assertTrue(request.getResourcePath().contains(key));
}

代码示例来源:origin: aws-amplify/aws-sdk-android

protected String getCanonicalRequest(Request<?> request, String contentSha256) {
  /* This would url-encode the resource path for the first time */
  final String path = HttpUtils.appendUri(request.getEndpoint().getPath(),
      request.getResourcePath());
  final String canonicalRequest =
      request.getHttpMethod().toString() + "\n" +
          /*
           * This would optionally double url-encode the resource
           * path
           */
          getCanonicalizedResourcePath(path, doubleUrlEncode) + "\n" +
          getCanonicalizedQueryString(request) + "\n" +
          getCanonicalizedHeaderString(request) + "\n" +
          getSignedHeadersString(request) + "\n" +
          contentSha256;
  log.debug("AWS4 Canonical Request: '\"" + canonicalRequest + "\"");
  return canonicalRequest;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreateRequestAccelerate() {
  s3.setS3ClientOptions(accelerateOption);
  final String bucketName = "bucket";
  final String key = "key";
  final File file = new File(key);
  final HttpMethodName method = HttpMethodName.PUT;
  final PutObjectRequest originalRequest = new PutObjectRequest(bucketName, key, file);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  assertEquals(String.format("%s.s3-accelerate.amazonaws.com", bucketName),
      request.getEndpoint().getHost());
  assertEquals(method, request.getHttpMethod());
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreateRequestNonDNS() {
  final String bucketName = "bucket.with.dot";
  final String key = "key";
  final File file = new File(key);
  final HttpMethodName method = HttpMethodName.PUT;
  final PutObjectRequest originalRequest = new PutObjectRequest(bucketName, key, file);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  assertEquals("s3.amazonaws.com", request.getEndpoint().getHost());
  assertEquals(String.format("%s/%s", bucketName, key), request.getResourcePath());
  assertEquals(method, request.getHttpMethod());
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreateGetObjectRequestWithSpecialCharacterKeys() {
  final String bucketName = "bucket";
  final String key = "key%^!@#*()";
  final HttpMethodName method = HttpMethodName.GET;
  final GetObjectRequest originalRequest = new GetObjectRequest(bucketName, key);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  assertEquals(String.format("%s.s3.amazonaws.com", bucketName),
      request.getEndpoint().getHost());
  assertEquals(method, request.getHttpMethod());
  assertTrue(request.getResourcePath().contains(key));
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreateRequestAccelerateUnsupportedMethod() {
  s3.setS3ClientOptions(accelerateOption);
  final String bucketName = "bucket";
  final HttpMethodName method = HttpMethodName.DELETE;
  final DeleteBucketRequest originalRequest = new DeleteBucketRequest(bucketName);
  final Request<?> request = s3.createRequest(bucketName, null, originalRequest, method);
  assertEquals(String.format("%s.s3.amazonaws.com", bucketName),
      request.getEndpoint().getHost());
  assertEquals(method, request.getHttpMethod());
}

相关文章