Java 类com.amazonaws.Request 实例源码

项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
/**
 * Retrieves the request payment configuration for a given Amazon S3 bucket.
 * <p>
 * When the request payment configuration for a Amazon S3 bucket is
 * <code>Requester</code>, the requester instead of the bucket owner pays
 * the cost of the request and the data download from the bucket. The bucket
 * owner always pays the cost of storing data.
 */
private RequestPaymentConfiguration getBucketRequestPayment(
        GetRequestPaymentConfigurationRequest getRequestPaymentConfigurationRequest) {

    String bucketName = getRequestPaymentConfigurationRequest
            .getBucketName();

    rejectNull(
            bucketName,
            "The bucket name parameter must be specified while getting the Request Payment Configuration.");

    Request<GetRequestPaymentConfigurationRequest> request = createRequest(
            bucketName, null, getRequestPaymentConfigurationRequest,
            HttpMethodName.GET);
    request.addParameter("requestPayment", null);
    request.addHeader("Content-Type", "application/xml");

    return invoke(request,
            new Unmarshallers.RequestPaymentConfigurationUnmarshaller(),
            bucketName, null);
}
项目:ibm-cos-sdk-java    文件:EncryptRequestProtocolMarshaller.java   
public Request<EncryptRequest> marshall(EncryptRequest encryptRequest) {

        if (encryptRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<EncryptRequest> protocolMarshaller = protocolFactory
                    .createProtocolMarshaller(SDK_OPERATION_BINDING, encryptRequest);

            protocolMarshaller.startMarshalling();
            EncryptRequestMarshaller.getInstance().marshall(encryptRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:ListRetirableGrantsRequestProtocolMarshaller.java   
public Request<ListRetirableGrantsRequest> marshall(ListRetirableGrantsRequest listRetirableGrantsRequest) {

        if (listRetirableGrantsRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<ListRetirableGrantsRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    listRetirableGrantsRequest);

            protocolMarshaller.startMarshalling();
            ListRetirableGrantsRequestMarshaller.getInstance().marshall(listRetirableGrantsRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:GenerateDataKeyRequestProtocolMarshaller.java   
public Request<GenerateDataKeyRequest> marshall(GenerateDataKeyRequest generateDataKeyRequest) {

        if (generateDataKeyRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<GenerateDataKeyRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    generateDataKeyRequest);

            protocolMarshaller.startMarshalling();
            GenerateDataKeyRequestMarshaller.getInstance().marshall(generateDataKeyRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:ListKeyPoliciesRequestProtocolMarshaller.java   
public Request<ListKeyPoliciesRequest> marshall(ListKeyPoliciesRequest listKeyPoliciesRequest) {

        if (listKeyPoliciesRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<ListKeyPoliciesRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    listKeyPoliciesRequest);

            protocolMarshaller.startMarshalling();
            ListKeyPoliciesRequestMarshaller.getInstance().marshall(listKeyPoliciesRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public void deleteBucketTaggingConfiguration(
        DeleteBucketTaggingConfigurationRequest deleteBucketTaggingConfigurationRequest) {
    deleteBucketTaggingConfigurationRequest = beforeClientExecution(deleteBucketTaggingConfigurationRequest);
    rejectNull(deleteBucketTaggingConfigurationRequest,
            "The delete bucket tagging configuration request object must be specified.");

    String bucketName = deleteBucketTaggingConfigurationRequest.getBucketName();
    rejectNull(bucketName,
            "The bucket name parameter must be specified when deleting bucket tagging configuration.");

    Request<DeleteBucketTaggingConfigurationRequest> request = createRequest(bucketName, null, deleteBucketTaggingConfigurationRequest, HttpMethodName.DELETE);
    request.addParameter("tagging", null);

    invoke(request, voidResponseHandler, bucketName, null);
}
项目:ibm-cos-sdk-java    文件:PutKeyPolicyRequestProtocolMarshaller.java   
public Request<PutKeyPolicyRequest> marshall(PutKeyPolicyRequest putKeyPolicyRequest) {

        if (putKeyPolicyRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<PutKeyPolicyRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    putKeyPolicyRequest);

            protocolMarshaller.startMarshalling();
            PutKeyPolicyRequestMarshaller.getInstance().marshall(putKeyPolicyRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
private static void populateSourceSSE_C(Request<?> request, SSECustomerKey sseKey) {
    if (sseKey == null) return;

    // Populate the SSE-C parameters for the source object
    addHeaderIfNotNull(request, Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM,
            sseKey.getAlgorithm());
    addHeaderIfNotNull(request, Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY,
            sseKey.getKey());
    addHeaderIfNotNull(request, Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
            sseKey.getMd5());
    // Calculate the MD5 hash of the encryption key and fill it in the
    // header, if the user didn't specify it in the metadata
    if (sseKey.getKey() != null
            && sseKey.getMd5() == null) {
        String encryptionKey_b64 = sseKey.getKey();
        byte[] encryptionKey = Base64.decode(encryptionKey_b64);
        request.addHeader(Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
                Md5Utils.md5AsBase64(encryptionKey));
    }
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public MultipartUploadListing listMultipartUploads(ListMultipartUploadsRequest listMultipartUploadsRequest)
        throws SdkClientException, AmazonServiceException {
    listMultipartUploadsRequest = beforeClientExecution(listMultipartUploadsRequest);
    rejectNull(listMultipartUploadsRequest,
        "The request parameter must be specified when listing multipart uploads");

    rejectNull(listMultipartUploadsRequest.getBucketName(),
        "The bucket name parameter must be specified when listing multipart uploads");

    Request<ListMultipartUploadsRequest> request = createRequest(listMultipartUploadsRequest.getBucketName(), null, listMultipartUploadsRequest, HttpMethodName.GET);
    request.addParameter("uploads", null);

    if (listMultipartUploadsRequest.getKeyMarker() != null) request.addParameter("key-marker", listMultipartUploadsRequest.getKeyMarker());
    if (listMultipartUploadsRequest.getMaxUploads() != null) request.addParameter("max-uploads", listMultipartUploadsRequest.getMaxUploads().toString());
    if (listMultipartUploadsRequest.getUploadIdMarker() != null) request.addParameter("upload-id-marker", listMultipartUploadsRequest.getUploadIdMarker());
    if (listMultipartUploadsRequest.getDelimiter() != null) request.addParameter("delimiter", listMultipartUploadsRequest.getDelimiter());
    if (listMultipartUploadsRequest.getPrefix() != null) request.addParameter("prefix", listMultipartUploadsRequest.getPrefix());
    if (listMultipartUploadsRequest.getEncodingType() != null) request.addParameter("encoding-type", listMultipartUploadsRequest.getEncodingType());

    return invoke(request, new Unmarshallers.ListMultipartUploadsResultUnmarshaller(), listMultipartUploadsRequest.getBucketName(), null);
}
项目:ibm-cos-sdk-java    文件:DisableKeyRequestProtocolMarshaller.java   
public Request<DisableKeyRequest> marshall(DisableKeyRequest disableKeyRequest) {

        if (disableKeyRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<DisableKeyRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    disableKeyRequest);

            protocolMarshaller.startMarshalling();
            DisableKeyRequestMarshaller.getInstance().marshall(disableKeyRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:GetKeyRotationStatusRequestProtocolMarshaller.java   
public Request<GetKeyRotationStatusRequest> marshall(GetKeyRotationStatusRequest getKeyRotationStatusRequest) {

        if (getKeyRotationStatusRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<GetKeyRotationStatusRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    getKeyRotationStatusRequest);

            protocolMarshaller.startMarshalling();
            GetKeyRotationStatusRequestMarshaller.getInstance().marshall(getKeyRotationStatusRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
        throws SdkClientException, AmazonServiceException {
    listObjectsRequest = beforeClientExecution(listObjectsRequest);
    rejectNull(listObjectsRequest.getBucketName(), "The bucket name parameter must be specified when listing objects in a bucket");

    /**
     * This flag shows whether we need to url decode S3 key names. This flag is enabled
     * only when the customers don't explicitly call {@link ListObjectsRequest#setEncodingType(String)},
     * otherwise, it will be disabled for maintaining backwards compatibility.
     */
    final boolean shouldSDKDecodeResponse = listObjectsRequest.getEncodingType() == null;

    Request<ListObjectsRequest> request = createRequest(listObjectsRequest.getBucketName(), null, listObjectsRequest, HttpMethodName.GET);
    addParameterIfNotNull(request, "prefix", listObjectsRequest.getPrefix());
    addParameterIfNotNull(request, "marker", listObjectsRequest.getMarker());
    addParameterIfNotNull(request, "delimiter", listObjectsRequest.getDelimiter());
    if (listObjectsRequest.getMaxKeys() != null && listObjectsRequest.getMaxKeys().intValue() >= 0) request.addParameter("max-keys", listObjectsRequest.getMaxKeys().toString());
    request.addParameter("encoding-type", shouldSDKDecodeResponse ? Constants.URL_ENCODING : listObjectsRequest.getEncodingType());

    return invoke(request, new Unmarshallers.ListObjectsUnmarshaller(shouldSDKDecodeResponse), listObjectsRequest.getBucketName(), null);
}
项目:ibm-cos-sdk-java    文件:EnableKeyRequestProtocolMarshaller.java   
public Request<EnableKeyRequest> marshall(EnableKeyRequest enableKeyRequest) {

        if (enableKeyRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<EnableKeyRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    enableKeyRequest);

            protocolMarshaller.startMarshalling();
            EnableKeyRequestMarshaller.getInstance().marshall(enableKeyRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:CancelKeyDeletionRequestProtocolMarshaller.java   
public Request<CancelKeyDeletionRequest> marshall(CancelKeyDeletionRequest cancelKeyDeletionRequest) {

        if (cancelKeyDeletionRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<CancelKeyDeletionRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    cancelKeyDeletionRequest);

            protocolMarshaller.startMarshalling();
            CancelKeyDeletionRequestMarshaller.getInstance().marshall(cancelKeyDeletionRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:GetKeyPolicyRequestProtocolMarshaller.java   
public Request<GetKeyPolicyRequest> marshall(GetKeyPolicyRequest getKeyPolicyRequest) {

        if (getKeyPolicyRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<GetKeyPolicyRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    getKeyPolicyRequest);

            protocolMarshaller.startMarshalling();
            GetKeyPolicyRequestMarshaller.getInstance().marshall(getKeyPolicyRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:ReEncryptRequestProtocolMarshaller.java   
public Request<ReEncryptRequest> marshall(ReEncryptRequest reEncryptRequest) {

        if (reEncryptRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<ReEncryptRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    reEncryptRequest);

            protocolMarshaller.startMarshalling();
            ReEncryptRequestMarshaller.getInstance().marshall(reEncryptRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:RetireGrantRequestProtocolMarshaller.java   
public Request<RetireGrantRequest> marshall(RetireGrantRequest retireGrantRequest) {

        if (retireGrantRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<RetireGrantRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    retireGrantRequest);

            protocolMarshaller.startMarshalling();
            RetireGrantRequestMarshaller.getInstance().marshall(retireGrantRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:ImportKeyMaterialRequestProtocolMarshaller.java   
public Request<ImportKeyMaterialRequest> marshall(ImportKeyMaterialRequest importKeyMaterialRequest) {

        if (importKeyMaterialRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<ImportKeyMaterialRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    importKeyMaterialRequest);

            protocolMarshaller.startMarshalling();
            ImportKeyMaterialRequestMarshaller.getInstance().marshall(importKeyMaterialRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:DeleteImportedKeyMaterialRequestProtocolMarshaller.java   
public Request<DeleteImportedKeyMaterialRequest> marshall(DeleteImportedKeyMaterialRequest deleteImportedKeyMaterialRequest) {

        if (deleteImportedKeyMaterialRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<DeleteImportedKeyMaterialRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(
                    SDK_OPERATION_BINDING, deleteImportedKeyMaterialRequest);

            protocolMarshaller.startMarshalling();
            DeleteImportedKeyMaterialRequestMarshaller.getInstance().marshall(deleteImportedKeyMaterialRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:ListGrantsRequestProtocolMarshaller.java   
public Request<ListGrantsRequest> marshall(ListGrantsRequest listGrantsRequest) {

        if (listGrantsRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<ListGrantsRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    listGrantsRequest);

            protocolMarshaller.startMarshalling();
            ListGrantsRequestMarshaller.getInstance().marshall(listGrantsRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
/**
 * Retrieves the region of the bucket by making a HeadBucket request to us-west-1 region.
 *
 * Currently S3 doesn't return region in a HEAD Bucket request if the bucket
 * owner has enabled bucket to accept only SigV4 requests via bucket
 * policies.
 */
private String getBucketRegionViaHeadRequest(String bucketName) {
    String bucketRegion = null;

    try {
        Request<HeadBucketRequest> request = createRequest(bucketName, null,
                new HeadBucketRequest(bucketName), HttpMethodName.HEAD);

        HeadBucketResult result = invoke(request, new HeadBucketResultHandler(), bucketName, null, true);
        bucketRegion = result.getBucketRegion();
    } catch (AmazonS3Exception exception) {
        if (exception.getAdditionalDetails() != null) {
            bucketRegion = exception.getAdditionalDetails().get(
                Headers.S3_BUCKET_REGION);
        }
    }

    if (bucketRegion == null && log.isDebugEnabled()) {
        log.debug("Not able to derive region of the " + bucketName + " from the HEAD Bucket requests.");
    }

    return bucketRegion;
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public List<Bucket> listBuckets(ListBucketsRequest listBucketsRequest)
        throws SdkClientException, AmazonServiceException {
    listBucketsRequest = beforeClientExecution(listBucketsRequest);
    rejectNull(listBucketsRequest, "The request object parameter listBucketsRequest must be specified.");
    Request<ListBucketsRequest> request = createRequest(null, null, listBucketsRequest, HttpMethodName.GET);

    //Add IBM Service Instance Id to headers
    if ((null != this.awsCredentialsProvider ) && (this.awsCredentialsProvider.getCredentials() instanceof IBMOAuthCredentials)) {
        IBMOAuthCredentials oAuthCreds = (IBMOAuthCredentials)this.awsCredentialsProvider.getCredentials();
        if (oAuthCreds.getServiceInstanceId() != null) {
            request.addHeader(Headers.IBM_SERVICE_INSTANCE_ID, oAuthCreds.getServiceInstanceId());  
        }
    }

    return invoke(request, new Unmarshallers.ListBucketsUnmarshaller(), null, null);
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
/**
 * <p>
 * Populates the specified request with the numerous attributes available in
 * <code>SSEWithCustomerKeyRequest</code>.
 * </p>
 *
 * @param request
 *            The request to populate with headers to represent all the
 *            options expressed in the
 *            <code>ServerSideEncryptionWithCustomerKeyRequest</code>
 *            object.
 * @param sseKey
 *            The request object for an S3 operation that allows server-side
 *            encryption using customer-provided keys.
 */
private static void populateSSE_C(Request<?> request, SSECustomerKey sseKey) {
    if (sseKey == null) return;

    addHeaderIfNotNull(request, Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM,
            sseKey.getAlgorithm());
    addHeaderIfNotNull(request, Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY,
            sseKey.getKey());
    addHeaderIfNotNull(request, Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
            sseKey.getMd5());
    // Calculate the MD5 hash of the encryption key and fill it in the
    // header, if the user didn't specify it in the metadata
    if (sseKey.getKey() != null
            && sseKey.getMd5() == null) {
        String encryptionKey_b64 = sseKey.getKey();
        byte[] encryptionKey = Base64.decode(encryptionKey_b64);
        request.addHeader(Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
                Md5Utils.md5AsBase64(encryptionKey));
    }
}
项目:ibm-cos-sdk-java    文件:DisableKeyRotationRequestProtocolMarshaller.java   
public Request<DisableKeyRotationRequest> marshall(DisableKeyRotationRequest disableKeyRotationRequest) {

        if (disableKeyRotationRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<DisableKeyRotationRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    disableKeyRotationRequest);

            protocolMarshaller.startMarshalling();
            DisableKeyRotationRequestMarshaller.getInstance().marshall(disableKeyRotationRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:ListResourceTagsRequestProtocolMarshaller.java   
public Request<ListResourceTagsRequest> marshall(ListResourceTagsRequest listResourceTagsRequest) {

        if (listResourceTagsRequest == null) {
            throw new SdkClientException("Invalid argument passed to marshall(...)");
        }

        try {
            final ProtocolRequestMarshaller<ListResourceTagsRequest> protocolMarshaller = protocolFactory.createProtocolMarshaller(SDK_OPERATION_BINDING,
                    listResourceTagsRequest);

            protocolMarshaller.startMarshalling();
            ListResourceTagsRequestMarshaller.getInstance().marshall(listResourceTagsRequest, protocolMarshaller);
            return protocolMarshaller.finishMarshalling();
        } catch (Exception e) {
            throw new SdkClientException("Unable to marshall request to JSON: " + e.getMessage(), e);
        }
    }
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest)
        throws SdkClientException, AmazonServiceException {
    getObjectMetadataRequest = beforeClientExecution(getObjectMetadataRequest);
    rejectNull(getObjectMetadataRequest, "The GetObjectMetadataRequest parameter must be specified when requesting an object's metadata");

    String bucketName = getObjectMetadataRequest.getBucketName();
    String key = getObjectMetadataRequest.getKey();
    String versionId = getObjectMetadataRequest.getVersionId();

    rejectNull(bucketName, "The bucket name parameter must be specified when requesting an object's metadata");
    rejectNull(key, "The key parameter must be specified when requesting an object's metadata");

    Request<GetObjectMetadataRequest> request = createRequest(bucketName, key, getObjectMetadataRequest, HttpMethodName.HEAD);

    if (versionId != null) request.addParameter("versionId", versionId);

    populateRequesterPaysHeader(request, getObjectMetadataRequest.isRequesterPays());
    addPartNumberIfNotNull(request, getObjectMetadataRequest.getPartNumber());

    populateSSE_C(request, getObjectMetadataRequest.getSSECustomerKey());

    return invoke(request, new S3MetadataResponseHandler(), bucketName, key);
}
项目:aws-xray-sdk-java    文件:TracingHandler.java   
@Override
public void beforeRequest(Request<?> request) {
    if(S3_SERVICE_NAME.equals(extractServiceName(request)) && S3_PRESIGN_REQUEST.equals(extractOperationName(request))) {
        return;
    }

    if (isSubsegmentDuplicate(recorder.getCurrentSubsegmentOptional(), request)) {
        return;
    }
    Entity entityContext = request.getHandlerContext(entityKey);
    if (null != entityContext) {
        recorder.setTraceEntity(entityContext);
    }
    Subsegment currentSubsegment = recorder.beginSubsegment(extractServiceName(request));
    if (null == currentSubsegment) {
        return;
    }
    currentSubsegment.putAllAws(extractRequestParameters(request));
    currentSubsegment.putAws(OPERATION_SUBSEGMENT_KEY, extractOperationName(request));
    if (null != accountId) {
        currentSubsegment.putAws(ACCOUNT_ID_SUBSEGMENT_KEY, accountId);
    }
    currentSubsegment.setNamespace(Namespace.AWS.toString());

    if (null != recorder.getCurrentSegment()) {
        TraceHeader header = new TraceHeader(recorder.getCurrentSegment().getTraceId(),
                                recorder.getCurrentSegment().isSampled() ? currentSubsegment.getId() : null,
                                recorder.getCurrentSegment().isSampled() ? SampleDecision.SAMPLED : SampleDecision.NOT_SAMPLED);
        request.addHeader(TraceHeader.HEADER_KEY, header.toString());
    }
}
项目:ibm-cos-sdk-java    文件:RuntimeHttpUtilsTest.java   
@Test
public void queryParamKeyWithWhitespace_UrlEnocded() {
    Request<?> request = newRequest();
    request.setResourcePath("foo/bar");
    request.withParameter("query one", "valOne");
    request.withParameter("queryTwo", "valTwo");
    URL url = RuntimeHttpUtils.convertRequestToUrl(request, false, false);
    assertUrlEquals("https://test.amazonaws.com/foo/bar?query%20one=valOne&queryTwo=valTwo", url);
}
项目:ibm-cos-sdk-java    文件:RuntimeHttpUtilsTest.java   
@Test
public void pathWithWhitespace_UrlEncodedWhenFlagSetToTrue() {
    Request<?> request = newRequest();
    request.setResourcePath("foo bar");
    URL url = RuntimeHttpUtils.convertRequestToUrl(request, false, true);
    assertUrlEquals("https://test.amazonaws.com/foo%20bar", url);
}
项目:ibm-cos-sdk-java    文件:AmazonS3ClientTest.java   
/**
 * Test No IAM Headers are added & no null pointers are thrown
 * 
 */ 
@Test
public void testNoIAMHeadersAreAdded() {

    CreateBucketRequest request = new CreateBucketRequest("testbucket");
    Request<CreateBucketRequest> defaultRequest = new DefaultRequest(Constants.S3_SERVICE_DISPLAY_NAME);
    AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials("987654321", "123456789"));
    defaultRequest = s3Client.addIAMHeaders(defaultRequest, request);

    assertEquals(defaultRequest.getHeaders().get(Headers.IBM_SERVICE_INSTANCE_ID), null);
}
项目:async-sqs    文件:AsyncResponseConverter.java   
public HttpResponse apply(Response asyncResponse, Request originalRequest) {
    HttpResponse output = new HttpResponse(originalRequest, null);
    output.setStatusCode(asyncResponse.getStatusCode());
    output.setStatusText(asyncResponse.getStatusText());
    output.setContent(asyncResponse.getResponseBodyAsStream());
    asyncResponse.getHeaders().forEach((header) -> output.addHeader(header.getKey(), header.getValue()));
    return output;
}
项目:ibm-cos-sdk-java    文件:RuntimeHttpUtilsTest.java   
@Test
public void queryParamWithMultipleValue_OrderingIsPreserved() {
    Request<?> request = newRequest();
    request.setResourcePath("foo/bar");
    request.addParameters("queryList", Arrays.asList("foo", "bar", "baz"));
    URL url = RuntimeHttpUtils.convertRequestToUrl(request, false, false);
    assertUrlEquals("https://test.amazonaws.com/foo/bar?queryList=foo&queryList=bar&queryList=baz", url);
}
项目:ibm-cos-sdk-java    文件:UriResourcePathUtilsTest.java   
@Test
public void queryparam_without_value_returns_list_containing_null_value() {
    final String uriResourcePath = "/foo/bar";
    final String uriResourcePathWithParams =
            uriResourcePath + "?param";
    final Request<Object> request = new DefaultRequest<Object>(null, null);

    Assert.assertEquals(uriResourcePath, UriResourcePathUtils.addStaticQueryParamtersToRequest(request, uriResourcePathWithParams));

    Assert.assertTrue(request.getParameters().containsKey("param"));
    Assert.assertEquals(Arrays.asList((String)null), request.getParameters().get("param"));
}
项目:ibm-cos-sdk-java    文件:JsonProtocolMarshaller.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;
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClient.java   
private RequestExecutor(Request<?> request, RequestConfig requestConfig,
                        HttpResponseHandler<? extends SdkBaseException> errorResponseHandler,
                        HttpResponseHandler<Output> responseHandler,
                        ExecutionContext executionContext,
                        List<RequestHandler2> requestHandler2s) {
    this.request = request;
    this.requestConfig = requestConfig;
    this.errorResponseHandler = errorResponseHandler;
    this.responseHandler = responseHandler;
    this.executionContext = executionContext;
    this.requestHandler2s = requestHandler2s;
    this.awsRequestMetrics = executionContext.getAwsRequestMetrics();
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClient.java   
/**
 * Reset the input stream of the request before a retry.
 *
 * @param request Request containing input stream to reset
 * @throws ResetException If Input Stream can't be reset which means the request can't be
 *                        retried
 */
private void resetRequestInputStream(final Request<?> request) throws ResetException {
    InputStream requestInputStream = request.getContent();
    if (requestInputStream != null) {
        if (requestInputStream.markSupported()) {
            try {
                requestInputStream.reset();
            } catch (IOException ex) {
                throw new ResetException("Failed to reset the request input stream", ex);
            }
        }
    }
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
@Test
public void testUseExpectContinueTrue() throws IOException {
    Request<?> request = mockRequest(SERVER_NAME, HttpMethodName.PUT, URI_NAME, true);
    ClientConfiguration clientConfiguration = new ClientConfiguration().withUseExpectContinue(true);

    HttpRequestFactory<HttpRequestBase> httpRequestFactory = new ApacheHttpRequestFactory();
    HttpRequestBase httpRequest = httpRequestFactory.create(request, HttpClientSettings.adapt(clientConfiguration));

    Assert.assertNotNull(httpRequest);
    Assert.assertTrue(httpRequest.getConfig().isExpectContinueEnabled());

}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.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);
        }
    }
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
@Test
public void testUseExpectContinueFalse() throws IOException {
    Request<?> request = mockRequest(SERVER_NAME, HttpMethodName.PUT, URI_NAME, true);
    ClientConfiguration clientConfiguration = new ClientConfiguration().withUseExpectContinue(false);

    HttpRequestFactory<HttpRequestBase> httpRequestFactory = new ApacheHttpRequestFactory();
    HttpRequestBase httpRequest = httpRequestFactory.create(request, HttpClientSettings.adapt(clientConfiguration));

    Assert.assertNotNull(httpRequest);
    Assert.assertFalse(httpRequest.getConfig().isExpectContinueEnabled());
}
项目:ibm-cos-sdk-java    文件:AwsResponseHandlerAdapter.java   
/**
 * @param delegate          Response handler to delegate to and unwrap
 * @param request           Marshalled request
 * @param awsRequestMetrics Request metrics
 */
public AwsResponseHandlerAdapter(HttpResponseHandler<AmazonWebServiceResponse<T>> delegate,
                                 Request<?> request,
                                 AWSRequestMetrics awsRequestMetrics,
                                 MetadataCache responseMetadataCache) {
    this.delegate = delegate;
    this.request = request;
    this.awsRequestMetrics = awsRequestMetrics;
    this.responseMetadataCache = responseMetadataCache;
}