From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- .../main/java/org/example/cephs3upload/App.java | 51 ++++++++++++++++++++++ .../java/org/example/cephs3upload/AppTest.java | 38 ++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 examples/rgw/java/ceph-s3-upload/src/main/java/org/example/cephs3upload/App.java create mode 100644 examples/rgw/java/ceph-s3-upload/src/test/java/org/example/cephs3upload/AppTest.java (limited to 'examples/rgw/java/ceph-s3-upload/src') diff --git a/examples/rgw/java/ceph-s3-upload/src/main/java/org/example/cephs3upload/App.java b/examples/rgw/java/ceph-s3-upload/src/main/java/org/example/cephs3upload/App.java new file mode 100644 index 000000000..32f334cfb --- /dev/null +++ b/examples/rgw/java/ceph-s3-upload/src/main/java/org/example/cephs3upload/App.java @@ -0,0 +1,51 @@ +package org.example.cephs3upload; + +import com.amazonaws.services.s3.model.AmazonS3Exception; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; + +import java.io.File; +import java.nio.file.Paths; + +public class App +{ + public static void main( String[] args ) + { + final String USAGE = "\n" + + "To run this example, supply the name of an S3 bucket and a file to\n" + + "upload to it.\n" + + "\n" + + "Ex: java -jar target/ceph-s3-upload-1.0-SNAPSHOT-jar-with-dependencies.jar \n"; + + if (args.length < 2) { + System.out.println(USAGE); + System.exit(1); + } + + String bucket_name = args[0]; + String file_path = args[1]; + String key_name = Paths.get(file_path).getFileName().toString(); + + System.out.format("Uploading %s to S3 bucket %s...\n", file_path, bucket_name); + // Put in the CEPH RGW access and secret keys here in that order "access key" "secret key" + // Must also be specified here + BasicAWSCredentials credentials = new BasicAWSCredentials("0555b35654ad1656d804","h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q=="); + // Note That the AWSClient builder takes in the endpoint and the region + // This has to be specified in this file + final AmazonS3 s3 = AmazonS3ClientBuilder + .standard() + .withCredentials(new AWSStaticCredentialsProvider(credentials)) + .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://127.0.0.1:8000", "default")) + .build(); + try { + s3.putObject(bucket_name, key_name, new File(file_path)); + } catch (AmazonS3Exception e) { + System.err.println(e.getMessage()); // raises more explicit error message than e.getErrorMessage() e.g when Bucket is not available + System.exit(1); + } + System.out.println("Object upload successful!"); + } +} diff --git a/examples/rgw/java/ceph-s3-upload/src/test/java/org/example/cephs3upload/AppTest.java b/examples/rgw/java/ceph-s3-upload/src/test/java/org/example/cephs3upload/AppTest.java new file mode 100644 index 000000000..1c8075253 --- /dev/null +++ b/examples/rgw/java/ceph-s3-upload/src/test/java/org/example/cephs3upload/AppTest.java @@ -0,0 +1,38 @@ +package org.example.cephs3upload; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} -- cgit v1.2.3