I am looking to develop a Singletone AmazonS3Client that serves my application to upload files to Amazon S3 server. however, I couldn't find how to check if the connection is active and able to upload buckets or not.
are there specific Exception that would be thrown if the connection dropped? or does the connection get dropped after certain period of time?
any answer would help.
here is snippet of my code:
private static final AmazonS3Client s3Client;
static {
AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
s3Client = new AmazonS3Client(awsCredentials);
}
private static boolean writeFile(AmazonS3Client s3Client, String fileName, File file, Boolean publicRead){
try {
PutObjectRequest p = new PutObjectRequest(bucketName, fileName, file);
if (publicRead)
p.setCannedAcl(CannedAccessControlList.PublicRead);
s3Client.putObject(p);
System.out.println("URL: " + S3_BASE_URL + fileName);
return true;
} catch (AmazonServiceException ase){
ase.printStackTrace();
} catch (AmazonClientException ace) {
ace.printStackTrace();
} catch (Exception ex){
ex.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}
catch (Exception ex){ ex.printStackTrace(); }
as you do the same thing in all cases and it will catch all other exceptions as they inherit fromException
– Morgan