1
|
package eu.dnetlib.data.objectStore.S3;
|
2
|
|
3
|
import com.amazonaws.ClientConfiguration;
|
4
|
import com.amazonaws.Protocol;
|
5
|
import com.amazonaws.auth.AWSCredentials;
|
6
|
import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
7
|
import com.amazonaws.auth.BasicAWSCredentials;
|
8
|
import com.amazonaws.client.builder.AwsClientBuilder;
|
9
|
import com.amazonaws.services.s3.AmazonS3;
|
10
|
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
11
|
import com.amazonaws.services.s3.model.*;
|
12
|
import org.junit.Ignore;
|
13
|
import org.junit.Test;
|
14
|
|
15
|
import java.util.List;
|
16
|
|
17
|
public class S3ObjectStoreTest {
|
18
|
|
19
|
|
20
|
private static final String S3_REGION = "eu-west-3";
|
21
|
|
22
|
|
23
|
@Ignore
|
24
|
public void testConnection() {
|
25
|
|
26
|
|
27
|
String s3AccessKey = "API";
|
28
|
String s3SecretKey = "SECRET";
|
29
|
String s3EndPoint = "s3.icm.edu.pl";
|
30
|
final AWSCredentials credentials = new BasicAWSCredentials(s3AccessKey, s3SecretKey);
|
31
|
final ClientConfiguration cfg = new ClientConfiguration().withProtocol(Protocol.HTTPS);
|
32
|
|
33
|
final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials))
|
34
|
.withClientConfiguration(cfg)
|
35
|
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3EndPoint, S3_REGION))
|
36
|
.build();
|
37
|
|
38
|
ListBucketsRequest listBucketsRequest = new ListBucketsRequest();
|
39
|
List<Bucket> buckets = s3.listBuckets(listBucketsRequest);
|
40
|
buckets.stream().forEach(x -> System.out.println(x.getName()));
|
41
|
|
42
|
|
43
|
S3Object object = s3.getObject("openaire-mdstore-beta", "fe6b7e2f-273e-4222-a72a-9d3159326318_T2JqZWN0U3RvcmVEU1Jlc291cmNlcy9PYmplY3RTdG9yZURTUmVzb3VyY2VUeXBl/shareLawArXv::ff18bafffc8ff53da0eb07960b32a9dd::bc6bfd352c354ed64b276f1ae5995041");
|
44
|
System.out.println(object.getObjectMetadata().getETag());
|
45
|
|
46
|
System.out.println(object.getObjectMetadata().getContentLength());
|
47
|
|
48
|
|
49
|
// ObjectMetadata objectMetadata = s3.getObjectMetadata("openaire-mdstore-beta", "fe6b7e2f-273e-4222-a72a-9d3159326318_T2JqZWN0U3RvcmVEU1Jlc291cmNlcy9PYmplY3RTdG9yZURTUmVzb3VyY2VUeXBl/shareLawArXv::ff18bafffc8ff53da0eb07960b32a9dd::bc6bfd352c354ed64b276f1ae5995041");
|
50
|
//
|
51
|
// System.out.println(objectMetadata.getContentMD5());
|
52
|
|
53
|
|
54
|
|
55
|
|
56
|
}
|
57
|
}
|