From 14146b3dfd28e08ab4c9b287917ef4294b7281c0 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 4 Mar 2020 17:29:34 -0500 Subject: [PATCH] Adding x-amz-tagging tag in direct upload and catching/reporting non-200 status codes, updating version number --- pom.xml | 2 +- .../org/sead/uploader/dataverse/DVUploader.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8c336de..d8705e6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 DVUploader DVUploader - 1.0.8 + 1.0.9 UTF-8 diff --git a/src/main/java/org/sead/uploader/dataverse/DVUploader.java b/src/main/java/org/sead/uploader/dataverse/DVUploader.java index ed9a1c7..02b77af 100644 --- a/src/main/java/org/sead/uploader/dataverse/DVUploader.java +++ b/src/main/java/org/sead/uploader/dataverse/DVUploader.java @@ -31,6 +31,7 @@ import org.apache.commons.codec.binary.Hex; import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.CookieSpecs; import org.apache.http.client.config.RequestConfig; @@ -38,6 +39,8 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.methods.RequestBuilder; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; @@ -410,10 +413,18 @@ protected String uploadDatafile(Resource file, String path) { String storageIdentifier = data.getString("storageIdentifier"); HttpPut httpput = new HttpPut(uploadUrl); + + + httpput.addHeader("x-amz-tagging", "dv-state=temp"); MessageDigest messageDigest = MessageDigest.getInstance("MD5"); try (InputStream inStream = file.getInputStream(); DigestInputStream digestInputStream = new DigestInputStream(inStream, messageDigest)) { - + // This is hte new form for requests - keeping the example but won't update until we can change all + //HttpUriRequest httpput = RequestBuilder.put() + // .setUri(uploadUrl) + // .setHeader("x-amz-tagging", "dv-state=temp") + // .setEntity(new InputStreamEntity(digestInputStream, file.length())) + // .build(); httpput.setEntity(new InputStreamEntity(digestInputStream, file.length())); CloseableHttpResponse putResponse = httpclient.execute(httpput); try { @@ -508,6 +519,9 @@ protected String uploadDatafile(Resource file, String path) { } finally { EntityUtils.consumeQuietly(response.getEntity()); } + } else { + println("Upload failed with status: " + putStatus + " (skipping)"); + retry=0; } } catch (IOException e) {