ceph官网中使用java访问rgw s3的代码已经不能使用了,
http://docs.ceph.com/docs/kraken/radosgw/s3/java/
折腾了好长时间,在同事的帮助下终于实现了使用java调用rgw s3接口,代码如下:
public static void main(String[] args) {
String accessKey = "your accessKey";
String secretKey = "your secretKey";
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withEndpointConfiguration(
new AwsClientBuilder.EndpointConfiguration(
"your ceph rgw site,like: http://10.0.0.12:8080",
""))
.build();
List<Bucket> listBuckets = amazonS3.listBuckets();
for (Bucket bucket : listBuckets) {
System.out.println(bucket.getName());
}
}
使用过程中需要引入很多包,如有需要可以联系本人。