Skip to content

Commit 86eb9a9

Browse files
authored
Merge pull request #981 from spelletier/Fix_ERAttachment_S3_urlGeneration
Fix ERAttachment s3 url generation
2 parents eb51c10 + d64a834 commit 86eb9a9

9 files changed

Lines changed: 95 additions & 99 deletions

File tree

Frameworks/BusinessLogic/ERAttachment/Sources/com/amazon/s3/AWSAuthConnection.java

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import java.net.URL;
4242
import java.text.SimpleDateFormat;
4343
import java.util.Date;
44-
import java.util.Iterator;
4544
import java.util.List;
4645
import java.util.Locale;
4746
import java.util.Map;
@@ -120,7 +119,7 @@ public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey,
120119
* @throws MalformedURLException
121120
* @throws IOException
122121
*/
123-
public Response createBucket(String bucket, Map headers)
122+
public Response createBucket(String bucket, Map<String, List<String>> headers)
124123
throws MalformedURLException, IOException {
125124
return new Response(makeRequest("PUT", bucket, headers));
126125
}
@@ -145,7 +144,7 @@ public Response createBucket(String bucket, Map headers)
145144
* @throws IOException
146145
*/
147146
public ListBucketResponse listBucket(String bucket, String prefix,
148-
String marker, Integer maxKeys, Map headers)
147+
String marker, Integer maxKeys, Map<String, List<String>> headers)
149148
throws MalformedURLException, IOException {
150149
String path = Utils.pathForListOptions(bucket, prefix, marker, maxKeys);
151150
return new ListBucketResponse(makeRequest("GET", path, headers));
@@ -163,7 +162,7 @@ public ListBucketResponse listBucket(String bucket, String prefix,
163162
* @throws MalformedURLException
164163
* @throws IOException
165164
*/
166-
public Response deleteBucket(String bucket, Map headers)
165+
public Response deleteBucket(String bucket, Map<String, List<String>> headers)
167166
throws MalformedURLException, IOException {
168167
return new Response(makeRequest("DELETE", bucket, headers));
169168
}
@@ -184,7 +183,7 @@ public Response deleteBucket(String bucket, Map headers)
184183
* @throws MalformedURLException
185184
* @throws IOException
186185
*/
187-
public Response put(String bucket, String key, S3Object object, Map headers)
186+
public Response put(String bucket, String key, S3Object object, Map<String, List<String>> headers)
188187
throws MalformedURLException, IOException {
189188

190189
boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -195,7 +194,7 @@ public Response put(String bucket, String key, S3Object object, Map headers)
195194
key = "";
196195

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

200199
request.setDoOutput(true);
201200
request.getOutputStream().write(
@@ -221,7 +220,7 @@ public Response put(String bucket, String key, S3Object object, Map headers)
221220
* @throws IOException
222221
*/
223222
public Response putStream(String bucket, String key, S3StreamObject object,
224-
Map headers) throws MalformedURLException, IOException {
223+
Map<String, List<String>> headers) throws MalformedURLException, IOException {
225224

226225
boolean isEmptyKey = (key == null) || (key.length() == 0)
227226
|| (key.trim().length() == 0);
@@ -230,7 +229,7 @@ public Response putStream(String bucket, String key, S3StreamObject object,
230229
if (key == null)
231230
key = "";
232231
HttpURLConnection request = makeStreamRequest("PUT", bucket + pathSep
233-
+ Utils.urlencode(key), headers, object);
232+
+ Utils.urlencodePath(key), headers, object);
234233

235234
request.setDoOutput(true);
236235
if (object.length != 0) {
@@ -263,7 +262,7 @@ public Response putStream(String bucket, String key, S3StreamObject object,
263262
* @throws MalformedURLException
264263
* @throws IOException
265264
*/
266-
public GetResponse get(String bucket, String key, Map headers)
265+
public GetResponse get(String bucket, String key, Map<String, List<String>> headers)
267266
throws MalformedURLException, IOException {
268267

269268
boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -274,7 +273,7 @@ public GetResponse get(String bucket, String key, Map headers)
274273
key = "";
275274

276275
return new GetResponse(makeRequest("GET", bucket + pathSep
277-
+ Utils.urlencode(key), headers));
276+
+ Utils.urlencodePath(key), headers));
278277
}
279278

280279
/**
@@ -291,7 +290,7 @@ public GetResponse get(String bucket, String key, Map headers)
291290
* @throws MalformedURLException
292291
* @throws IOException
293292
*/
294-
public GetStreamResponse getStream(String bucket, String key, Map headers)
293+
public GetStreamResponse getStream(String bucket, String key, Map<String, List<String>> headers)
295294
throws MalformedURLException, IOException {
296295

297296
boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -302,7 +301,7 @@ public GetStreamResponse getStream(String bucket, String key, Map headers)
302301
key = "";
303302

304303
return new GetStreamResponse(makeRequest("GET", bucket + pathSep
305-
+ Utils.urlencode(key), headers));
304+
+ Utils.urlencodePath(key), headers));
306305
}
307306

308307
/**
@@ -319,7 +318,7 @@ public GetStreamResponse getStream(String bucket, String key, Map headers)
319318
* @throws MalformedURLException
320319
* @throws IOException
321320
*/
322-
public GetResponse getTorrent(String bucket, String key, Map headers)
321+
public GetResponse getTorrent(String bucket, String key, Map<String, List<String>> headers)
323322
throws MalformedURLException, IOException {
324323

325324
boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -330,7 +329,7 @@ public GetResponse getTorrent(String bucket, String key, Map headers)
330329
key = "";
331330

332331
return new GetResponse(makeRequest("GET", bucket + pathSep
333-
+ Utils.urlencode(key) + "?torrent", headers));
332+
+ Utils.urlencodePath(key) + "?torrent", headers));
334333
}
335334

336335
/**
@@ -347,7 +346,7 @@ public GetResponse getTorrent(String bucket, String key, Map headers)
347346
* @throws MalformedURLException
348347
* @throws IOException
349348
*/
350-
public Response delete(String bucket, String key, Map headers)
349+
public Response delete(String bucket, String key, Map<String, List<String>> headers)
351350
throws MalformedURLException, IOException {
352351
boolean isEmptyKey = (key == null) || (key.length() == 0)
353352
|| (key.trim().length() == 0);
@@ -356,7 +355,7 @@ public Response delete(String bucket, String key, Map headers)
356355
if (key == null)
357356
key = "";
358357
return new Response(makeRequest("DELETE", bucket + pathSep
359-
+ Utils.urlencode(key), headers));
358+
+ Utils.urlencodePath(key), headers));
360359
}
361360

362361
/**
@@ -371,7 +370,7 @@ public Response delete(String bucket, String key, Map headers)
371370
* @throws MalformedURLException
372371
* @throws IOException
373372
*/
374-
public GetResponse getBucketACL(String bucket, Map headers)
373+
public GetResponse getBucketACL(String bucket, Map<String, List<String>> headers)
375374
throws MalformedURLException, IOException {
376375
return getACL(bucket, "", headers);
377376
}
@@ -390,7 +389,7 @@ public GetResponse getBucketACL(String bucket, Map headers)
390389
* @throws MalformedURLException
391390
* @throws IOException
392391
*/
393-
public GetResponse getACL(String bucket, String key, Map headers)
392+
public GetResponse getACL(String bucket, String key, Map<String, List<String>> headers)
394393
throws MalformedURLException, IOException {
395394

396395
boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -400,7 +399,7 @@ public GetResponse getACL(String bucket, String key, Map headers)
400399
if (key == null)
401400
key = "";
402401
return new GetResponse(makeRequest("GET", bucket + pathSep
403-
+ Utils.urlencode(key) + "?acl", headers));
402+
+ Utils.urlencodePath(key) + "?acl", headers));
404403
}
405404

406405
/**
@@ -417,7 +416,7 @@ public GetResponse getACL(String bucket, String key, Map headers)
417416
* @throws MalformedURLException
418417
* @throws IOException
419418
*/
420-
public Response putBucketACL(String bucket, String aclXMLDoc, Map headers)
419+
public Response putBucketACL(String bucket, String aclXMLDoc, Map<String, List<String>> headers)
421420
throws MalformedURLException, IOException {
422421
return putACL(bucket, "", aclXMLDoc, headers);
423422
}
@@ -439,7 +438,7 @@ public Response putBucketACL(String bucket, String aclXMLDoc, Map headers)
439438
* @throws IOException
440439
*/
441440
public Response putACL(String bucket, String key, String aclXMLDoc,
442-
Map headers) throws MalformedURLException, IOException {
441+
Map<String, List<String>> headers) throws MalformedURLException, IOException {
443442
S3Object object = new S3Object(aclXMLDoc.getBytes(), null);
444443

445444
boolean isEmptyKey = (key == null) || (key.length() == 0)
@@ -449,7 +448,7 @@ public Response putACL(String bucket, String key, String aclXMLDoc,
449448
if (key == null)
450449
key = "";
451450
HttpURLConnection request = makeRequest("PUT", bucket + pathSep
452-
+ Utils.urlencode(key) + "?acl", headers, object);
451+
+ Utils.urlencodePath(key) + "?acl", headers, object);
453452

454453
request.setDoOutput(true);
455454
request.getOutputStream().write(
@@ -468,7 +467,7 @@ public Response putACL(String bucket, String key, String aclXMLDoc,
468467
* @throws MalformedURLException
469468
* @throws IOException
470469
*/
471-
public ListAllMyBucketsResponse listAllMyBuckets(Map headers)
470+
public ListAllMyBucketsResponse listAllMyBuckets(Map<String, List<String>> headers)
472471
throws MalformedURLException, IOException {
473472
return new ListAllMyBucketsResponse(makeRequest("GET", "", headers));
474473
}
@@ -477,7 +476,7 @@ public ListAllMyBucketsResponse listAllMyBuckets(Map headers)
477476
* Make a new HttpURLConnection without passing an S3Object parameter.
478477
*/
479478
private HttpURLConnection makeRequest(String method, String resource,
480-
Map headers) throws MalformedURLException, IOException {
479+
Map<String, List<String>> headers) throws MalformedURLException, IOException {
481480
return makeRequest(method, resource, headers, null);
482481
}
483482

@@ -495,7 +494,7 @@ private HttpURLConnection makeRequest(String method, String resource,
495494
* The S3Object that is to be written (can be null).
496495
*/
497496
private HttpURLConnection makeRequest(String method, String resource,
498-
Map headers, S3Object object) throws MalformedURLException,
497+
Map<String, List<String>> headers, S3Object object) throws MalformedURLException,
499498
IOException {
500499
URL url = makeURL(resource);
501500
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -524,7 +523,7 @@ private HttpURLConnection makeRequest(String method, String resource,
524523
* The S3StreamObject that is to be written (can be null).
525524
*/
526525
private HttpURLConnection makeStreamRequest(String method, String resource,
527-
Map headers, S3StreamObject object) throws MalformedURLException,
526+
Map<String, List<String>> headers, S3StreamObject object) throws MalformedURLException,
528527
IOException {
529528
URL url = makeURL(resource);
530529
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
@@ -548,7 +547,7 @@ private HttpURLConnection makeStreamRequest(String method, String resource,
548547
* A Map of String to List of Strings representing the http
549548
* headers to pass (can be null).
550549
*/
551-
private void addHeaders(HttpURLConnection connection, Map headers) {
550+
private void addHeaders(HttpURLConnection connection, Map<String, List<String>> headers) {
552551
addHeaders(connection, headers, "");
553552
}
554553

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

@@ -578,14 +577,11 @@ private void addMetadataHeaders(HttpURLConnection connection, Map metadata) {
578577
* The string to prepend to each key before adding it to the
579578
* connection.
580579
*/
581-
private void addHeaders(HttpURLConnection connection, Map headers,
580+
private void addHeaders(HttpURLConnection connection, Map<String, List<String>> headers,
582581
String prefix) {
583582
if (headers != null) {
584-
for (Iterator i = headers.keySet().iterator(); i.hasNext();) {
585-
String key = (String) i.next();
586-
for (Iterator j = ((List) headers.get(key)).iterator(); j
587-
.hasNext();) {
588-
String value = (String) j.next();
583+
for (String key : headers.keySet()) {
584+
for (String value :headers.get(key)) {
589585
connection.addRequestProperty(prefix + key, value);
590586
}
591587
}

Frameworks/BusinessLogic/ERAttachment/Sources/com/amazon/s3/GetResponse.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.io.IOException;
1414
import java.io.InputStream;
1515
import java.net.HttpURLConnection;
16-
import java.util.Iterator;
16+
import java.util.List;
1717
import java.util.Map;
1818
import java.util.TreeMap;
1919

@@ -31,7 +31,7 @@ public class GetResponse extends Response {
3131
public GetResponse(HttpURLConnection connection) throws IOException {
3232
super(connection);
3333
if (connection.getResponseCode() < 400) {
34-
Map metadata = extractMetadata(connection);
34+
Map<String, List<String>> metadata = extractMetadata(connection);
3535
byte[] body = slurpInputStream(connection.getInputStream());
3636
object = new S3Object(body, metadata);
3737
}
@@ -41,11 +41,10 @@ public GetResponse(HttpURLConnection connection) throws IOException {
4141
* Examines the response's header fields and returns a Map from String to
4242
* List of Strings representing the object's metadata.
4343
*/
44-
private Map extractMetadata(HttpURLConnection connection) {
45-
TreeMap metadata = new TreeMap();
46-
Map headers = connection.getHeaderFields();
47-
for (Iterator i = headers.keySet().iterator(); i.hasNext();) {
48-
String key = (String) i.next();
44+
private Map<String, List<String>> extractMetadata(HttpURLConnection connection) {
45+
TreeMap<String, List<String>> metadata = new TreeMap<>();
46+
Map<String, List<String>> headers = connection.getHeaderFields();
47+
for (String key : headers.keySet()) {
4948
if (key == null)
5049
continue;
5150
metadata.put(key, headers.get(key));

Frameworks/BusinessLogic/ERAttachment/Sources/com/amazon/s3/GetStreamResponse.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import java.io.IOException;
2929
import java.net.HttpURLConnection;
30-
import java.util.Iterator;
30+
import java.util.List;
3131
import java.util.Map;
3232
import java.util.TreeMap;
3333

@@ -47,7 +47,7 @@ public class GetStreamResponse extends Response {
4747
public GetStreamResponse(HttpURLConnection connection) throws IOException {
4848
super(connection);
4949
if (connection.getResponseCode() < 400) {
50-
Map metadata = extractMetadata(connection);
50+
Map<String, List<String>> metadata = extractMetadata(connection);
5151
object = new S3StreamObject(connection.getInputStream(),
5252
metadata);
5353
}
@@ -57,11 +57,10 @@ public GetStreamResponse(HttpURLConnection connection) throws IOException {
5757
* Examines the response's header fields and returns a Map from String to
5858
* List of Strings representing the object's metadata.
5959
*/
60-
private Map extractMetadata(HttpURLConnection connection) {
61-
TreeMap metadata = new TreeMap();
62-
Map headers = connection.getHeaderFields();
63-
for (Iterator i = headers.keySet().iterator(); i.hasNext();) {
64-
String key = (String) i.next();
60+
private Map<String, List<String>> extractMetadata(HttpURLConnection connection) {
61+
TreeMap<String, List<String>> metadata = new TreeMap<>();
62+
Map<String, List<String>> headers = connection.getHeaderFields();
63+
for (String key : headers.keySet()) {
6564
if (key == null)
6665
continue;
6766
if (key.startsWith(Utils.METADATA_PREFIX)) {

Frameworks/BusinessLogic/ERAttachment/Sources/com/amazon/s3/ListAllMyBucketsResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ListAllMyBucketsResponse extends Response {
3131
* A list of Bucket objects, one for each of this account's buckets. Will be null if
3232
* the request fails.
3333
*/
34-
public List entries;
34+
public List<Bucket> entries;
3535

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

5353
static class ListAllMyBucketsHandler extends DefaultHandler {
5454

55-
private List entries = null;
55+
private List<Bucket> entries = null;
5656
private Bucket currBucket = null;
5757
private StringBuffer currText = null;
5858
private SimpleDateFormat iso8601Parser = null;
5959

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

106-
public List getEntries() {
106+
public List<Bucket> getEntries() {
107107
return entries;
108108
}
109109
}

0 commit comments

Comments
 (0)