Example usage for com.amazonaws.services.s3 Headers CONTENT_TYPE

List of usage examples for com.amazonaws.services.s3 Headers CONTENT_TYPE

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 Headers CONTENT_TYPE.

Prototype

String CONTENT_TYPE

To view the source code for com.amazonaws.services.s3 Headers CONTENT_TYPE.

Click Source Link

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  ww  w. ja v  a  2s  .c o  m
    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:edu.upenn.library.fcrepo.connector.annex.S3AnnexResolverFactory.java

License:Apache License

public URI getObjectURI(String annexId, Map<String, String> remoteResponseHeaderHints) {
    GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, annexId);
    request.addRequestParameter(ResponseHeaderOverrides.RESPONSE_HEADER_CONTENT_TYPE,
            remoteResponseHeaderHints.get(Headers.CONTENT_TYPE));
    request.addRequestParameter(ResponseHeaderOverrides.RESPONSE_HEADER_CONTENT_DISPOSITION,
            remoteResponseHeaderHints.get(Headers.CONTENT_DISPOSITION));
    try {//from   w  ww.  ja v  a 2 s  .  c  o  m
        return conn.generatePresignedUrl(request).toURI();
    } catch (URISyntaxException ex) {
        throw null;
    }
}

From source file:org.duracloud.s3storage.S3StorageProvider.java

License:Apache License

@Override
protected Map<String, String> removeCalculatedProperties(Map<String, String> contentProperties) {
    contentProperties = super.removeCalculatedProperties(contentProperties);
    if (contentProperties != null) {
        contentProperties.remove(Headers.CONTENT_LENGTH);
        contentProperties.remove(Headers.CONTENT_TYPE); // Content-Type is set on ObjectMetadata object
        contentProperties.remove(Headers.LAST_MODIFIED);
        contentProperties.remove(Headers.DATE);
        contentProperties.remove(Headers.ETAG);
        contentProperties.remove(Headers.CONTENT_LENGTH.toLowerCase());
        contentProperties.remove(Headers.CONTENT_TYPE.toLowerCase());
        contentProperties.remove(Headers.LAST_MODIFIED.toLowerCase());
        contentProperties.remove(Headers.DATE.toLowerCase());
        contentProperties.remove(Headers.ETAG.toLowerCase());
    }//www .  ja v  a 2 s .  co m

    return contentProperties;
}

From source file:org.duracloud.s3storage.S3StorageProvider.java

License:Apache License

private Map<String, String> prepContentProperties(ObjectMetadata objMetadata) {
    Map<String, String> contentProperties = new HashMap<>();

    // Set the user properties
    Map<String, String> userProperties = objMetadata.getUserMetadata();
    for (String metaName : userProperties.keySet()) {
        String metaValue = userProperties.get(metaName);
        contentProperties.put(getWithSpace(decodeHeaderKey(metaName)), decodeHeaderValue(metaValue));
    }/*from  ww  w  .j  ava2s  .c  om*/

    // Set the response metadata
    Map<String, Object> responseMeta = objMetadata.getRawMetadata();
    for (String metaName : responseMeta.keySet()) {
        Object metaValue = responseMeta.get(metaName);
        if (metaValue instanceof String) {
            contentProperties.put(metaName, (String) metaValue);
        }
    }

    // Set MIMETYPE
    String contentType = objMetadata.getContentType();
    if (contentType != null) {
        contentProperties.put(PROPERTIES_CONTENT_MIMETYPE, contentType);
        contentProperties.put(Headers.CONTENT_TYPE, contentType);
    }

    // Set CONTENT_ENCODING
    String encoding = objMetadata.getContentEncoding();
    if (encoding != null) {
        contentProperties.put(Headers.CONTENT_ENCODING, encoding);
    }

    // Set SIZE
    long contentLength = objMetadata.getContentLength();
    if (contentLength >= 0) {
        String size = String.valueOf(contentLength);
        contentProperties.put(PROPERTIES_CONTENT_SIZE, size);
        contentProperties.put(Headers.CONTENT_LENGTH, size);
    }

    // Set CHECKSUM
    String checksum = objMetadata.getETag();
    if (checksum != null) {
        String eTagValue = getETagValue(checksum);
        contentProperties.put(PROPERTIES_CONTENT_CHECKSUM, eTagValue);
        contentProperties.put(PROPERTIES_CONTENT_MD5, eTagValue);
        contentProperties.put(Headers.ETAG, eTagValue);
    }

    // Set MODIFIED
    Date modified = objMetadata.getLastModified();
    if (modified != null) {
        String modDate = formattedDate(modified);
        contentProperties.put(PROPERTIES_CONTENT_MODIFIED, modDate);
        contentProperties.put(Headers.LAST_MODIFIED, modDate);
    }

    return contentProperties;
}