/** * Performs an HTTP GET request using the {@link #performRequest} method. * * @param bucketName the bucket's name * @param objectKey the object's key name, may be null if the operation is on a bucket only. * @param requestParameters parameters to add to the request URL as GET params * @param requestHeaders headers to add to the request * @return The HTTP method object used to perform the request. * @throws org.jets3t.service.ServiceException * */ protected HttpResponse performRestGet(String bucketName, String objectKey, Map<String, String> requestParameters, Map<String, Object> requestHeaders) throws ServiceException { int[] expectedStatusCodes = {200}; // 200 is normally the expected response code if (requestHeaders != null && requestHeaders.containsKey("Range")) { // Partial data responses have a status code of 206, or sometimes 200 // for complete responses (issue #80) expectedStatusCodes = new int[]{206, 200}; } return performRestGet(bucketName, objectKey, requestParameters, requestHeaders, expectedStatusCodes); }
/** * Performs an HTTP GET request using the {@link #performRequest} method. * * @param bucketName the bucket's name * @param objectKey the object's key name, may be null if the operation is on a bucket only. * @param requestParameters parameters to add to the request URL as GET params * @param requestHeaders headers to add to the request * @return The HTTP method object used to perform the request. * @throws org.jets3t.service.ServiceException * */ protected HttpResponse performRestGet(String bucketName, String objectKey, Map<String, String> requestParameters, Map<String, Object> requestHeaders) throws ServiceException { int[] expectedStatusCodes = {200}; // 200 is normally the expected response code if (requestHeaders != null && requestHeaders.containsKey("Range")) { // Partial data responses have a status code of 206, or sometimes 200 // for complete responses (issue #80) expectedStatusCodes = new int[]{206, 200}; } return performRestGet(bucketName, objectKey, requestParameters, requestHeaders, expectedStatusCodes); }
protected String getBucketLocationImpl(String bucketName) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving location of Bucket: " + bucketName); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("location", ""); HttpResponse httpResponse = performRestGet(bucketName, null, requestParameters, null); return getXmlResponseSaxParser() .parseBucketLocationResponse( new HttpMethodReleaseInputStream(httpResponse)); }
protected String getBucketLocationImpl(String bucketName) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving location of Bucket: " + bucketName); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("location", ""); HttpResponse httpResponse = performRestGet(bucketName, null, requestParameters, null); return getXmlResponseSaxParser() .parseBucketLocationResponse( new HttpMethodReleaseInputStream(httpResponse)); }
@Override protected AccessControlList getBucketAclImpl(String bucketName) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving Access Control List for Bucket: " + bucketName); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("acl", ""); HttpResponse httpResponse = performRestGet(bucketName, null, requestParameters, null); return getXmlResponseSaxParser() .parseAccessControlListResponse( new HttpMethodReleaseInputStream(httpResponse)).getAccessControlList(); }
protected StorageBucketLoggingStatus getBucketLoggingStatusImpl(String bucketName) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving Logging Status for Bucket: " + bucketName); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("logging", ""); HttpResponse httpResponse = performRestGet(bucketName, null, requestParameters, null); return getXmlResponseSaxParser() .parseLoggingStatusResponse( new HttpMethodReleaseInputStream(httpResponse)).getBucketLoggingStatus(); }
protected AccessControlList getObjectAclImpl(String bucketName, String objectKey) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving Access Control List for bucketName=" + bucketName + ", objectKey=" + objectKey); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("acl", ""); HttpResponse httpResponse = performRestGet(bucketName, objectKey, requestParameters, null); return getXmlResponseSaxParser() .parseAccessControlListResponse( new HttpMethodReleaseInputStream(httpResponse)).getAccessControlList(); }
protected AccessControlList getObjectAclImpl(String bucketName, String objectKey) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving Access Control List for bucketName=" + bucketName + ", objectKey=" + objectKey); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("acl", ""); HttpResponse httpResponse = performRestGet(bucketName, objectKey, requestParameters, null); return getXmlResponseSaxParser() .parseAccessControlListResponse( new HttpMethodReleaseInputStream(httpResponse)).getAccessControlList(); }
@Override protected AccessControlList getBucketAclImpl(String bucketName) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving Access Control List for Bucket: " + bucketName); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("acl", ""); HttpResponse httpResponse = performRestGet(bucketName, null, requestParameters, null); return getXmlResponseSaxParser() .parseAccessControlListResponse( new HttpMethodReleaseInputStream(httpResponse)).getAccessControlList(); }
protected StorageBucketLoggingStatus getBucketLoggingStatusImpl(String bucketName) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving Logging Status for Bucket: " + bucketName); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("logging", ""); HttpResponse httpResponse = performRestGet(bucketName, null, requestParameters, null); return getXmlResponseSaxParser() .parseLoggingStatusResponse( new HttpMethodReleaseInputStream(httpResponse)).getBucketLoggingStatus(); }
protected WebsiteConfig getWebsiteConfigImpl(String bucketName) throws ServiceException { Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put(this.isTargettingGoogleStorageService() ? "websiteConfig" : "website", ""); HttpResponse getMethod = performRestGet(bucketName, null, requestParameters, null); return getXmlResponseSaxParser().parseWebsiteConfigurationResponse( new HttpMethodReleaseInputStream(getMethod)); }
@Override protected AccessControlList getObjectAclImpl(String bucketName, String objectKey, String versionId) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving versioned Access Control List for bucketName=" + bucketName + ", objectKey=" + objectKey); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("acl", ""); if(versionId != null) { requestParameters.put("versionId", versionId); } HttpResponse httpResponse = performRestGet(bucketName, objectKey, requestParameters, null); return getXmlResponseSaxParser() .parseAccessControlListResponse( new HttpMethodReleaseInputStream(httpResponse)).getAccessControlList(); }
protected WebsiteConfig getWebsiteConfigImpl(String bucketName) throws ServiceException { Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put(this.isTargettingGoogleStorageService() ? "websiteConfig" : "website", ""); HttpResponse getMethod = performRestGet(bucketName, null, requestParameters, null); return getXmlResponseSaxParser().parseWebsiteConfigurationResponse( new HttpMethodReleaseInputStream(getMethod)); }
@Override protected AccessControlList getObjectAclImpl(String bucketName, String objectKey, String versionId) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Retrieving versioned Access Control List for bucketName=" + bucketName + ", objectKey=" + objectKey); } Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put("acl", ""); if(versionId != null) { requestParameters.put("versionId", versionId); } HttpResponse httpResponse = performRestGet(bucketName, objectKey, requestParameters, null); return getXmlResponseSaxParser() .parseAccessControlListResponse( new HttpMethodReleaseInputStream(httpResponse)).getAccessControlList(); }
@Override protected StorageBucket[] listAllBucketsImpl(Map<String, Object> headers) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Listing all buckets for user: " + getProviderCredentials().getAccessKey()); } String bucketName = ""; // Root path of S3 service lists the user's buckets. HttpResponse httpResponse = performRestGet(bucketName, null, null, headers); String contentType = httpResponse.getFirstHeader("Content-Type").getValue(); if(!isXmlContentType(contentType)) { throw new ServiceException("Expected XML document response from S3 but received content type " + contentType); } return getXmlResponseSaxParser() .parseListMyBucketsResponse( new HttpMethodReleaseInputStream(httpResponse)).getBuckets(); }
HttpResponse httpResponse = performRestGet(bucketName, null, parameters, null); ListBucketHandler listBucketHandler;
@Override protected StorageOwner getAccountOwnerImpl() throws ServiceException { if(log.isDebugEnabled()) { log.debug("Looking up owner of S3 account via the ListAllBuckets response: " + getProviderCredentials().getAccessKey()); } String bucketName = ""; // Root path of S3 service lists the user's buckets. HttpResponse httpResponse = performRestGet(bucketName, null, null, null); String contentType = httpResponse.getFirstHeader("Content-Type").getValue(); if(!isXmlContentType(contentType)) { throw new ServiceException("Expected XML document response from S3 but received content type " + contentType); } return getXmlResponseSaxParser() .parseListMyBucketsResponse( new HttpMethodReleaseInputStream(httpResponse)).getOwner(); }
@Override protected StorageOwner getAccountOwnerImpl() throws ServiceException { if(log.isDebugEnabled()) { log.debug("Looking up owner of S3 account via the ListAllBuckets response: " + getProviderCredentials().getAccessKey()); } String bucketName = ""; // Root path of S3 service lists the user's buckets. HttpResponse httpResponse = performRestGet(bucketName, null, null, null); String contentType = httpResponse.getFirstHeader("Content-Type").getValue(); if(!isXmlContentType(contentType)) { throw new ServiceException("Expected XML document response from S3 but received content type " + contentType); } return getXmlResponseSaxParser() .parseListMyBucketsResponse( new HttpMethodReleaseInputStream(httpResponse)).getOwner(); }
@Override protected StorageBucket[] listAllBucketsImpl(Map<String, Object> headers) throws ServiceException { if(log.isDebugEnabled()) { log.debug("Listing all buckets for user: " + getProviderCredentials().getAccessKey()); } String bucketName = ""; // Root path of S3 service lists the user's buckets. HttpResponse httpResponse = performRestGet(bucketName, null, null, headers); String contentType = httpResponse.getFirstHeader("Content-Type").getValue(); if(!isXmlContentType(contentType)) { throw new ServiceException("Expected XML document response from S3 but received content type " + contentType); } return getXmlResponseSaxParser() .parseListMyBucketsResponse( new HttpMethodReleaseInputStream(httpResponse)).getBuckets(); }
httpResponse = performRestGet(bucketName, objectKey, requestParameters, requestHeaders);