Sample Java Code for using Content Gateway's S3 Interface

caringos3samples.zip

The zipped file referenced above contains everything you need to build Java source code samples that use the AWS Java SDK to list, upload (including S3 multipart), and download objects in a Swarm cluster. This requires a Content Gateway with the S3 port enabled.

First configure and test s3cmd [https://caringo.atlassian.net/servicedesk/customer/portal/1?q=using+the+s3cmd], to verify your access / secret keys are valid and that url resolution of your domain works. Your DNS must map your domain to your Content Gateway or https proxy.

Then just set the same endpoint, access key, and secret key environment variables when running maven to build and run a sample:

S3_ENDPOINT="http://backup42.docker.tx.caringo.com:4285"

S3_ACCESS_KEY=a33898e802a42d5e099536b8a9727a3d

S3_SECRET_KEY=secret

mvn compile exec:java

You can change the mainClass in pom.xml to run S3Sample, LowLevel_LargeObjectCopy, or gui S3TransferProgressSample. TODO: some configuration code needs to be updated to use non-deprecated methods.

These sample programs came from the AWS SDK or documentation. Really the only change needed to use a Swarm domain instead of AWS S3 is the addition of the line:

s3.setEndpoint("https://mydomain.example.com");

You might also have to set S3ClientOptions.setPathStyleAccess(true) to avoid certificate validation failures. This forces requests to be made to https://mydomain.example.com/mybucket instead of https://mybucket.mydomain.example.com/.

Some samples allow configuration of other options, such as connection timeouts or whether V4 signatures are used (tip: V4 is slower than V2).

The pom.xml specifies the latest 1.11.122 SDK but it should work as far back as 1.9

© DataCore Software Corporation. · https://www.datacore.com · All rights reserved.