/** * Throws an exception if an object's key name is null or empty. * @param key * An object's key name. * @param action * the action being attempted which this assertion is applied, for debugging purposes. * @throws ServiceException */ protected void assertValidObject(String key, String action) throws ServiceException { if (key == null || key.length() == 0) { throw new ServiceException("The action " + action + " cannot be performed with an invalid object key name: " + key); } }
/** * Throws an exception if an object's key name is null or empty. * @param key * An object's key name. * @param action * the action being attempted which this assertion is applied, for debugging purposes. * @throws ServiceException */ protected void assertValidObject(String key, String action) throws ServiceException { if (key == null || key.length() == 0) { throw new ServiceException("The action " + action + " cannot be performed with an invalid object key name: " + key); } }
/** * Throws an exception if this service is anonymous (that is, it was created without * an {@link ProviderCredentials} object representing a user account. * @param action * the action being attempted which this assertion is applied, for debugging purposes. * @throws ServiceException */ protected void assertAuthenticatedConnection(String action) throws ServiceException { if (!isAuthenticatedConnection()) { throw new ServiceException( "The requested action cannot be performed with a non-authenticated service: " + action); } }
/** * Throws an exception if this service is anonymous (that is, it was created without * an {@link ProviderCredentials} object representing a user account. * @param action * the action being attempted which this assertion is applied, for debugging purposes. * @throws ServiceException */ protected void assertAuthenticatedConnection(String action) throws ServiceException { if (!isAuthenticatedConnection()) { throw new ServiceException( "The requested action cannot be performed with a non-authenticated service: " + action); } }
/** * Throws an exception if an object is null or contains a null/empty key. * @param object * @param action * the action being attempted which this assertion is applied, for debugging purposes. * @throws ServiceException */ protected void assertValidObject(StorageObject object, String action) throws ServiceException { if (object == null || object.getKey() == null || object.getKey().length() == 0) { throw new ServiceException("The action " + action + " cannot be performed with an invalid object: " + object); } }
/** * Throws an exception if an object is null or contains a null/empty key. * @param object * @param action * the action being attempted which this assertion is applied, for debugging purposes. * @throws ServiceException */ protected void assertValidObject(StorageObject object, String action) throws ServiceException { if (object == null || object.getKey() == null || object.getKey().length() == 0) { throw new ServiceException("The action " + action + " cannot be performed with an invalid object: " + object); } }
/** * Throws an exception if a bucket is null or contains a null/empty name. * @param bucket * @param action * the action being attempted which this assertion is applied, for debugging purposes. * @throws ServiceException */ protected void assertValidBucket(StorageBucket bucket, String action) throws ServiceException { if (bucket == null || bucket.getName() == null || bucket.getName().length() == 0) { throw new ServiceException("The action " + action + " cannot be performed with an invalid bucket: " + bucket); } }
/** * Throws an exception if a bucket is null or contains a null/empty name. * @param bucket * @param action * the action being attempted which this assertion is applied, for debugging purposes. * @throws ServiceException */ protected void assertValidBucket(StorageBucket bucket, String action) throws ServiceException { if (bucket == null || bucket.getName() == null || bucket.getName().length() == 0) { throw new ServiceException("The action " + action + " cannot be performed with an invalid bucket: " + bucket); } }
protected void setWebsiteConfigImpl(String bucketName, WebsiteConfig config) throws ServiceException { Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put(this.isTargettingGoogleStorageService() ? "websiteConfig" : "website", ""); Map<String, Object> metadata = new HashMap<String, Object>(); String xml; try { xml = config.toXml(); } catch(Exception e) { throw new ServiceException("Unable to build WebsiteConfig XML document", e); } performRestPut(bucketName, null, metadata, requestParameters, new StringEntity(xml, ContentType.create("text/plain", Constants.DEFAULT_ENCODING)), true); }
/** * @return * an XML representation of the Access Control List object, suitable to send to * a storage service in the request body. */ public String toXml() throws ServiceException { try { return toXMLBuilder().asString(); } catch (Exception e) { throw new ServiceException("Failed to build XML document for ACL", e); } }
protected void setWebsiteConfigImpl(String bucketName, WebsiteConfig config) throws ServiceException { Map<String, String> requestParameters = new HashMap<String, String>(); requestParameters.put(this.isTargettingGoogleStorageService() ? "websiteConfig" : "website", ""); Map<String, Object> metadata = new HashMap<String, Object>(); String xml; try { xml = config.toXml(); } catch(Exception e) { throw new ServiceException("Unable to build WebsiteConfig XML document", e); } performRestPut(bucketName, null, metadata, requestParameters, new StringEntity(xml, ContentType.create("text/plain", Constants.DEFAULT_ENCODING)), true); }
/** * @return * an XML representation of the Access Control List object, suitable to send to * a storage service in the request body. */ public String toXml() throws ServiceException { try { return toXMLBuilder().asString(); } catch (Exception e) { throw new ServiceException("Failed to build XML document for ACL", e); } }
/** * * @return * An XML representation of the object suitable for use as an input to the REST/HTTP interface. * * @throws org.jets3t.service.S3ServiceException */ public String toXml() throws ServiceException { try { return toXMLBuilder().asString(); } catch (Exception e) { throw new ServiceException("Failed to build XML document for ACL", e); } }
/** * * @return * An XML representation of the object suitable for use as an input to the REST/HTTP interface. * * @throws org.jets3t.service.S3ServiceException */ public String toXml() throws ServiceException { try { return toXMLBuilder().asString(); } catch (Exception e) { throw new ServiceException("Failed to build XML document for ACL", e); } }
@Override public void event(GetObjectHeadsEvent event) { if (GetObjectHeadsEvent.EVENT_IN_PROGRESS == event.getEventCode()) { StorageObject[] finishedObjects = event.getCompletedObjects(); if (finishedObjects.length > 0) { objectsCompleteList.addAll(Arrays.asList(finishedObjects)); } } else if (GetObjectHeadsEvent.EVENT_ERROR == event.getEventCode()) { serviceExceptions[0] = new ServiceException( "Failed to retrieve detailed information about all objects", event.getErrorCause()); } } });
@Override public void event(GetObjectHeadsEvent event) { if (GetObjectHeadsEvent.EVENT_IN_PROGRESS == event.getEventCode()) { StorageObject[] finishedObjects = event.getCompletedObjects(); if (finishedObjects.length > 0) { objectsCompleteList.addAll(Arrays.asList(finishedObjects)); } } else if (GetObjectHeadsEvent.EVENT_ERROR == event.getEventCode()) { serviceExceptions[0] = new ServiceException( "Failed to retrieve detailed information about all objects", event.getErrorCause()); } } });
@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(); }
public ServiceException getServiceException() { String fullMessage = message + ": PartNumber=" + partNumber + ", MinSizeAllowed=" + minSizeAllowed + ", ProposedSize=" + proposedSize + ", ETag=" + etag; ServiceException e = new ServiceException(fullMessage); e.setErrorCode(code); e.setErrorMessage(message); e.setErrorHostId(hostId); e.setErrorRequestId(requestId); return e; }
public ServiceException getServiceException() { String fullMessage = message + ": PartNumber=" + partNumber + ", MinSizeAllowed=" + minSizeAllowed + ", ProposedSize=" + proposedSize + ", ETag=" + etag; ServiceException e = new ServiceException(fullMessage); e.setErrorCode(code); e.setErrorMessage(message); e.setErrorHostId(hostId); e.setErrorRequestId(requestId); return e; }