throw new RuntimeException("HTTP redirect support required."); addHeaders(connection, headers); if(object != null) addMetadataHeaders(connection, object.metadata); addAuthHeader(connection, method, bucket, key, pathArgs);
ListAllMyBucketsResponse bucket_list=conn.listAllMyBuckets(null); List buckets=bucket_list.entries; if(buckets != null) { if(!skip_bucket_existence_check && !conn.checkBucketExists(location)) { conn.createBucket(location, AWSAuthConnection.LOCATION_DEFAULT, null).connection.getResponseMessage();
@Override protected void removeAll(String clustername) { if(clustername == null) return; try { Map headers=new TreeMap(); headers.put("Content-Type", Collections.singletonList("text/plain")); clustername=sanitize(clustername); ListBucketResponse rsp=conn.listBucket(location, clustername, null, null, null); if(rsp.entries != null) { for(Iterator<ListEntry> it=rsp.entries.iterator(); it.hasNext();) { ListEntry key=it.next(); try { if (usingPreSignedUrls()) conn.delete(pre_signed_delete_url).connection.getResponseMessage(); else conn.delete(location, key.key, headers).connection.getResponseMessage(); log.trace("removing %s/%s", location, key.key); } catch(Throwable t) { log.error("failed deleting object %s/%s: %s", location, key.key, t); } } } } catch(IOException ex) { log.error(Util.getMessage("FailedDeletingAllObjects"), ex); } }
throw new RuntimeException("HTTP redirect support required."); addHeaders(connection, headers); if(object != null) addMetadataHeaders(connection, object.metadata); addAuthHeader(connection, method, bucket, key, pathArgs);
@Override protected void readAll(List<Address> members, String clustername, Responses responses) { if(clustername == null) return; try { if (usingPreSignedUrls()) { PreSignedUrlParser parsedPut = new PreSignedUrlParser(pre_signed_put_url); clustername = parsedPut.getPrefix(); } clustername=sanitize(clustername); ListBucketResponse rsp=conn.listBucket(location, clustername, null, null, null); if(rsp.entries != null) { for(Iterator<ListEntry> it=rsp.entries.iterator(); it.hasNext();) { ListEntry key=it.next(); try { GetResponse val=conn.get(location, key.key, null); readResponse(val, members, responses); } catch(Throwable t) { log.error("failed reading key %s: %s", key.key, t); } } } } catch(IOException ex) { log.error(Util.getMessage("FailedReadingAddresses"), ex); } }
ListAllMyBucketsResponse bucket_list=conn.listAllMyBuckets(null); List buckets=bucket_list.entries; if(buckets != null) { if(!skip_bucket_existence_check && !conn.checkBucketExists(location)) { conn.createBucket(location, AWSAuthConnection.LOCATION_DEFAULT, null).connection.getResponseMessage();
@Override protected void removeAll(String clustername) { if(clustername == null) return; try { Map headers=new TreeMap(); headers.put("Content-Type", Collections.singletonList("text/plain")); clustername=sanitize(clustername); ListBucketResponse rsp=conn.listBucket(location, clustername, null, null, null); if(rsp.entries != null) { for(Iterator<ListEntry> it=rsp.entries.iterator(); it.hasNext();) { ListEntry key=it.next(); try { if (usingPreSignedUrls()) conn.delete(pre_signed_delete_url).connection.getResponseMessage(); else conn.delete(location, key.key, headers).connection.getResponseMessage(); log.trace("removing %s/%s", location, key.key); } catch(Throwable t) { log.error("failed deleting object %s/%s: %s", location, key.key, t); } } } } catch(IOException ex) { log.error(Util.getMessage("FailedDeletingAllObjects"), ex); } }
/** * Add the appropriate Authorization header to the HttpURLConnection. * @param connection The HttpURLConnection to which the header will be added. * @param method The HTTP method to use (GET, PUT, DELETE) * @param bucket the bucket name this request is for * @param key the key this request is for * @param pathArgs path arguments which are part of this request */ private void addAuthHeader(HttpURLConnection connection, String method, String bucket, String key, Map pathArgs) { if(connection.getRequestProperty("Date") == null) { connection.setRequestProperty("Date", httpDate()); } if(connection.getRequestProperty("Content-Type") == null) { connection.setRequestProperty("Content-Type", ""); } if(this.awsAccessKeyId != null && this.awsSecretAccessKey != null) { String canonicalString= Utils.makeCanonicalString(method, bucket, key, pathArgs, connection.getRequestProperties()); String encodedCanonical=Utils.encode(this.awsSecretAccessKey, canonicalString, false); connection.setRequestProperty("Authorization", "AWS " + this.awsAccessKeyId + ":" + encodedCanonical); } }
protected void remove(String clustername, Address addr) { if(clustername == null || addr == null) return; String filename=addressToFilename(addr);// addr instanceof org.jgroups.util.UUID? ((org.jgroups.util.UUID)addr).toStringLong() : addr.toString(); String key=sanitize(clustername) + "/" + sanitize(filename); try { Map headers=new TreeMap(); headers.put("Content-Type", Collections.singletonList("text/plain")); if (usingPreSignedUrls()) { conn.delete(pre_signed_delete_url).connection.getResponseMessage(); } else { conn.delete(location, key, headers).connection.getResponseMessage(); } if(log.isTraceEnabled()) log.trace("removing " + location + "/" + key); } catch(Exception e) { log.error(Util.getMessage("FailureRemovingData"), e); } }
protected AWSAuthConnection createConnection() { return port > 0? new AWSAuthConnection(access_key, secret_access_key, use_ssl, host, port) : new AWSAuthConnection(access_key, secret_access_key, use_ssl, host); }
/** * Add the given metadata fields to the HttpURLConnection. * @param connection The HttpURLConnection to which the headers will be added. * @param metadata A Map of String to List of Strings representing the s3 * metadata for this resource. */ private static void addMetadataHeaders(HttpURLConnection connection, Map metadata) { addHeaders(connection, metadata, Utils.METADATA_PREFIX); }
/** * Add the given headers to the HttpURLConnection. * @param connection The HttpURLConnection to which the headers will be added. * @param headers A Map of String to List of Strings representing the http * headers to pass (can be null). */ private static void addHeaders(HttpURLConnection connection, Map headers) { addHeaders(connection, headers, ""); }
/** * Get the ACL for a given bucket * @param bucket The name of the bucket where the object lives. * @param headers A Map of String to List of Strings representing the http * headers to pass (can be null). */ public GetResponse getBucketACL(String bucket, Map headers) throws IOException { return getACL(bucket, "", headers); }
protected AWSAuthConnection createConnection() { // Fix for JGRP-1992. Always use secure port, if port is not specified int tmp_port=port > 0? port : Utils.SECURE_PORT; return new AWSAuthConnection(access_key, secret_access_key, use_ssl, host, tmp_port); } }
/** * Creates a new bucket. * @param bucket The name of the bucket to create. * @param headers A Map of String to List of Strings representing the http headers to pass (can be null). */ public Response createBucket(String bucket, Map headers) throws IOException { return createBucket(bucket, null, headers); }
private static 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; }
@Override protected void readAll(List<Address> members, String clustername, Responses responses) { if(clustername == null) return; try { if (usingPreSignedUrls()) { PreSignedUrlParser parsedPut = new PreSignedUrlParser(pre_signed_put_url); clustername = parsedPut.getPrefix(); } clustername=sanitize(clustername); ListBucketResponse rsp=conn.listBucket(location, clustername, null, null, null); if(rsp.entries != null) { for(Iterator<ListEntry> it=rsp.entries.iterator(); it.hasNext();) { ListEntry key=it.next(); try { GetResponse val=conn.get(location, key.key, null); readResponse(val, members, responses); } catch(Throwable t) { log.error("failed reading key %s: %s", key.key, t); } } } } catch(IOException ex) { log.error(Util.getMessage("FailedReadingAddresses"), ex); } }
/** * Add the appropriate Authorization header to the HttpURLConnection. * @param connection The HttpURLConnection to which the header will be added. * @param method The HTTP method to use (GET, PUT, DELETE) * @param bucket the bucket name this request is for * @param key the key this request is for * @param pathArgs path arguments which are part of this request */ private void addAuthHeader(HttpURLConnection connection, String method, String bucket, String key, Map pathArgs) { if(connection.getRequestProperty("Date") == null) { connection.setRequestProperty("Date", httpDate()); } if(connection.getRequestProperty("Content-Type") == null) { connection.setRequestProperty("Content-Type", ""); } if(this.awsAccessKeyId != null && this.awsSecretAccessKey != null) { String canonicalString= Utils.makeCanonicalString(method, bucket, key, pathArgs, connection.getRequestProperties()); String encodedCanonical=Utils.encode(this.awsSecretAccessKey, canonicalString, false); connection.setRequestProperty("Authorization", "AWS " + this.awsAccessKeyId + ":" + encodedCanonical); } }
protected void remove(String clustername, Address addr) { if(clustername == null || addr == null) return; String filename=addressToFilename(addr);// addr instanceof org.jgroups.util.UUID? ((org.jgroups.util.UUID)addr).toStringLong() : addr.toString(); String key=sanitize(clustername) + "/" + sanitize(filename); try { Map headers=new TreeMap(); headers.put("Content-Type", Collections.singletonList("text/plain")); if (usingPreSignedUrls()) { conn.delete(pre_signed_delete_url).connection.getResponseMessage(); } else { conn.delete(location, key, headers).connection.getResponseMessage(); } if(log.isTraceEnabled()) log.trace("removing " + location + "/" + key); } catch(Exception e) { log.error(Util.getMessage("FailureRemovingData"), e); } }
protected AWSAuthConnection createConnection() { return port > 0? new AWSAuthConnection(access_key, secret_access_key, use_ssl, host, port) : new AWSAuthConnection(access_key, secret_access_key, use_ssl, host); }