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
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 @@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
Expand All @@ -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));
}
Expand All @@ -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)
Expand All @@ -195,7 +194,7 @@ public Response put(String bucket, String key, S3Object object, Map headers)
key = "";

HttpURLConnection request = makeRequest("PUT", bucket + pathSep
+ Utils.urlencode(key), headers, object);
+ Utils.urlencodePath(key), headers, object);

request.setDoOutput(true);
request.getOutputStream().write(
Expand All @@ -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);
Expand All @@ -230,7 +229,7 @@ public Response putStream(String bucket, String key, S3StreamObject object,
if (key == null)
key = "";
HttpURLConnection request = makeStreamRequest("PUT", bucket + pathSep
+ Utils.urlencode(key), headers, object);
+ Utils.urlencodePath(key), headers, object);

request.setDoOutput(true);
if (object.length != 0) {
Expand Down Expand Up @@ -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)
Expand All @@ -274,7 +273,7 @@ public GetResponse get(String bucket, String key, Map headers)
key = "";

return new GetResponse(makeRequest("GET", bucket + pathSep
+ Utils.urlencode(key), headers));
+ Utils.urlencodePath(key), headers));
}

/**
Expand All @@ -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)
Expand All @@ -302,7 +301,7 @@ public GetStreamResponse getStream(String bucket, String key, Map headers)
key = "";

return new GetStreamResponse(makeRequest("GET", bucket + pathSep
+ Utils.urlencode(key), headers));
+ Utils.urlencodePath(key), headers));
}

/**
Expand All @@ -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)
Expand All @@ -330,7 +329,7 @@ public GetResponse getTorrent(String bucket, String key, Map headers)
key = "";

return new GetResponse(makeRequest("GET", bucket + pathSep
+ Utils.urlencode(key) + "?torrent", headers));
+ Utils.urlencodePath(key) + "?torrent", headers));
}

/**
Expand All @@ -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);
Expand All @@ -356,7 +355,7 @@ public Response delete(String bucket, String key, Map headers)
if (key == null)
key = "";
return new Response(makeRequest("DELETE", bucket + pathSep
+ Utils.urlencode(key), headers));
+ Utils.urlencodePath(key), headers));
}

/**
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -400,7 +399,7 @@ public GetResponse getACL(String bucket, String key, Map headers)
if (key == null)
key = "";
return new GetResponse(makeRequest("GET", bucket + pathSep
+ Utils.urlencode(key) + "?acl", headers));
+ Utils.urlencodePath(key) + "?acl", headers));
}

/**
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -449,7 +448,7 @@ public Response putACL(String bucket, String key, String aclXMLDoc,
if (key == null)
key = "";
HttpURLConnection request = makeRequest("PUT", bucket + pathSep
+ Utils.urlencode(key) + "?acl", headers, object);
+ Utils.urlencodePath(key) + "?acl", headers, object);

request.setDoOutput(true);
request.getOutputStream().write(
Expand All @@ -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));
}
Expand All @@ -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);
}

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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, "");
}

Expand All @@ -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);
}

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
Expand Down
Loading