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

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

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

Request.setContent介绍

[英]Sets the optional stream containing the payload data to include for this request. Not all requests will contain payload data.
[中]设置包含此请求的有效负载数据的可选流。并非所有请求都包含有效负载数据。

代码示例

代码示例来源: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

@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 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

if (originalRequest == null) originalRequest = new GenericBucketRequest(bucketName);
Request<AmazonWebServiceRequest> request = createRequest(bucketName, key, originalRequest, HttpMethodName.PUT);
request.addHeader("Content-Type", "application/xml");
request.addHeader("Content-Length", String.valueOf(aclAsXml.length));
request.setContent(new ByteArrayInputStream(aclAsXml));

代码示例来源: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 setBucketLoggingConfiguration(SetBucketLoggingConfigurationRequest setBucketLoggingConfigurationRequest)
    throws SdkClientException, AmazonServiceException {
  setBucketLoggingConfigurationRequest = beforeClientExecution(setBucketLoggingConfigurationRequest);
  rejectNull(setBucketLoggingConfigurationRequest,
    "The set bucket logging configuration request object must be specified when enabling server access logging");
  String bucketName = setBucketLoggingConfigurationRequest.getBucketName();
  BucketLoggingConfiguration loggingConfiguration = setBucketLoggingConfigurationRequest.getLoggingConfiguration();
  rejectNull(bucketName,
    "The bucket name parameter must be specified when enabling server access logging");
  rejectNull(loggingConfiguration,
    "The logging configuration parameter must be specified when enabling server access logging");
  Request<SetBucketLoggingConfigurationRequest> request = createRequest(bucketName, null, setBucketLoggingConfigurationRequest, HttpMethodName.PUT);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketLogging");
  request.addParameter("logging", null);
  byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(loggingConfiguration);
  request.setContent(new ByteArrayInputStream(bytes));
  invoke(request, voidResponseHandler, bucketName, null);
}

代码示例来源: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

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 void setBucketNotificationConfiguration(
    SetBucketNotificationConfigurationRequest setBucketNotificationConfigurationRequest)
    throws SdkClientException, AmazonServiceException {
  setBucketNotificationConfigurationRequest = beforeClientExecution(setBucketNotificationConfigurationRequest);
  rejectNull(setBucketNotificationConfigurationRequest,
      "The set bucket notification configuration request object must be specified.");
  String bucketName = setBucketNotificationConfigurationRequest.getBucketName();
  BucketNotificationConfiguration bucketNotificationConfiguration = setBucketNotificationConfigurationRequest.getNotificationConfiguration();
  rejectNull(bucketName,
      "The bucket name parameter must be specified when setting bucket notification configuration.");
  rejectNull(bucketNotificationConfiguration,
      "The notification configuration parameter must be specified when setting bucket notification configuration.");
  Request<SetBucketNotificationConfigurationRequest> request = createRequest(bucketName, null, setBucketNotificationConfigurationRequest, HttpMethodName.PUT);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketNotificationConfiguration");
  request.addParameter("notification", null);
  byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(bucketNotificationConfiguration);
  request.setContent(new ByteArrayInputStream(bytes));
  invoke(request, voidResponseHandler, bucketName, null);
}

代码示例来源: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-amplify/aws-sdk-android

/**
 * Sets the optional stream containing the payload data from the byte array
 * to include for this request. Not all requests will contain payload data.
 *
 * @param body The request body represented as a array of bytes.
 * @return the updated request object.
 */
public ApiRequest withBody(byte[] body) {
  request.setContent(new ByteArrayInputStream(body));
  return this;
}

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

"The replication configuration parameter must be specified when setting replication configuration.");
Request<SetBucketReplicationConfigurationRequest> request = createRequest(
    bucketName, null, setBucketReplicationConfigurationRequest,
    HttpMethodName.PUT);
    .convertToXmlByteArray(bucketReplicationConfiguration);
request.addHeader("Content-Length", String.valueOf(bytes.length));
request.addHeader("Content-Type", "application/xml");
request.setContent(new ByteArrayInputStream(bytes));
  request.addHeader("Content-MD5",
      BinaryUtils.toBase64(Md5Utils.computeMD5Hash(bytes)));
} catch (Exception e) {
  throw new SdkClientException(
      "Not able to compute MD5 of the replication rule configuration. Exception Message : "
          + e.getMessage(), e);

代码示例来源: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<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 SetPublicAccessBlockResult setPublicAccessBlock(SetPublicAccessBlockRequest setPublicAccessBlockRequest) {
  setPublicAccessBlockRequest = beforeClientExecution(setPublicAccessBlockRequest);
  rejectNull(setPublicAccessBlockRequest, "The request object must be specified.");
  String bucketName = setPublicAccessBlockRequest.getBucketName();
  PublicAccessBlockConfiguration config = setPublicAccessBlockRequest.getPublicAccessBlockConfiguration();
  rejectNull(bucketName,
        "The bucket name parameter must be specified when setting public block configuration.");
  rejectNull(config,
        "The PublicAccessBlockConfiguration parameter must be specified when setting public block");
  Request<SetPublicAccessBlockRequest> request = createRequest(bucketName, null, setPublicAccessBlockRequest, HttpMethodName.PUT);
  request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutPublicAccessBlock");
  request.addParameter("publicAccessBlock", null);
  byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(config);
  request.setContent(new ByteArrayInputStream(bytes));
  return invoke(request, new Unmarshallers.SetPublicAccessBlockUnmarshaller(), bucketName, null);
}

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

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 {
      final byte[] md5 = Md5Utils.computeMD5Hash(content);
      final String md5Base64 = BinaryUtils.toBase64(md5);
      request.addHeader("Content-MD5", md5Base64);
    } catch ( final Exception e ) {
      throw new AmazonClientException("Couldn't compute md5 sum", e);
    }
  }
}

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

/**
 * Sets the optional stream containing the payload data from a string
 * content to include for this request. Not all requests will contain
 * payload data.
 *
 * @param body the request body represented as a string.
 * @return the updated request object.
 */
public ApiRequest withBody(String body) {
  final byte[] contentBytes = body.getBytes(StringUtils.UTF8);
  request.setContent(new ByteArrayInputStream(contentBytes));
  return this;
}

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

"The request payment configuration parameter must be specified when setting the Requester Pays.");
Request<SetRequestPaymentConfigurationRequest> request = createRequest(
    bucketName, null, setRequestPaymentConfigurationRequest,
    HttpMethodName.PUT);
request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "PutBucketRequestPayment");
request.addParameter("requestPayment", null);
request.addHeader("Content-Type", "application/xml");
request.setContent(new ByteArrayInputStream(bytes));

代码示例来源: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);

相关文章