Example usage for com.amazonaws.http HttpResponse getHeaders

List of usage examples for com.amazonaws.http HttpResponse getHeaders

Introduction

In this page you can find the example usage for com.amazonaws.http HttpResponse getHeaders.

Prototype

public Map<String, String> getHeaders() 

Source Link

Document

Returns the HTTP headers returned with 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  w w  .j a  va  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(// w  w w .  j  a v a  2s . com
                        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.ivona.services.tts.model.transform.createspeech.CreateSpeechResultUnmarshaller.java

License:Open Source License

@Override
public CreateSpeechResult unmarshall(HttpResponse response) {
    String requestId = response.getHeaders().get(HEADER_AMZN_REQUEST_ID);
    String ttsRequestId = response.getHeaders().get(HEADER_IVONA_TTS_REQUEST_ID);
    String contentType = response.getHeaders().get(HEADER_CONTENT_TYPE);
    int requestCharacters = Integer.parseInt(response.getHeaders().get(HEADER_TTS_REQUEST_CHARACTERS));
    int requestUnits = Integer.parseInt(response.getHeaders().get(HEADER_TTS_REQUEST_UNITS));

    CreateSpeechResult createSpeechResult = new CreateSpeechResult();
    createSpeechResult.setRequestId(requestId);
    createSpeechResult.setTtsRequestId(ttsRequestId);
    createSpeechResult.setContentType(contentType);
    createSpeechResult.setTtsRequestCharacters(requestCharacters);
    createSpeechResult.setTtsRequestUnits(requestUnits);
    createSpeechResult.setBody(response.getContent());
    return createSpeechResult;
}