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

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

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

Request.addHeader介绍

[英]Sets the specified header for this request.
[中]设置此请求的指定标头。

代码示例

代码示例来源: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 void setContent(Request<?> request, byte[] content, String contentType, boolean setMd5) {
  request.setContent(new ByteArrayInputStream(content));
  request.addHeader("Content-Length", Integer.toString(content.length));
  request.addHeader("Content-Type", contentType);
  if (setMd5) {
    try {
      byte[] md5 = Md5Utils.computeMD5Hash(content);
      String md5Base64 = BinaryUtils.toBase64(md5);
      request.addHeader("Content-MD5", md5Base64);
    } catch ( Exception e ) {
      throw new AmazonClientException("Couldn't compute md5 sum", e);
    }
  }
}

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

public Request<GetPublicAccessBlockRequest> marshall(GetPublicAccessBlockRequest getPublicAccessBlockRequest) {
  if (getPublicAccessBlockRequest == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }
  Request<GetPublicAccessBlockRequest> request = new DefaultRequest<GetPublicAccessBlockRequest>(getPublicAccessBlockRequest, "AWSS3Control");
  request.setHttpMethod(HttpMethodName.GET);
  if (getPublicAccessBlockRequest.getAccountId() != null) {
    request.addHeader("x-amz-account-id", StringUtils.fromString(getPublicAccessBlockRequest.getAccountId()));
  }
  String uriResourcePath = "/v20180820/configuration/publicAccessBlock";
  request.setResourcePath(uriResourcePath);
  return request;
}

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

public Request<UpdateHostedZoneCommentRequest> marshall(UpdateHostedZoneCommentRequest updateHostedZoneCommentRequest) {
  if (updateHostedZoneCommentRequest == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }
  Request<UpdateHostedZoneCommentRequest> request = new DefaultRequest<UpdateHostedZoneCommentRequest>(updateHostedZoneCommentRequest, "AmazonRoute53");
  request.setHttpMethod(HttpMethodName.POST);
  String uriResourcePath = "/2013-04-01/hostedzone/{Id}";
  uriResourcePath = com.amazonaws.transform.PathMarshallers.NON_GREEDY.marshall(uriResourcePath, "Id", updateHostedZoneCommentRequest.getId());
  request.setResourcePath(uriResourcePath);
  try {
    StringWriter stringWriter = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(stringWriter, "https://route53.amazonaws.com/doc/2013-04-01/");
    xmlWriter.startElement("UpdateHostedZoneCommentRequest");
    if (updateHostedZoneCommentRequest != null) {
      if (updateHostedZoneCommentRequest.getComment() != null) {
        xmlWriter.startElement("Comment").value(updateHostedZoneCommentRequest.getComment()).endElement();
      }
    }
    xmlWriter.endElement();
    request.setContent(new StringInputStream(stringWriter.getBuffer().toString()));
    request.addHeader("Content-Length", Integer.toString(stringWriter.getBuffer().toString().getBytes(UTF8).length));
    if (!request.getHeaders().containsKey("Content-Type")) {
      request.addHeader("Content-Type", "application/xml");
    }
  } catch (Throwable t) {
    throw new SdkClientException("Unable to marshall request to XML: " + t.getMessage(), t);
  }
  return request;
}

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

@Override
public void setBucketLifecycleConfiguration(
    SetBucketLifecycleConfigurationRequest setBucketLifecycleConfigurationRequest) {
  setBucketLifecycleConfigurationRequest = beforeClientExecution(setBucketLifecycleConfigurationRequest);
  rejectNull(setBucketLifecycleConfigurationRequest,
      "The set bucket lifecycle configuration request object must be specified.");
  String bucketName = setBucketLifecycleConfigurationRequest.getBucketName();
  BucketLifecycleConfiguration bucketLifecycleConfiguration = setBucketLifecycleConfigurationRequest.getLifecycleConfiguration();
  rejectNull(bucketName,
      "The bucket name parameter must be specified when setting bucket lifecycle configuration.");
  rejectNull(bucketLifecycleConfiguration,
      "The lifecycle configuration parameter must be specified when setting bucket lifecycle configuration.");
  Request<SetBucketLifecycleConfigurationRequest> request = createRequest(bucketName, null, setBucketLifecycleConfigurationRequest, HttpMethodName.PUT);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketLifecycleConfiguration");
  request.addParameter("lifecycle", null);
  byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketLifecycleConfiguration);
  request.addHeader("Content-Length", String.valueOf(content.length));
  request.addHeader("Content-Type", "application/xml");
  request.setContent(new ByteArrayInputStream(content));
  try {
    byte[] md5 = Md5Utils.computeMD5Hash(content);
    String md5Base64 = BinaryUtils.toBase64(md5);
    request.addHeader("Content-MD5", md5Base64);
  } catch ( Exception e ) {
    throw new SdkClientException("Couldn't compute md5 sum", e);
  }
  invoke(request, voidResponseHandler, bucketName, null);
}

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

private Request<OrigRequest> fillBasicRequestParams(OperationInfo operationInfo, OrigRequest originalRequest) {
  Request<OrigRequest> request = createRequest(operationInfo, originalRequest);
  request.setHttpMethod(operationInfo.httpMethodName());
  request.setResourcePath(UriResourcePathUtils.addStaticQueryParamtersToRequest(request, operationInfo.requestUri()));
  if (operationInfo.operationIdentifier() != null) {
    request.addHeader("X-Amz-Target", operationInfo.operationIdentifier());
  }
  return request;
}

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

@Override
public void beforeRequest(Request<?> request) {
  request.addHeader("x-amz-glacier-version", "2012-06-01");
  request.addHeader("x-amz-content-sha256", "required");
    if (resourcePath != null) {
      String newResourcePath = resourcePath.replace("{jobType}", "archive-retrievals");
      request.setResourcePath(newResourcePath);

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

public Request<UpdateTrafficPolicyCommentRequest> marshall(UpdateTrafficPolicyCommentRequest updateTrafficPolicyCommentRequest) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
      "AmazonRoute53");
  request.setHttpMethod(HttpMethodName.POST);
  uriResourcePath = com.amazonaws.transform.PathMarshallers.NON_GREEDY.marshall(uriResourcePath, "Version",
      updateTrafficPolicyCommentRequest.getVersion());
  request.setResourcePath(uriResourcePath);
    StringWriter stringWriter = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(stringWriter, "https://route53.amazonaws.com/doc/2013-04-01/");
    request.setContent(new StringInputStream(stringWriter.getBuffer().toString()));
    request.addHeader("Content-Length", Integer.toString(stringWriter.getBuffer().toString().getBytes(UTF8).length));
    if (!request.getHeaders().containsKey("Content-Type")) {
      request.addHeader("Content-Type", "application/xml");
    throw new SdkClientException("Unable to marshall request to XML: " + t.getMessage(), t);

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

@Override
  public Request<RawRequest> marshall(RawRequest rawRequestRequest) {
    if (rawRequestRequest == null) {
      throw new AmazonClientException("Invalid argument passed to marshall(...)");
    }

    Request<RawRequest> request = new DefaultRequest<>("MyService");

    request.setHttpMethod(rawRequestRequest.httpMethod());
    request.setResourcePath(rawRequestRequest.path());
    request.setContent(rawRequestRequest.payload());

    // Custom headers and query params are set later in the runtime
    if (!request.getHeaders().containsKey("Content-Type")) {
      request.addHeader("Content-Type", protocolFactory.getContentType());
    }

    return request;
  }
}

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

@Override
public Request<OrigRequest> finishMarshalling() {
  // Content may already be set if the payload is binary data.
  if (request.getContent() == null) {
    // End the implicit request object if needed.
    if (!hasExplicitPayloadMember) {
      jsonGenerator.writeEndObject();
    }
    byte[] content = jsonGenerator.getBytes();
    request.setContent(new ByteArrayInputStream(content));
    if (content.length > 0) {
      request.addHeader("Content-Length", Integer.toString(content.length));
    }
  }
  if (!request.getHeaders().containsKey("Content-Type")) {
    request.addHeader("Content-Type", contentType);
  }
  return request;
}

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

@Override
public void setBucketCrossOriginConfiguration(
    SetBucketCrossOriginConfigurationRequest setBucketCrossOriginConfigurationRequest) {
  setBucketCrossOriginConfigurationRequest = beforeClientExecution(setBucketCrossOriginConfigurationRequest);
  rejectNull(setBucketCrossOriginConfigurationRequest,
      "The set bucket cross origin configuration request object must be specified.");
  String bucketName = setBucketCrossOriginConfigurationRequest.getBucketName();
  BucketCrossOriginConfiguration bucketCrossOriginConfiguration = setBucketCrossOriginConfigurationRequest.getCrossOriginConfiguration();
  rejectNull(bucketName,
      "The bucket name parameter must be specified when setting bucket cross origin configuration.");
  rejectNull(bucketCrossOriginConfiguration,
      "The cross origin configuration parameter must be specified when setting bucket cross origin configuration.");
  Request<SetBucketCrossOriginConfigurationRequest> request = createRequest(bucketName, null, setBucketCrossOriginConfigurationRequest, HttpMethodName.PUT);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketCors");
  request.addParameter("cors", null);
  byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketCrossOriginConfiguration);
  request.addHeader("Content-Length", String.valueOf(content.length));
  request.addHeader("Content-Type", "application/xml");
  request.setContent(new ByteArrayInputStream(content));
  try {
    byte[] md5 = Md5Utils.computeMD5Hash(content);
    String md5Base64 = BinaryUtils.toBase64(md5);
    request.addHeader("Content-MD5", md5Base64);
  } catch ( Exception e ) {
    throw new SdkClientException("Couldn't compute md5 sum", e);
  }
  invoke(request, voidResponseHandler, bucketName, null);
}

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

public Request<DeletePublicAccessBlockRequest> marshall(DeletePublicAccessBlockRequest deletePublicAccessBlockRequest) {
  if (deletePublicAccessBlockRequest == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }
  Request<DeletePublicAccessBlockRequest> request = new DefaultRequest<DeletePublicAccessBlockRequest>(deletePublicAccessBlockRequest, "AWSS3Control");
  request.setHttpMethod(HttpMethodName.DELETE);
  if (deletePublicAccessBlockRequest.getAccountId() != null) {
    request.addHeader("x-amz-account-id", StringUtils.fromString(deletePublicAccessBlockRequest.getAccountId()));
  }
  String uriResourcePath = "/v20180820/configuration/publicAccessBlock";
  request.setResourcePath(uriResourcePath);
  return request;
}

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

public Request<CreateQueryLoggingConfigRequest> marshall(CreateQueryLoggingConfigRequest createQueryLoggingConfigRequest) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  request.setHttpMethod(HttpMethodName.POST);
  request.setResourcePath(uriResourcePath);
    StringWriter stringWriter = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(stringWriter, "https://route53.amazonaws.com/doc/2013-04-01/");
    request.setContent(new StringInputStream(stringWriter.getBuffer().toString()));
    request.addHeader("Content-Length", Integer.toString(stringWriter.getBuffer().toString().getBytes(UTF8).length));
    if (!request.getHeaders().containsKey("Content-Type")) {
      request.addHeader("Content-Type", "application/xml");
    throw new SdkClientException("Unable to marshall request to XML: " + t.getMessage(), t);

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

public Request<DescribeLimitsRequest> marshall(DescribeLimitsRequest describeLimitsRequest) {
    if (describeLimitsRequest == null) {
      throw new AmazonClientException(
          "Invalid argument passed to marshall(DescribeLimitsRequest)");
    }

    Request<DescribeLimitsRequest> request = new DefaultRequest<DescribeLimitsRequest>(
        describeLimitsRequest, "AmazonDynamoDB");
    String target = "DynamoDB_20120810.DescribeLimits";
    request.addHeader("X-Amz-Target", target);
    request.setHttpMethod(HttpMethodName.POST);

    String uriResourcePath = "/";
    request.setResourcePath(uriResourcePath);
    request.addHeader("Content-Length", "0");
    request.setContent(new ByteArrayInputStream(new byte[0]));
    if (!request.getHeaders().containsKey("Content-Type")) {
      request.addHeader("Content-Type", "application/x-amz-json-1.0");
    }

    return request;
  }
}

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

request.addHeader("Content-Type", "application/xml");
request.addHeader("Content-Length", String.valueOf(aclAsXml.length));
request.setContent(new ByteArrayInputStream(aclAsXml));

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

@Override
public void setBucketTaggingConfiguration(
    SetBucketTaggingConfigurationRequest setBucketTaggingConfigurationRequest) {
  setBucketTaggingConfigurationRequest = beforeClientExecution(setBucketTaggingConfigurationRequest);
  rejectNull(setBucketTaggingConfigurationRequest,
      "The set bucket tagging configuration request object must be specified.");
  String bucketName = setBucketTaggingConfigurationRequest.getBucketName();
  BucketTaggingConfiguration bucketTaggingConfiguration = setBucketTaggingConfigurationRequest.getTaggingConfiguration();
  rejectNull(bucketName,
      "The bucket name parameter must be specified when setting bucket tagging configuration.");
  rejectNull(bucketTaggingConfiguration,
      "The tagging configuration parameter must be specified when setting bucket tagging configuration.");
  Request<SetBucketTaggingConfigurationRequest> request = createRequest(bucketName, null, setBucketTaggingConfigurationRequest, HttpMethodName.PUT);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketTagging");
  request.addParameter("tagging", null);
  byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketTaggingConfiguration);
  request.addHeader("Content-Length", String.valueOf(content.length));
  request.addHeader("Content-Type", "application/xml");
  request.setContent(new ByteArrayInputStream(content));
  try {
    byte[] md5 = Md5Utils.computeMD5Hash(content);
    String md5Base64 = BinaryUtils.toBase64(md5);
    request.addHeader("Content-MD5", md5Base64);
  } catch ( Exception e ) {
    throw new SdkClientException("Couldn't compute md5 sum", e);
  }
  invoke(request, voidResponseHandler, bucketName, null);
}

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

public Request<DeletePublicKeyRequest> marshall(DeletePublicKeyRequest deletePublicKeyRequest) {
  if (deletePublicKeyRequest == null) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
  }
  Request<DeletePublicKeyRequest> request = new DefaultRequest<DeletePublicKeyRequest>(deletePublicKeyRequest, "AmazonCloudFront");
  request.setHttpMethod(HttpMethodName.DELETE);
  if (deletePublicKeyRequest.getIfMatch() != null) {
    request.addHeader("If-Match", StringUtils.fromString(deletePublicKeyRequest.getIfMatch()));
  }
  String uriResourcePath = "/2018-11-05/public-key/{Id}";
  uriResourcePath = com.amazonaws.transform.PathMarshallers.NON_GREEDY.marshall(uriResourcePath, "Id", deletePublicKeyRequest.getId());
  request.setResourcePath(uriResourcePath);
  return request;
}

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

public Request<CreateReusableDelegationSetRequest> marshall(CreateReusableDelegationSetRequest createReusableDelegationSetRequest) {
    throw new SdkClientException("Invalid argument passed to marshall(...)");
      "AmazonRoute53");
  request.setHttpMethod(HttpMethodName.POST);
  request.setResourcePath(uriResourcePath);
    StringWriter stringWriter = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(stringWriter, "https://route53.amazonaws.com/doc/2013-04-01/");
    request.setContent(new StringInputStream(stringWriter.getBuffer().toString()));
    request.addHeader("Content-Length", Integer.toString(stringWriter.getBuffer().toString().getBytes(UTF8).length));
    if (!request.getHeaders().containsKey("Content-Type")) {
      request.addHeader("Content-Type", "application/xml");
    throw new SdkClientException("Unable to marshall request to XML: " + t.getMessage(), t);

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

public Request<DescribeEndpointsRequest> marshall(
      DescribeEndpointsRequest describeEndpointsRequest) {
    if (describeEndpointsRequest == null) {
      throw new AmazonClientException(
          "Invalid argument passed to marshall(DescribeEndpointsRequest)");
    }

    Request<DescribeEndpointsRequest> request = new DefaultRequest<DescribeEndpointsRequest>(
        describeEndpointsRequest, "AmazonDynamoDB");
    String target = "DynamoDB_20120810.DescribeEndpoints";
    request.addHeader("X-Amz-Target", target);
    request.setHttpMethod(HttpMethodName.POST);

    String uriResourcePath = "/";
    request.setResourcePath(uriResourcePath);
    request.addHeader("Content-Length", "0");
    request.setContent(new ByteArrayInputStream(new byte[0]));
    if (!request.getHeaders().containsKey("Content-Type")) {
      request.addHeader("Content-Type", "application/x-amz-json-1.0");
    }

    return request;
  }
}

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

@Override
public SetBucketInventoryConfigurationResult setBucketInventoryConfiguration(
    SetBucketInventoryConfigurationRequest setBucketInventoryConfigurationRequest)
    throws AmazonServiceException, SdkClientException {
  setBucketInventoryConfigurationRequest = beforeClientExecution(setBucketInventoryConfigurationRequest);
  rejectNull(setBucketInventoryConfigurationRequest, "The request cannot be null");
  final String bucketName = assertStringNotEmpty(setBucketInventoryConfigurationRequest.getBucketName(), "BucketName");
  final InventoryConfiguration inventoryConfiguration = assertNotNull(setBucketInventoryConfigurationRequest.getInventoryConfiguration(),
      "InventoryConfiguration");
  final String id = assertNotNull(inventoryConfiguration.getId(), "Inventory id");
  Request<SetBucketInventoryConfigurationRequest> request = createRequest(bucketName, null, setBucketInventoryConfigurationRequest, HttpMethodName.PUT);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketInventoryConfiguration");
  request.addParameter("inventory", null);
  request.addParameter("id", id);
  final byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(inventoryConfiguration);
  request.addHeader("Content-Length", String.valueOf(bytes.length));
  request.addHeader("Content-Type", "application/xml");
  request.setContent(new ByteArrayInputStream(bytes));
  return invoke(request, new Unmarshallers.SetBucketInventoryConfigurationUnmarshaller(), bucketName, null);
}

相关文章