Created
September 16, 2010 21:26
-
-
Save bbrowning/583206 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: src/org/jgroups/protocols/S3_PING.java | |
| =================================================================== | |
| RCS file: /cvsroot/javagroups/JGroups/src/org/jgroups/protocols/S3_PING.java,v | |
| retrieving revision 1.12 | |
| diff -u -r1.12 S3_PING.java | |
| --- src/org/jgroups/protocols/S3_PING.java 16 Sep 2010 14:57:17 -0000 1.12 | |
| +++ src/org/jgroups/protocols/S3_PING.java 16 Sep 2010 21:25:53 -0000 | |
| @@ -49,6 +49,12 @@ | |
| @Property(description="When non-null, we set location to prefix-UUID") | |
| protected String prefix=null; | |
| + @Property(description="When non-null, we use this pre-signed URL for PUTs") | |
| + protected String pre_signed_put_url=null; | |
| + | |
| + @Property(description="When non-null, we use this pre-signed URL for DELETEs") | |
| + protected String pre_signed_delete_url=null; | |
| + | |
| protected AWSAuthConnection conn=null; | |
| @@ -102,6 +108,9 @@ | |
| List<PingData> retval=new ArrayList<PingData>(); | |
| try { | |
| + if (pre_signed_put_url != null) { | |
| + clustername = null; | |
| + } | |
| ListBucketResponse rsp=conn.listBucket(location, clustername, null, null, null); | |
| if(rsp.entries != null) { | |
| for(Iterator<ListEntry> it=rsp.entries.iterator(); it.hasNext();) { | |
| @@ -137,11 +146,18 @@ | |
| String filename=local_addr instanceof org.jgroups.util.UUID? ((org.jgroups.util.UUID)local_addr).toStringLong() : local_addr.toString(); | |
| String key=clustername + "/" + filename; | |
| try { | |
| - Map headers=new TreeMap(); | |
| - headers.put("Content-Type", Arrays.asList("text/plain")); | |
| byte[] buf=Util.objectToByteBuffer(data); | |
| S3Object val=new S3Object(buf, null); | |
| - conn.put(location, key, val, headers).connection.getResponseMessage(); | |
| + | |
| + if (pre_signed_put_url != null) { | |
| + Map headers = new TreeMap(); | |
| + headers.put("x-amz-acl", Arrays.asList("public-read")); | |
| + conn.put(pre_signed_put_url, val, headers).connection.getResponseMessage(); | |
| + } else { | |
| + Map headers=new TreeMap(); | |
| + headers.put("Content-Type", Arrays.asList("text/plain")); | |
| + conn.put(location, key, val, headers).connection.getResponseMessage(); | |
| + } | |
| } | |
| catch(Exception e) { | |
| log.error("failed marshalling " + data + " to buffer", e); | |
| @@ -157,7 +173,11 @@ | |
| try { | |
| Map headers=new TreeMap(); | |
| headers.put("Content-Type", Arrays.asList("text/plain")); | |
| - conn.delete(location, key, headers).connection.getResponseMessage(); | |
| + if (pre_signed_delete_url != null) { | |
| + conn.delete(pre_signed_delete_url).connection.getResponseMessage(); | |
| + } else { | |
| + conn.delete(location, key, headers).connection.getResponseMessage(); | |
| + } | |
| if(log.isTraceEnabled()) | |
| log.trace("removing " + location + "/" + key); | |
| } | |
| @@ -355,6 +375,14 @@ | |
| return new Response(request); | |
| } | |
| + public Response put(String preSignedUrl, S3Object object, Map headers) throws IOException { | |
| + HttpURLConnection request = makePreSignedRequest("PUT", preSignedUrl, headers); | |
| + request.setDoOutput(true); | |
| + request.getOutputStream().write(object.data == null? new byte[]{} : object.data); | |
| + | |
| + return new Response(request); | |
| + } | |
| + | |
| /** | |
| * Creates a copy of an existing S3 Object. In this signature, we will copy the | |
| * existing metadata. The default access control policy is private; if you want | |
| @@ -444,6 +472,10 @@ | |
| return new Response(makeRequest("DELETE", bucket, Utils.urlencode(key), null, headers)); | |
| } | |
| + public Response delete(String preSignedUrl) throws IOException { | |
| + return new Response(makePreSignedRequest("DELETE", preSignedUrl, null)); | |
| + } | |
| + | |
| /** | |
| * Get the requestPayment xml document for a given bucket | |
| * @param bucket The name of the bucket | |
| @@ -642,6 +674,16 @@ | |
| return connection; | |
| } | |
| + private HttpURLConnection makePreSignedRequest(String method, String preSignedUrl, Map headers) throws IOException { | |
| + URL url = new URL(preSignedUrl); | |
| + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | |
| + connection.setRequestMethod(method); | |
| + | |
| + addHeaders(connection, headers); | |
| + | |
| + return connection; | |
| + } | |
| + | |
| /** | |
| * Add the given headers to the HttpURLConnection. | |
| * @param connection The HttpURLConnection to which the headers will be added. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment