All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.s3.transform.DeleteObjectsRequestMarshaller Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon S3 module holds the client classes that are used for communicating with Amazon Simple Storage Service

There is a newer version: 2.29.39
Show newest version
/*
 * Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.s3.transform;

import static software.amazon.awssdk.util.StringUtils.UTF8;

import java.io.StringWriter;

import java.util.List;

import javax.annotation.Generated;

import software.amazon.awssdk.SdkClientException;
import software.amazon.awssdk.Request;
import software.amazon.awssdk.DefaultRequest;
import software.amazon.awssdk.http.HttpMethodName;
import software.amazon.awssdk.services.s3.model.*;
import software.amazon.awssdk.runtime.transform.Marshaller;

import software.amazon.awssdk.util.StringInputStream;
import software.amazon.awssdk.util.StringUtils;

import software.amazon.awssdk.util.Md5Utils;
import software.amazon.awssdk.util.XmlWriter;

/**
 * DeleteObjectsRequest Marshaller
 */

@Generated("software.amazon.awssdk:aws-java-sdk-code-generator")
public class DeleteObjectsRequestMarshaller implements Marshaller, DeleteObjectsRequest> {

    public Request marshall(DeleteObjectsRequest deleteObjectsRequest) {

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

        Request request = new DefaultRequest(deleteObjectsRequest, "S3Client");

        request.setHttpMethod(HttpMethodName.POST);

        if (deleteObjectsRequest.mfa() != null) {
            request.addHeader("x-amz-mfa", StringUtils.fromString(deleteObjectsRequest.mfa()));
        }

        if (deleteObjectsRequest.requestPayer() != null) {
            request.addHeader("x-amz-request-payer", StringUtils.fromString(deleteObjectsRequest.requestPayer()));
        }

        String uriResourcePath = "/{Bucket}?delete";

        uriResourcePath = software.amazon.awssdk.util.UriResourcePathUtils.addStaticQueryParamtersToRequest(request,
                uriResourcePath);

        uriResourcePath = software.amazon.awssdk.runtime.transform.PathMarshallers.NON_GREEDY.marshall(uriResourcePath, "Bucket",
                deleteObjectsRequest.bucket());
        request.setResourcePath(uriResourcePath);

        try {
            StringWriter stringWriter = null;
            Delete delete = deleteObjectsRequest.delete();
            if (delete != null) {
                stringWriter = new StringWriter();
                XmlWriter xmlWriter = new XmlWriter(stringWriter, "http://s3.amazonaws.com/doc/2006-03-01/");
                xmlWriter.startElement("Delete");

                java.util.List deleteObjectsList = delete.objects();
                if (deleteObjectsList != null) {
                    for (ObjectIdentifier deleteObjectsListValue : deleteObjectsList) {
                        xmlWriter.startElement("Object");

                        if (deleteObjectsListValue.key() != null) {
                            xmlWriter.startElement("Key").value(deleteObjectsListValue.key()).endElement();
                        }

                        if (deleteObjectsListValue.versionId() != null) {
                            xmlWriter.startElement("VersionId").value(deleteObjectsListValue.versionId()).endElement();
                        }
                        xmlWriter.endElement();
                    }
                }

                if (delete.quiet() != null) {
                    xmlWriter.startElement("Quiet").value(delete.quiet()).endElement();
                }
                xmlWriter.endElement();
            }

            if (stringWriter != null) {
                if (!request.getHeaders().containsKey("Content-MD5")) {
                    request.addHeader("Content-MD5", Md5Utils.md5AsBase64(stringWriter.getBuffer().toString().getBytes(UTF8)));
                }
                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;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy