@Override public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest) { this.getObjectMetadataRequest = getObjectMetadataRequest; if (getObjectMetadataHttpCode != SC_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode); exception.setStatusCode(getObjectMetadataHttpCode); throw exception; } return null; }
@Override public S3Object getObject(GetObjectRequest getObjectRequest) { if (getObjectHttpCode != SC_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObject call with " + getObjectHttpCode); exception.setStatusCode(getObjectHttpCode); throw exception; } return null; }
/** * Creates a new AmazonS3Exception object with the values set. */ public AmazonS3Exception build() { AmazonS3Exception s3Exception = errorResponseXml == null ? new AmazonS3Exception( errorMessage) : new AmazonS3Exception(errorMessage, errorResponseXml); s3Exception.setErrorCode(errorCode); s3Exception.setExtendedRequestId(extendedRequestId); s3Exception.setStatusCode(statusCode); s3Exception.setRequestId(requestId); s3Exception.setCloudFrontId(cloudFrontId); s3Exception.setAdditionalDetails(additionalDetails); s3Exception.setErrorType(errorTypeOf(statusCode)); return s3Exception; }
ase.setExtendedRequestId(hostId); ase.setServiceName(request.getServiceName()); ase.setStatusCode(200);
/** * Used to create an {@link AmazonS3Exception} when we failed to read the * error response or parsed the error response as XML. */ private AmazonS3Exception newAmazonS3Exception(String errmsg, HttpResponse httpResponse) { final AmazonS3Exception ase = new AmazonS3Exception(errmsg); final int statusCode = httpResponse.getStatusCode(); ase.setErrorCode(statusCode + " " + httpResponse.getStatusText()); ase.setStatusCode(statusCode); ase.setErrorType(errorTypeOf(statusCode)); final Map<String, String> headers = httpResponse.getHeaders(); ase.setRequestId(headers.get(Headers.REQUEST_ID)); ase.setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID)); ase.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID)); final Map<String, String> additionalDetails = new HashMap<String, String>(); additionalDetails.put(Headers.S3_BUCKET_REGION, headers.get(Headers.S3_BUCKET_REGION)); ase.setAdditionalDetails(additionalDetails); return ase; }
ase.setExtendedRequestId(hostId); ase.setServiceName(request.getServiceName()); ase.setStatusCode(200);
final AmazonS3Exception ase = new AmazonS3Exception(message); final int statusCode = errorResponse.getStatusCode(); ase.setStatusCode(statusCode); ase.setErrorType(errorTypeOf(statusCode)); ase.setErrorCode(errorCode);
@Override public S3Object getObject(String bucketName, String key) { File file = getFile(bucketName, key); if (file.isFile()) { return new OfflineS3Object(bucketName, key, file); } else { AmazonS3Exception amazonS3Exception = new AmazonS3Exception("Object does not exist."); amazonS3Exception.setStatusCode(404); throw amazonS3Exception; } }
@Override public S3Object getObject(GetObjectRequest getObjectRequest) { if (getObjectHttpCode != SC_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObject call with " + getObjectHttpCode); exception.setStatusCode(getObjectHttpCode); throw exception; } return null; }
@Override public ObjectMetadata getObjectMetadata(String bucketName, String key) throws AmazonClientException { if (getObjectMetadataHttpCode != SC_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode); exception.setStatusCode(getObjectMetadataHttpCode); throw exception; } return null; }
@Override public S3Object getObject(GetObjectRequest getObjectRequest) { if (getObjectHttpCode != HTTP_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObject call with " + getObjectHttpCode); exception.setStatusCode(getObjectHttpCode); throw exception; } return null; }
@Override public S3Object getObject(GetObjectRequest getObjectRequest) throws AmazonClientException { if (getObjectHttpCode != SC_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObject call with " + getObjectHttpCode); exception.setStatusCode(getObjectHttpCode); throw exception; } return null; }
@Override public S3Object getObject(GetObjectRequest getObjectRequest) { if (getObjectHttpCode != HTTP_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObject call with " + getObjectHttpCode); exception.setStatusCode(getObjectHttpCode); throw exception; } return null; }
@Override public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest) { this.getObjectMetadataRequest = getObjectMetadataRequest; if (getObjectMetadataHttpCode != SC_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode); exception.setStatusCode(getObjectMetadataHttpCode); throw exception; } return null; }
@Override public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest) { this.getObjectMetadataRequest = getObjectMetadataRequest; if (getObjectMetadataHttpCode != HTTP_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode); exception.setStatusCode(getObjectMetadataHttpCode); throw exception; } return null; }
@Override public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest) { this.getObjectMetadataRequest = getObjectMetadataRequest; if (getObjectMetadataHttpCode != HTTP_OK) { AmazonS3Exception exception = new AmazonS3Exception("Failing getObjectMetadata call with " + getObjectMetadataHttpCode); exception.setStatusCode(getObjectMetadataHttpCode); throw exception; } return null; }
@Test public void testFetchOffsetNewTopic() throws Exception { AmazonS3 s3Mock = mock(AmazonS3.class); S3Writer s3Writer = new S3Writer(testBucket, "pfx", s3Mock); // Non existing topic should return 0 offset // Since the file won't exist. code will expect the initial fetch to 404 AmazonS3Exception ase = new AmazonS3Exception("The specified key does not exist."); ase.setStatusCode(404); when(s3Mock.getObject(eq(testBucket), eq("pfx/last_chunk_index.new_topic-00000.txt"))) .thenThrow(ase) .thenReturn(null); TopicPartition tp = new TopicPartition("new_topic", 0); long offset = s3Writer.fetchOffset(tp); assertEquals(0, offset); verify(s3Mock).getObject(eq(testBucket), eq("pfx/last_chunk_index.new_topic-00000.txt")); }
ase.setExtendedRequestId(hostId); ase.setServiceName(request.getServiceName()); ase.setStatusCode(200);
ase.setExtendedRequestId(hostId); ase.setServiceName(request.getServiceName()); ase.setStatusCode(200);
/** * Creates a new AmazonS3Exception object with the values set. */ public AmazonS3Exception build() { AmazonS3Exception s3Exception = errorResponseXml == null ? new AmazonS3Exception( errorMessage) : new AmazonS3Exception(errorMessage, errorResponseXml); s3Exception.setErrorCode(errorCode); s3Exception.setExtendedRequestId(extendedRequestId); s3Exception.setStatusCode(statusCode); s3Exception.setRequestId(requestId); s3Exception.setCloudFrontId(cloudFrontId); s3Exception.setAdditionalDetails(additionalDetails); s3Exception.setErrorType(errorTypeOf(statusCode)); return s3Exception; }