Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ERAttachment s3 url generation #981

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add generics to remove warnings in S3 api classes.
  • Loading branch information
spelletier committed May 11, 2022
commit a368db15b60790219159b3d5288fde02538a0aae
Original file line number Diff line number Diff line change
@@ -41,7 +41,6 @@
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -120,7 +119,7 @@ public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey,
* @throws MalformedURLException
* @throws IOException
*/
public Response createBucket(String bucket, Map headers)
public Response createBucket(String bucket, Map<String, List<String>> headers)
throws MalformedURLException, IOException {
return new Response(makeRequest("PUT", bucket, headers));
}
@@ -145,7 +144,7 @@ public Response createBucket(String bucket, Map headers)
* @throws IOException
*/
public ListBucketResponse listBucket(String bucket, String prefix,
String marker, Integer maxKeys, Map headers)
String marker, Integer maxKeys, Map<String, List<String>> headers)
throws MalformedURLException, IOException {
String path = Utils.pathForListOptions(bucket, prefix, marker, maxKeys);
return new ListBucketResponse(makeRequest("GET", path, headers));
@@ -163,7 +162,7 @@ public ListBucketResponse listBucket(String bucket, String prefix,
* @throws MalformedURLException
* @throws IOException
*/
public Response deleteBucket(String bucket, Map headers)
public Response deleteBucket(String bucket, Map<String, List<String>> headers)
throws MalformedURLException, IOException {
return new Response(makeRequest("DELETE", bucket, headers));
}
@@ -184,7 +183,7 @@ public Response deleteBucket(String bucket, Map headers)
* @throws MalformedURLException
* @throws IOException
*/
public Response put(String bucket, String key, S3Object object, Map headers)
public Response put(String bucket, String key, S3Object object, Map<String, List<String>> headers)
throws MalformedURLException, IOException {

boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -221,7 +220,7 @@ public Response put(String bucket, String key, S3Object object, Map headers)
* @throws IOException
*/
public Response putStream(String bucket, String key, S3StreamObject object,
Map headers) throws MalformedURLException, IOException {
Map<String, List<String>> headers) throws MalformedURLException, IOException {

boolean isEmptyKey = (key == null) || (key.length() == 0)
|| (key.trim().length() == 0);
@@ -263,7 +262,7 @@ public Response putStream(String bucket, String key, S3StreamObject object,
* @throws MalformedURLException
* @throws IOException
*/
public GetResponse get(String bucket, String key, Map headers)
public GetResponse get(String bucket, String key, Map<String, List<String>> headers)
throws MalformedURLException, IOException {

boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -291,7 +290,7 @@ public GetResponse get(String bucket, String key, Map headers)
* @throws MalformedURLException
* @throws IOException
*/
public GetStreamResponse getStream(String bucket, String key, Map headers)
public GetStreamResponse getStream(String bucket, String key, Map<String, List<String>> headers)
throws MalformedURLException, IOException {

boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -319,7 +318,7 @@ public GetStreamResponse getStream(String bucket, String key, Map headers)
* @throws MalformedURLException
* @throws IOException
*/
public GetResponse getTorrent(String bucket, String key, Map headers)
public GetResponse getTorrent(String bucket, String key, Map<String, List<String>> headers)
throws MalformedURLException, IOException {

boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -347,7 +346,7 @@ public GetResponse getTorrent(String bucket, String key, Map headers)
* @throws MalformedURLException
* @throws IOException
*/
public Response delete(String bucket, String key, Map headers)
public Response delete(String bucket, String key, Map<String, List<String>> headers)
throws MalformedURLException, IOException {
boolean isEmptyKey = (key == null) || (key.length() == 0)
|| (key.trim().length() == 0);
@@ -371,7 +370,7 @@ public Response delete(String bucket, String key, Map headers)
* @throws MalformedURLException
* @throws IOException
*/
public GetResponse getBucketACL(String bucket, Map headers)
public GetResponse getBucketACL(String bucket, Map<String, List<String>> headers)
throws MalformedURLException, IOException {
return getACL(bucket, "", headers);
}
@@ -390,7 +389,7 @@ public GetResponse getBucketACL(String bucket, Map headers)
* @throws MalformedURLException
* @throws IOException
*/
public GetResponse getACL(String bucket, String key, Map headers)
public GetResponse getACL(String bucket, String key, Map<String, List<String>> headers)
throws MalformedURLException, IOException {

boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -417,7 +416,7 @@ public GetResponse getACL(String bucket, String key, Map headers)
* @throws MalformedURLException
* @throws IOException
*/
public Response putBucketACL(String bucket, String aclXMLDoc, Map headers)
public Response putBucketACL(String bucket, String aclXMLDoc, Map<String, List<String>> headers)
throws MalformedURLException, IOException {
return putACL(bucket, "", aclXMLDoc, headers);
}
@@ -439,7 +438,7 @@ public Response putBucketACL(String bucket, String aclXMLDoc, Map headers)
* @throws IOException
*/
public Response putACL(String bucket, String key, String aclXMLDoc,
Map headers) throws MalformedURLException, IOException {
Map<String, List<String>> headers) throws MalformedURLException, IOException {
S3Object object = new S3Object(aclXMLDoc.getBytes(), null);

boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -468,7 +467,7 @@ public Response putACL(String bucket, String key, String aclXMLDoc,
* @throws MalformedURLException
* @throws IOException
*/
public ListAllMyBucketsResponse listAllMyBuckets(Map headers)
public ListAllMyBucketsResponse listAllMyBuckets(Map<String, List<String>> headers)
throws MalformedURLException, IOException {
return new ListAllMyBucketsResponse(makeRequest("GET", "", headers));
}
@@ -477,7 +476,7 @@ public ListAllMyBucketsResponse listAllMyBuckets(Map headers)
* Make a new HttpURLConnection without passing an S3Object parameter.
*/
private HttpURLConnection makeRequest(String method, String resource,
Map headers) throws MalformedURLException, IOException {
Map<String, List<String>> headers) throws MalformedURLException, IOException {
return makeRequest(method, resource, headers, null);
}

@@ -495,7 +494,7 @@ private HttpURLConnection makeRequest(String method, String resource,
* The S3Object that is to be written (can be null).
*/
private HttpURLConnection makeRequest(String method, String resource,
Map headers, S3Object object) throws MalformedURLException,
Map<String, List<String>> headers, S3Object object) throws MalformedURLException,
IOException {
URL url = makeURL(resource);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -524,7 +523,7 @@ private HttpURLConnection makeRequest(String method, String resource,
* The S3StreamObject that is to be written (can be null).
*/
private HttpURLConnection makeStreamRequest(String method, String resource,
Map headers, S3StreamObject object) throws MalformedURLException,
Map<String, List<String>> headers, S3StreamObject object) throws MalformedURLException,
IOException {
URL url = makeURL(resource);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -548,7 +547,7 @@ private HttpURLConnection makeStreamRequest(String method, String resource,
* A Map of String to List of Strings representing the http
* headers to pass (can be null).
*/
private void addHeaders(HttpURLConnection connection, Map headers) {
private void addHeaders(HttpURLConnection connection, Map<String, List<String>> headers) {
addHeaders(connection, headers, "");
}

@@ -561,7 +560,7 @@ private void addHeaders(HttpURLConnection connection, Map headers) {
* A Map of String to List of Strings representing the s3
* metadata for this resource.
*/
private void addMetadataHeaders(HttpURLConnection connection, Map metadata) {
private void addMetadataHeaders(HttpURLConnection connection, Map<String, List<String>> metadata) {
addHeaders(connection, metadata, Utils.METADATA_PREFIX);
}

@@ -578,14 +577,11 @@ private void addMetadataHeaders(HttpURLConnection connection, Map metadata) {
* The string to prepend to each key before adding it to the
* connection.
*/
private void addHeaders(HttpURLConnection connection, Map headers,
private void addHeaders(HttpURLConnection connection, Map<String, List<String>> headers,
String prefix) {
if (headers != null) {
for (Iterator i = headers.keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
for (Iterator j = ((List) headers.get(key)).iterator(); j
.hasNext();) {
String value = (String) j.next();
for (String key : headers.keySet()) {
for (String value :headers.get(key)) {
connection.addRequestProperty(prefix + key, value);
}
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@@ -31,7 +31,7 @@ public class GetResponse extends Response {
public GetResponse(HttpURLConnection connection) throws IOException {
super(connection);
if (connection.getResponseCode() < 400) {
Map metadata = extractMetadata(connection);
Map<String, List<String>> metadata = extractMetadata(connection);
byte[] body = slurpInputStream(connection.getInputStream());
object = new S3Object(body, metadata);
}
@@ -41,11 +41,10 @@ public GetResponse(HttpURLConnection connection) throws IOException {
* Examines the response's header fields and returns a Map from String to
* List of Strings representing the object's metadata.
*/
private Map extractMetadata(HttpURLConnection connection) {
TreeMap metadata = new TreeMap();
Map headers = connection.getHeaderFields();
for (Iterator i = headers.keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
private Map<String, List<String>> extractMetadata(HttpURLConnection connection) {
TreeMap<String, List<String>> metadata = new TreeMap<>();
Map<String, List<String>> headers = connection.getHeaderFields();
for (String key : headers.keySet()) {
if (key == null)
continue;
metadata.put(key, headers.get(key));
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

@@ -47,7 +47,7 @@ public class GetStreamResponse extends Response {
public GetStreamResponse(HttpURLConnection connection) throws IOException {
super(connection);
if (connection.getResponseCode() < 400) {
Map metadata = extractMetadata(connection);
Map<String, List<String>> metadata = extractMetadata(connection);
object = new S3StreamObject(connection.getInputStream(),
metadata);
}
@@ -57,11 +57,10 @@ public GetStreamResponse(HttpURLConnection connection) throws IOException {
* Examines the response's header fields and returns a Map from String to
* List of Strings representing the object's metadata.
*/
private Map extractMetadata(HttpURLConnection connection) {
TreeMap metadata = new TreeMap();
Map headers = connection.getHeaderFields();
for (Iterator i = headers.keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
private Map<String, List<String>> extractMetadata(HttpURLConnection connection) {
TreeMap<String, List<String>> metadata = new TreeMap<>();
Map<String, List<String>> headers = connection.getHeaderFields();
for (String key : headers.keySet()) {
if (key == null)
continue;
if (key.startsWith(Utils.METADATA_PREFIX)) {
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ public class ListAllMyBucketsResponse extends Response {
* A list of Bucket objects, one for each of this account's buckets. Will be null if
* the request fails.
*/
public List entries;
public List<Bucket> entries;

public ListAllMyBucketsResponse(HttpURLConnection connection) throws IOException {
super(connection);
@@ -52,14 +52,14 @@ public ListAllMyBucketsResponse(HttpURLConnection connection) throws IOException

static class ListAllMyBucketsHandler extends DefaultHandler {

private List entries = null;
private List<Bucket> entries = null;
private Bucket currBucket = null;
private StringBuffer currText = null;
private SimpleDateFormat iso8601Parser = null;

public ListAllMyBucketsHandler() {
super();
entries = new ArrayList();
entries = new ArrayList<>();
iso8601Parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
iso8601Parser.setTimeZone(new SimpleTimeZone(0, "GMT"));
currText = new StringBuffer();
@@ -103,7 +103,7 @@ public void characters(char ch[], int start, int length) {
currText.append(ch, start, length);
}

public List getEntries() {
public List<Bucket> getEntries() {
return entries;
}
}
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ public class ListBucketResponse extends Response {
* A List of ListEntry objects representing the objects in the given bucket. This will
* be null if the request fails.
*/
public List entries = null;
public List<ListEntry> entries = null;

public ListBucketResponse(HttpURLConnection connection) throws IOException {
super(connection);
@@ -53,14 +53,14 @@ public ListBucketResponse(HttpURLConnection connection) throws IOException {

class ListBucketHandler extends DefaultHandler {

private List entries = null;
private List<ListEntry> entries = null;
private ListEntry currEntry = null;
private StringBuffer currText = null;
private SimpleDateFormat iso8601Parser = null;

public ListBucketHandler() {
super();
entries = new ArrayList();
entries = new ArrayList<>();
iso8601Parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
iso8601Parser.setTimeZone(new SimpleTimeZone(0, "GMT"));
currText = new StringBuffer();
@@ -116,7 +116,7 @@ public void characters(char ch[], int start, int length) {
currText.append(ch, start, length);
}

public List getEntries() {
public List<ListEntry> getEntries() {
return entries;
}
}
Loading