@Override protected InputStream openObject(String key, OpenOptions options) throws IOException { try { return new GCSInputStream(mBucketName, key, mClient, options.getOffset()); } catch (ServiceException e) { throw new IOException(e.getMessage()); } } }
private void handleServiceException(ServiceException e) throws IOException { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } else { if(LOG.isDebugEnabled()) { LOG.debug("Got ServiceException with Error code: " + e.getErrorCode() + ";and Error message: " + e.getErrorMessage()); } } }
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 static boolean isServiceExceptionRecoverable(ServiceException ex) { final boolean isIOException = ex.getCause() instanceof IOException; final boolean isTimeout = "RequestTimeout".equals(((ServiceException) ex).getErrorCode()); return isIOException || isTimeout; }
/** * Wrap a ServiceException as an S3ServiceException. * @param se */ public S3ServiceException(ServiceException se) { super(se.getMessage(), se.getXmlMessage(), se.getCause()); this.setResponseHeaders(se.getResponseHeaders()); this.setResponseCode(se.getResponseCode()); this.setResponseStatus(se.getResponseStatus()); this.setResponseDate(se.getResponseDate()); this.setRequestVerb(se.getRequestVerb()); this.setRequestPath(se.getRequestPath()); this.setRequestHost(se.getRequestHost()); }
exception = new ServiceException("Service Error Message.", sb.toString()); } else { if(log.isDebugEnabled()) { exception = new ServiceException( "Request Error" + (responseText != null ? " [" + responseText + "]." : "."), httpException); exception.setResponseCode(responseCode); exception.setResponseHeaders(RestUtils.convertHeadersToMap(response.getAllHeaders())); else if("RequestTimeout".equals(exception.getErrorCode())) { if(requestTimeoutErrorCount >= retryMaxCount) { throw exception; else if("RequestTimeTooSkewed".equals(exception.getErrorCode())) { if(requestTimeTooSkewedErrorCount >= retryMaxCount) { throw exception; && "NoSuchKey".equals(exception.getErrorCode()) else if ("InvalidRequest".equals(exception.getErrorCode()) && exception.getErrorMessage().contains("Please use AWS4-HMAC-SHA256")) else if("AuthorizationHeaderMalformed".equals(exception.getErrorCode())) { String expectedRegion = null; try { expectedRegion = exception.getXmlMessageAsBuilder() .xpathFind("/Error/Region").getElement().getTextContent();
@Override public BackgroundException map(final ServiceException e) { if(e.getCause() instanceof ServiceException) { return this.map((ServiceException) e.getCause()); if(StringUtils.isNotBlank(e.getErrorMessage())) { this.append(buffer, StringEscapeUtils.unescapeXml(e.getErrorMessage())); this.append(buffer, e.getResponseStatus()); this.append(buffer, e.getMessage()); switch(e.getResponseCode()) { case HttpStatus.SC_FORBIDDEN: if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "SignatureDoesNotMatch": case "InvalidAccessKeyId": if(StringUtils.isNotBlank(e.getErrorCode())) { switch(e.getErrorCode()) { case "RequestTimeout": return new ConnectionTimeoutException(buffer.toString(), e); if(e.getCause() instanceof IOException) { return new DefaultIOExceptionMappingService().map((IOException) e.getCause()); if(e.getCause() instanceof SAXException) { return new InteroperabilityException(buffer.toString(), e);
/** * 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); } }
public static boolean isObjectInBucket(RestS3Service s3Client, String bucketName, String objectKey) throws ServiceException { try { s3Client.getObjectDetails(bucketName, objectKey); } catch (ServiceException e) { if (404 == e.getResponseCode() || "NoSuchKey".equals(e.getErrorCode()) || "NoSuchBucket".equals(e.getErrorCode())) { return false; } if ("AccessDenied".equals(e.getErrorCode())) { // Object is inaccessible to current user, but does exist. return true; } // Something else has gone wrong throw e; } return true; }
ioErrorRetryCount = 0; } catch (ServiceException e) { if (e.getCause() instanceof IOException && ioErrorRetryCount < ioErrorRetryMaxCount) throw new ServiceException("Unable to retrieve paginated " + "ListMultipartUploadsResult without valid NextKeyMarker " + " or NextUploadIdMarker value.");
@Override public InputStream openStream() throws IOException { try { return buildFileObject(uri, s3Client).openInputStream(); } catch (ServiceException e) { if (e.getCause() != null) { if (S3Utils.S3RETRY.apply(e)) { throw new IOException("Recoverable exception", e); } } throw Throwables.propagate(e); } } };
final ServiceException failure = new ServiceException(); failure.setErrorCode(error.getErrorCode()); failure.setErrorMessage(error.getMessage()); throw new S3ExceptionMappingService().map("Cannot delete {0}", failure, new Path(container, error.getKey(), EnumSet.of(Path.Type.file))); final ServiceException failure = new ServiceException(); failure.setErrorCode(error.getErrorCode()); failure.setErrorMessage(error.getMessage()); throw new S3ExceptionMappingService().map("Cannot delete {0}", failure, new Path(container, error.getKey(), EnumSet.of(Path.Type.file)));
/** * Create a service exception that includes a specific message, an optional XML error * document returned by service, and an optional underlying cause exception. * * @param message * @param xmlMessage * @param cause */ public ServiceException(String message, String xmlMessage, Throwable cause) { super(message, cause); if (xmlMessage != null) { parseXmlMessage(xmlMessage); } MxDelegate.getInstance().registerS3ServiceExceptionEvent(getErrorCode()); }
if(null != e.getResponseHeaders()) { if(e.getResponseHeaders().containsKey(AMZ_DELETE_MARKER)) { final S3Object marker = new S3Object(); marker.addMetadata(S3_VERSION_ID, e.getResponseHeaders().get(AMZ_VERSION_ID)); return marker; log.warn(String.format("Missing permission to read object details for %s %s", file, e.getMessage())); final StorageObject object = new StorageObject(containerService.getKey(file)); object.setBucketName(container);
throw new IOException(e.getErrorMessage(), new S3ExceptionMappingService().map(e));
if(e.getResponseCode() == 403) { if(log.isDebugEnabled()) { log.debug("Bucket named '" + bucketName + "' exists but is inaccessible, " else if(e.getResponseCode() == 404) { if(log.isDebugEnabled()) { log.debug("Bucket does not exist: " + bucketName, e);
ServiceException se = (ServiceException) thrown; LOG.debug("S3ServiceException: {}: {} : {}", se.getErrorCode(), se.toString(), se, se); result = new S3Exception(se); } else if (thrown instanceof IOException) {
System.out.println("Bucket [" + bucketName + "] deleted"); } catch (ServiceException e) { e.printStackTrace();
/** * Wrap a ServiceException as an S3ServiceException. * @param se */ public S3ServiceException(ServiceException se) { super(se.getMessage(), se.getXmlMessage(), se.getCause()); this.setResponseHeaders(se.getResponseHeaders()); this.setResponseCode(se.getResponseCode()); this.setResponseStatus(se.getResponseStatus()); this.setResponseDate(se.getResponseDate()); this.setRequestVerb(se.getRequestVerb()); this.setRequestPath(se.getRequestPath()); this.setRequestHost(se.getRequestHost()); }
exception = new ServiceException("Service Error Message.", sb.toString()); } else { if(log.isDebugEnabled()) { exception = new ServiceException( "Request Error" + (responseText != null ? " [" + responseText + "]." : "."), httpException); exception.setResponseCode(responseCode); exception.setResponseHeaders(RestUtils.convertHeadersToMap(response.getAllHeaders())); else if("RequestTimeout".equals(exception.getErrorCode())) { if(requestTimeoutErrorCount >= retryMaxCount) { throw exception; else if("RequestTimeTooSkewed".equals(exception.getErrorCode())) { if(requestTimeTooSkewedErrorCount >= retryMaxCount) { throw exception; && "NoSuchKey".equals(exception.getErrorCode()) else if ("InvalidRequest".equals(exception.getErrorCode()) && exception.getErrorMessage().contains("Please use AWS4-HMAC-SHA256")) else if("AuthorizationHeaderMalformed".equals(exception.getErrorCode())) { String expectedRegion = null; try { expectedRegion = exception.getXmlMessageAsBuilder() .xpathFind("/Error/Region").getElement().getTextContent();