本文整理汇总了Java中org.jets3t.service.ServiceException类的典型用法代码示例。如果您正苦于以下问题:Java ServiceException类的具体用法?Java ServiceException怎么用?Java ServiceException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceException类属于org.jets3t.service包,在下文中一共展示了ServiceException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPermission
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public Acl getPermission(final Path file) throws BackgroundException {
try {
if(containerService.isContainer(file)) {
// This method can be performed by anonymous services, but can only succeed if the
// bucket's existing ACL already allows write access by the anonymous user.
// In general, you can only access the ACL of a bucket if the ACL already in place
// for that bucket (in S3) allows you to do so.
return this.convert(session.getClient().getBucketAcl(containerService.getContainer(file).getName()));
}
else if(file.isFile() || file.isPlaceholder()) {
return this.convert(session.getClient().getVersionedObjectAcl(file.attributes().getVersionId(),
containerService.getContainer(file).getName(), containerService.getKey(file)));
}
return Acl.EMPTY;
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Failure to read attributes of {0}", e, file);
}
}
示例2: setPermission
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public void setPermission(final Path file, final Acl acl) throws BackgroundException {
try {
final Path container = containerService.getContainer(file);
if(null == acl.getOwner()) {
// Read owner from cache
acl.setOwner(file.attributes().getAcl().getOwner());
}
if(null == acl.getOwner()) {
// Read owner from bucket
final Acl permission = this.getPermission(container);
acl.setOwner(permission.getOwner());
}
if(containerService.isContainer(file)) {
session.getClient().putBucketAcl(container.getName(), this.convert(acl));
}
else {
if(file.isFile() || file.isPlaceholder()) {
session.getClient().putObjectAcl(container.getName(), containerService.getKey(file), this.convert(acl));
}
}
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Cannot change permissions of {0}", e, file);
}
}
示例3: write
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public HttpResponseOutputStream<List<MultipartPart>> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
final S3Object object = new S3WriteFeature(session, new S3DisabledMultipartService())
.getDetails(file, status);
// ID for the initiated multipart upload.
final MultipartUpload multipart;
try {
multipart = session.getClient().multipartStartUpload(
containerService.getContainer(file).getName(), object);
if(log.isDebugEnabled()) {
log.debug(String.format("Multipart upload started for %s with ID %s",
multipart.getObjectKey(), multipart.getUploadId()));
}
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Upload {0} failed", e, file);
}
final MultipartOutputStream proxy = new MultipartOutputStream(multipart, file, status);
return new HttpResponseOutputStream<List<MultipartPart>>(new MemorySegementingOutputStream(proxy,
preferences.getInteger("s3.upload.multipart.partsize.minimum"))) {
@Override
public List<MultipartPart> getStatus() throws BackgroundException {
return proxy.getCompleted();
}
};
}
示例4: read
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
try {
final HttpRange range = HttpRange.withStatus(status);
final RequestEntityRestStorageService client = session.getClient();
final S3Object object = client.getVersionedObject(
file.attributes().getVersionId(),
containerService.getContainer(file).getName(),
containerService.getKey(file),
null, // ifModifiedSince
null, // ifUnmodifiedSince
null, // ifMatch
null, // ifNoneMatch
status.isAppend() ? range.getStart() : null,
status.isAppend() ? (range.getEnd() == -1 ? null : range.getEnd()) : null);
if(log.isDebugEnabled()) {
log.debug(String.format("Reading stream with content length %d", object.getContentLength()));
}
return object.getDataInputStream();
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Download {0} failed", e, file);
}
}
示例5: retryRequest
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) {
if(super.retryRequest(exception, executionCount, context)) {
final Object attribute = context.getAttribute(HttpCoreContext.HTTP_REQUEST);
if(attribute instanceof HttpUriRequest) {
final HttpUriRequest method = (HttpUriRequest) attribute;
log.warn(String.format("Retrying request %s", method));
try {
// Build the authorization string for the method.
authorizer.authorizeHttpRequest(method, context, null);
return true;
}
catch(ServiceException e) {
log.warn("Unable to generate updated authorization string for retried request", e);
}
}
}
return false;
}
示例6: setConfiguration
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public void setConfiguration(final Path file, final LoggingConfiguration configuration) throws BackgroundException {
// Logging target bucket
final Path bucket = containerService.getContainer(file);
try {
final S3BucketLoggingStatus status = new S3BucketLoggingStatus(
StringUtils.isNotBlank(configuration.getLoggingTarget()) ? configuration.getLoggingTarget() : bucket.getName(), null);
if(configuration.isEnabled()) {
status.setLogfilePrefix(PreferencesFactory.get().getProperty("s3.logging.prefix"));
}
session.getClient().setBucketLoggingStatus(bucket.getName(), status, true);
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, file);
}
}
示例7: setConfiguration
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public void setConfiguration(final Path file, final LifecycleConfiguration configuration) throws BackgroundException {
final Path container = containerService.getContainer(file);
try {
if(configuration.getTransition() != null || configuration.getExpiration() != null) {
final LifecycleConfig config = new LifecycleConfig();
// Unique identifier for the rule. The value cannot be longer than 255 characters. When you specify an empty prefix, the rule applies to all objects in the bucket
final LifecycleConfig.Rule rule = config.newRule(
String.format("%s-%s", PreferencesFactory.get().getProperty("application.name"), new AlphanumericRandomStringService().random()), StringUtils.EMPTY, true);
if(configuration.getTransition() != null) {
rule.newTransition().setDays(configuration.getTransition());
}
if(configuration.getExpiration() != null) {
rule.newExpiration().setDays(configuration.getExpiration());
}
session.getClient().setLifecycleConfig(container.getName(), config);
}
else {
session.getClient().deleteLifecycleConfig(container.getName());
}
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e, container);
}
}
示例8: write
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public void write(final Path file, final Distribution distribution, final LoginCallback prompt) throws BackgroundException {
final Path container = containerService.getContainer(file);
try {
if(distribution.isEnabled()) {
String suffix = "index.html";
if(StringUtils.isNotBlank(distribution.getIndexDocument())) {
suffix = PathNormalizer.name(distribution.getIndexDocument());
}
// Enable website endpoint
session.getClient().setWebsiteConfigImpl(container.getName(), new GSWebsiteConfig(suffix));
final DistributionLogging logging = this.getFeature(DistributionLogging.class, distribution.getMethod());
if(logging != null) {
new GoogleStorageLoggingFeature(session).setConfiguration(container, new LoggingConfiguration(
distribution.isEnabled(), distribution.getLoggingContainer()));
}
}
else {
// Disable website endpoint
session.getClient().setWebsiteConfigImpl(container.getName(), new GSWebsiteConfig());
}
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Cannot write website configuration", e);
}
}
示例9: create
import org.jets3t.service.ServiceException; //导入依赖的package包/类
public void create(final Path bucket, final String location) throws BackgroundException {
// Create bucket
if(!ServiceUtils.isBucketNameValidDNSName(bucket.getName())) {
throw new InteroperabilityException(LocaleFactory.localizedString("Bucket name is not DNS compatible", "S3"));
}
AccessControlList acl;
if(PreferencesFactory.get().getProperty("s3.bucket.acl.default").equals("public-read")) {
acl = GSAccessControlList.REST_CANNED_PUBLIC_READ;
}
else {
acl = GSAccessControlList.REST_CANNED_PRIVATE;
}
try {
session.getClient().createBucket(new S3PathContainerService().getContainer(bucket).getName(), location, acl);
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Cannot create folder {0}", e, bucket);
}
}
示例10: setConfiguration
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public void setConfiguration(final Path container, final LoggingConfiguration configuration) throws BackgroundException {
try {
// Logging target bucket
final GSBucketLoggingStatus status = new GSBucketLoggingStatus(
StringUtils.isNotBlank(configuration.getLoggingTarget()) ? configuration.getLoggingTarget() : container.getName(), null);
if(configuration.isEnabled()) {
status.setLogfilePrefix(PreferencesFactory.get().getProperty("google.logging.prefix"));
}
// Grant write for Google to logging target bucket
final AccessControlList acl = session.getClient().getBucketAcl(container.getName());
final GroupByEmailAddressGrantee grantee = new GroupByEmailAddressGrantee(
"[email protected]");
if(!acl.getPermissionsForGrantee(grantee).contains(Permission.PERMISSION_WRITE)) {
acl.grantPermission(grantee, Permission.PERMISSION_WRITE);
session.getClient().putBucketAcl(container.getName(), acl);
}
session.getClient().setBucketLoggingStatusImpl(container.getName(), status);
}
catch(ServiceException e) {
throw new S3ExceptionMappingService().map("Failure to write attributes of {0}", e);
}
}
示例11: retrieveMetadata
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public FileMetadata retrieveMetadata(String key) throws IOException {
StorageObject object = null;
try {
LOG.debug("Getting metadata for key: {} from bucket: {}",
key, bucket.getName());
object = s3Service.getObjectDetails(bucket.getName(), key);
return new FileMetadata(key, object.getContentLength(),
object.getLastModifiedDate().getTime());
} catch (ServiceException e) {
try {
// process
handleException(e, key);
return null;
} catch (FileNotFoundException fnfe) {
// and downgrade missing files
return null;
}
} finally {
if (object != null) {
object.closeDataInputStream();
}
}
}
示例12: retrieve
import org.jets3t.service.ServiceException; //导入依赖的package包/类
/**
*
* @param key
* The key is the object name that is being retrieved from the S3 bucket
* @return
* This method returns null if the key is not found
* @throws IOException
*/
@Override
public InputStream retrieve(String key, long byteRangeStart)
throws IOException {
try {
LOG.debug("Getting key: {} from bucket: {} with byteRangeStart: {}",
key, bucket.getName(), byteRangeStart);
S3Object object = s3Service.getObject(bucket, key, null, null, null,
null, byteRangeStart, null);
return object.getDataInputStream();
} catch (ServiceException e) {
handleException(e, key);
return null;
}
}
示例13: list
import org.jets3t.service.ServiceException; //导入依赖的package包/类
/**
* list objects
* @param prefix prefix
* @param delimiter delimiter
* @param maxListingLength max no. of entries
* @param priorLastKey last key in any previous search
* @return a list of matches
* @throws IOException on any reported failure
*/
private PartialListing list(String prefix, String delimiter,
int maxListingLength, String priorLastKey) throws IOException {
try {
if (!prefix.isEmpty() && !prefix.endsWith(PATH_DELIMITER)) {
prefix += PATH_DELIMITER;
}
StorageObjectsChunk chunk = s3Service.listObjectsChunked(bucket.getName(),
prefix, delimiter, maxListingLength, priorLastKey);
FileMetadata[] fileMetadata =
new FileMetadata[chunk.getObjects().length];
for (int i = 0; i < fileMetadata.length; i++) {
StorageObject object = chunk.getObjects()[i];
fileMetadata[i] = new FileMetadata(object.getKey(),
object.getContentLength(), object.getLastModifiedDate().getTime());
}
return new PartialListing(chunk.getPriorLastKey(), fileMetadata,
chunk.getCommonPrefixes());
} catch (ServiceException e) {
handleException(e, prefix);
return null; // never returned - keep compiler happy
}
}
示例14: copy
import org.jets3t.service.ServiceException; //导入依赖的package包/类
@Override
public void copy(String srcKey, String dstKey) throws IOException {
try {
if(LOG.isDebugEnabled()) {
LOG.debug("Copying srcKey: " + srcKey + "to dstKey: " + dstKey + "in bucket: " + bucket.getName());
}
if (multipartEnabled) {
S3Object object = s3Service.getObjectDetails(bucket, srcKey, null,
null, null, null);
if (multipartCopyBlockSize > 0 &&
object.getContentLength() > multipartCopyBlockSize) {
copyLargeFile(object, dstKey);
return;
}
}
S3Object dstObject = new S3Object(dstKey);
dstObject.setServerSideEncryptionAlgorithm(serverSideEncryptionAlgorithm);
s3Service.copyObject(bucket.getName(), srcKey, bucket.getName(),
dstObject, false);
} catch (ServiceException e) {
handleException(e, srcKey);
}
}
示例15: putAclImpl
import org.jets3t.service.ServiceException; //导入依赖的package包/类
protected void putAclImpl(String bucketName, String objectKey, AccessControlList acl,
String versionId) throws ServiceException
{
if (log.isDebugEnabled()) {
log.debug("Setting 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);
}
Map<String, Object> metadata = new HashMap<String, Object>();
metadata.put("Content-Type", "text/plain");
try {
String aclAsXml = acl.toXml();
metadata.put("Content-Length", String.valueOf(aclAsXml.length()));
performRestPut(bucketName, objectKey, metadata, requestParameters,
new StringEntity(aclAsXml, "text/plain", Constants.DEFAULT_ENCODING),
true);
} catch (UnsupportedEncodingException e) {
throw new ServiceException("Unable to encode ACL XML document", e);
}
}