Example usage for com.amazonaws AmazonWebServiceResponse setResult

List of usage examples for com.amazonaws AmazonWebServiceResponse setResult

Introduction

In this page you can find the example usage for com.amazonaws AmazonWebServiceResponse setResult.

Prototype

public void setResult(T result) 

Source Link

Document

Sets the result contained by this response.

Usage

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

public BucketFileAccessModeResult setBucketFileAccessMode(SetBucketFileAccessModeRequest putAccessModeRequest)
        throws AmazonClientException {
    assertParameterNotNull(putAccessModeRequest,
            "The SetBucketFileAccessModeRequest parameter must be specified");

    String bucketName = putAccessModeRequest.getBucketName();
    assertParameterNotNull(bucketName, "The bucket name parameter must be specified when changing access mode");

    Request<SetBucketFileAccessModeRequest> request = createRequest(bucketName, null, putAccessModeRequest,
            HttpMethodName.PUT);/*from  w ww .j  a v  a 2 s .c  om*/
    request.addParameter(ViPRConstants.ACCESS_MODE_PARAMETER, null);
    request.addHeader(Headers.CONTENT_TYPE, Mimetypes.MIMETYPE_XML);

    if (putAccessModeRequest.getAccessMode() != null) {
        request.addHeader(ViPRConstants.FILE_ACCESS_MODE_HEADER,
                putAccessModeRequest.getAccessMode().toString());
    }
    if (putAccessModeRequest.getDuration() != 0) {
        request.addHeader(ViPRConstants.FILE_ACCESS_DURATION_HEADER,
                Long.toString(putAccessModeRequest.getDuration()));
    }
    if (putAccessModeRequest.getHostList() != null) {
        request.addHeader(ViPRConstants.FILE_ACCESS_HOST_LIST_HEADER,
                join(",", putAccessModeRequest.getHostList()));
    }
    if (putAccessModeRequest.getUid() != null) {
        request.addHeader(ViPRConstants.FILE_ACCESS_UID_HEADER, putAccessModeRequest.getUid());
    }
    if (putAccessModeRequest.getToken() != null) {
        request.addHeader(ViPRConstants.FILE_ACCESS_TOKEN_HEADER, putAccessModeRequest.getToken());
    }
    if (putAccessModeRequest.isPreserveIngestPaths()) {
        request.addHeader(ViPRConstants.FILE_ACCESS_PRESERVE_INGEST_PATHS, "true");
    }

    return invoke(request, new AbstractS3ResponseHandler<BucketFileAccessModeResult>() {
        public AmazonWebServiceResponse<BucketFileAccessModeResult> handle(HttpResponse response)
                throws Exception {
            BucketFileAccessModeResult result = new BucketFileAccessModeResult();
            Map<String, String> headers = response.getHeaders();

            if (headers.containsKey(ViPRConstants.FILE_ACCESS_MODE_HEADER))
                result.setAccessMode(ViPRConstants.FileAccessMode
                        .valueOf(headers.get(ViPRConstants.FILE_ACCESS_MODE_HEADER)));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_DURATION_HEADER))
                result.setDuration(Long.parseLong(headers.get(ViPRConstants.FILE_ACCESS_DURATION_HEADER)));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_HOST_LIST_HEADER))
                result.setHostList(
                        Arrays.asList(headers.get(ViPRConstants.FILE_ACCESS_HOST_LIST_HEADER).split(",")));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_UID_HEADER))
                result.setUid(headers.get(ViPRConstants.FILE_ACCESS_UID_HEADER));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_START_TOKEN_HEADER))
                result.setStartToken(headers.get(ViPRConstants.FILE_ACCESS_START_TOKEN_HEADER));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_END_TOKEN_HEADER))
                result.setEndToken(headers.get(ViPRConstants.FILE_ACCESS_END_TOKEN_HEADER));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_PRESERVE_INGEST_PATHS))
                result.setPreserveIngestPaths(
                        Boolean.parseBoolean(headers.get(ViPRConstants.FILE_ACCESS_PRESERVE_INGEST_PATHS)));

            AmazonWebServiceResponse<BucketFileAccessModeResult> awsResponse = parseResponseMetadata(response);
            awsResponse.setResult(result);
            return awsResponse;
        }
    }, bucketName, null);
}

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

public BucketFileAccessModeResult getBucketFileAccessMode(String bucketName) throws AmazonClientException {
    assertParameterNotNull(bucketName, "The bucket name parameter must be specified when querying access mode");

    Request<GenericBucketRequest> request = createRequest(bucketName, null,
            new GenericBucketRequest(bucketName), HttpMethodName.GET);
    request.addParameter(ViPRConstants.ACCESS_MODE_PARAMETER, null);

    return invoke(request, new AbstractS3ResponseHandler<BucketFileAccessModeResult>() {
        public AmazonWebServiceResponse<BucketFileAccessModeResult> handle(HttpResponse response)
                throws Exception {
            BucketFileAccessModeResult result = new BucketFileAccessModeResult();
            Map<String, String> headers = response.getHeaders();

            if (headers.containsKey(ViPRConstants.FILE_ACCESS_MODE_HEADER))
                result.setAccessMode(ViPRConstants.FileAccessMode
                        .valueOf(headers.get(ViPRConstants.FILE_ACCESS_MODE_HEADER)));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_DURATION_HEADER))
                result.setDuration(Long.parseLong(headers.get(ViPRConstants.FILE_ACCESS_DURATION_HEADER)));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_HOST_LIST_HEADER))
                result.setHostList(//from   ww w.ja  v  a 2s  . c  o m
                        Arrays.asList(headers.get(ViPRConstants.FILE_ACCESS_HOST_LIST_HEADER).split(",")));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_UID_HEADER))
                result.setUid(headers.get(ViPRConstants.FILE_ACCESS_UID_HEADER));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_START_TOKEN_HEADER))
                result.setStartToken(headers.get(ViPRConstants.FILE_ACCESS_START_TOKEN_HEADER));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_END_TOKEN_HEADER))
                result.setEndToken(headers.get(ViPRConstants.FILE_ACCESS_END_TOKEN_HEADER));
            if (headers.containsKey(ViPRConstants.FILE_ACCESS_PRESERVE_INGEST_PATHS))
                result.setPreserveIngestPaths(
                        Boolean.parseBoolean(headers.get(ViPRConstants.FILE_ACCESS_PRESERVE_INGEST_PATHS)));

            AmazonWebServiceResponse<BucketFileAccessModeResult> awsResponse = parseResponseMetadata(response);
            awsResponse.setResult(result);
            return awsResponse;
        }
    }, bucketName, null);
}

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

public GetFileAccessResult getFileAccess(GetFileAccessRequest getFileAccessRequest)
        throws AmazonClientException {
    assertParameterNotNull(getFileAccessRequest, "The GetFileAccessRequest parameter must be specified");

    String bucketName = getFileAccessRequest.getBucketName();
    assertParameterNotNull(bucketName, "The bucket name parameter must be specified when querying file access");

    Request<GetFileAccessRequest> request = createRequest(bucketName, null, getFileAccessRequest,
            HttpMethodName.GET);/*  w  w w . j  a va  2s . c om*/
    request.addParameter(ViPRConstants.FILE_ACCESS_PARAMETER, null);

    if (getFileAccessRequest.getMarker() != null) {
        request.addParameter(ViPRConstants.MARKER_PARAMETER, getFileAccessRequest.getMarker());
    }
    if (getFileAccessRequest.getMaxKeys() > 0) { // TODO: is this an appropriate indicator?
        request.addParameter(ViPRConstants.MAX_KEYS_PARAMETER,
                Long.toString(getFileAccessRequest.getMaxKeys()));
    }

    return invoke(request, new AbstractS3ResponseHandler<GetFileAccessResult>() {
        public AmazonWebServiceResponse<GetFileAccessResult> handle(HttpResponse response) throws Exception {
            log.trace("Beginning to parse fileaccess response XML");
            GetFileAccessResult result = new GetFileAccessResultUnmarshaller()
                    .unmarshall(response.getContent());
            log.trace("Done parsing fileaccess response XML");

            AmazonWebServiceResponse<GetFileAccessResult> awsResponse = parseResponseMetadata(response);
            awsResponse.setResult(result);
            return awsResponse;
        }
    }, bucketName, null);
}

From source file:com.emc.vipr.services.s3.ViPRS3Client.java

License:Open Source License

public ListDataNodesResult listDataNodes(ListDataNodesRequest listDataNodesRequest)
        throws AmazonClientException {
    Request<ListDataNodesRequest> request = createRequest(null, null, listDataNodesRequest, HttpMethodName.GET);
    request.addParameter(ViPRConstants.ENDPOINT_PARAMETER, null);

    return invoke(request, new AbstractS3ResponseHandler<ListDataNodesResult>() {
        public AmazonWebServiceResponse<ListDataNodesResult> handle(HttpResponse response) throws Exception {
            log.trace("Beginning to parse endpoint response XML");
            ListDataNodesResult result = new ListDataNodesResultUnmarshaller()
                    .unmarshall(response.getContent());
            log.trace("Done parsing endpoint response XML");

            AmazonWebServiceResponse<ListDataNodesResult> awsResponse = parseResponseMetadata(response);
            awsResponse.setResult(result);
            return awsResponse;
        }//ww w .  j av  a2s .c om
    }, null, null);
}

From source file:com.ivona.services.tts.http.StreamResponseHandler.java

License:Open Source License

@Override
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
    AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
    T result = responseUnmarshaller.unmarshall(response);
    awsResponse.setResult(result);
    return awsResponse;
}