Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@
import java.io.InputStream;
import java.nio.channels.SeekableByteChannel;
import com.spectralogic.ds3client.utils.SeekableByteChannelInputStream;
import static com.spectralogic.ds3client.utils.Guard.isStringNullOrEmpty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.spectralogic.ds3client.commands.interfaces.AbstractRequest;
import java.util.UUID;
import com.google.common.net.UrlEscapers;
import com.spectralogic.ds3client.models.ChecksumType;
public class PutObjectRequest extends AbstractRequest {

final static private Logger LOG = LoggerFactory.getLogger(PutObjectRequest.class);

// Variables
public final static String AMZ_META_HEADER = "x-amz-meta-";

Expand Down Expand Up @@ -157,6 +162,10 @@ public ChecksumType.Type getChecksumType() {


public PutObjectRequest withMetaData(final String key, final String value) {
if (isStringNullOrEmpty(value)) {
LOG.warn("Key has not been added to metadata because value was null or empty: " + key);
return this;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something in the indentation here is weird... is it just github?

final String modifiedKey;
if (!key.toLowerCase().startsWith(AMZ_META_HEADER)){
modifiedKey = AMZ_META_HEADER + key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,39 @@ public void createObjectWithMetadata() throws IOException, SignatureException, U
.putObject(por);
}

@Test
public void createObjectWithNullAndEmptyMetadata() throws IOException, SignatureException, URISyntaxException {
final String jobIdString = "a4a586a1-cb80-4441-84e2-48974e982d51";
final Map<String, String> queryParams = new HashMap<>();
queryParams.put("job", jobIdString);
queryParams.put("offset", Long.toString(0));

final Path resourcePath = ResourceUtils.loadFileResource("LoremIpsumTwice.txt");
final byte[] fileBytes = Files.readAllBytes(resourcePath);
final String output = new String(fileBytes, Charset.forName("UTF-8"));
final FileChannel channel = FileChannel.open(resourcePath, StandardOpenOption.READ);

final PutObjectRequest por = new PutObjectRequest(
"bucketName",
"objectName",
channel,
UUID.fromString(jobIdString),
0,
fileBytes.length);

final Multimap<String, String> expectedRequestHeaders = TreeMultimap.create();
expectedRequestHeaders.put("Naming-Convention", "s3"); //default from AbstractRequest

por.withMetaData("test1", null);
por.withMetaData("test2", "");

MockNetwork
.expecting(HttpVerb.PUT, "/bucketName/objectName", queryParams, expectedRequestHeaders, output)
.returning(200, "")
.asClient()
.putObject(por);
}

@Test
public void headObjectWithMetadata() throws IOException, SignatureException {

Expand Down