Developer
Search…
🧩Examples

Sample application - List buckets

This simple app that contains a sample application that lists your buckets.
/app/build.gradle
/app/src/main/java/tech/storewise/sample/App.java /
1
plugins {
2
id 'java'
3
id 'application'
4
}
5
6
repositories {
7
jcenter()
8
}
9
10
dependencies {
11
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.779')
12
implementation 'com.amazonaws:aws-java-sdk-s3:1.11.779'
13
implementation 'ch.qos.logback:logback-classic:1.2.3'
14
implementation project(path: ':sdk')
15
}
16
17
application {
18
mainClassName = 'tech.storewise.sample.App'
19
}
Copied!
1
package tech.storewise.sample;
2
3
import com.amazonaws.services.s3.AmazonS3;
4
import com.amazonaws.services.s3.model.Bucket;
5
import java.io.IOException;
6
import java.nio.file.Path;
7
import java.nio.file.Paths;
8
import tech.storewise.sdk.Gateway;
9
10
/**
11
* Sample application that initializes the SDK and retrieves buckets.
12
*
13
* <p>It requires to set these two environment variables:
14
*
15
* <ul>
16
* <li>STOREWISE_USER: StoreWise username
17
* <li>STOREWISE_PASSWORD: the password for the above user
18
* </ul>
19
*
20
* <p>Visit https://console.staging.storewise.tech/ to obtain your username and password.
21
*/
22
public class App {
23
/** Path to the directory where metadata files are stored in. */
24
private static final Path METADATA_DIR = Paths.get("~/.config/storewise/java-sdk");
25
26
public static void main(String[] args) {
27
try {
28
final AmazonS3 cli =
29
Gateway.start(
30
METADATA_DIR,
31
System.getenv("STOREWISE_USER"),
32
System.getenv("STOREWISE_PASSWORD"));
33
for (final Bucket b : cli.listBuckets()) {
34
System.out.println(b.getName());
35
}
36
} catch (IOException | InterruptedException e) {
37
e.printStackTrace();
38
} finally {
39
try {
40
Gateway.close();
41
} catch (InterruptedException | IOException e) {
42
e.printStackTrace();
43
}
44
}
45
}
46
}
Copied!
Last modified 1yr ago
Copy link