Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions javav2/example_code/s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,68 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>S3J2Project</groupId>
<artifactId>S3J2Project</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>21</java.version>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>21</release>
</configuration>
<!-- The following execution section processes the plugin annotations for apache logging for the custom memory appender, MemoryLog4jAppender, used in the test for ParseUri.java -->

<!-- Processes Log4j plugin annotations for custom MemoryLog4jAppender -->
<executions>
<execution>
<id>log4j-plugin-processor</id>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<proc>only</proc>
<annotationProcessors>
<annotationProcessor>org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor</annotationProcessor>
<annotationProcessor>
org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor
</annotationProcessor>
</annotationProcessors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.31.8</version>
<version>2.35.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -68,26 +77,25 @@
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.4</version>
<scope>test</scope>
</dependency>

<!-- AWS SDK v2 -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>cloudformation</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
<version>0.29.25</version>
<version>0.38.13</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
Expand Down Expand Up @@ -161,15 +169,12 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>ec2</artifactId>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
Expand All @@ -178,6 +183,13 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.13</version>
</dependency>

<!-- Utility Libraries -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand All @@ -188,5 +200,10 @@
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.transfer.s3.S3TransferManager;
import software.amazon.awssdk.transfer.s3.model.CompletedFileDownload;
Expand All @@ -18,6 +19,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;
Expand Down Expand Up @@ -127,20 +129,25 @@ private void setUp() {
}

public void cleanUp() {
S3ClientFactory.s3Client.deleteObject(b -> b.bucket(bucketName).key(key));
S3ClientFactory.s3Client.deleteBucket(b -> b.bucket(bucketName));
URL url = DownloadFile.class.getClassLoader().getResource(downloadedFileName);
if (url != null) {
try {
Files.delete(Paths.get(url.toURI().getPath()));
System.out.println("File deleted successfully");
} catch (URISyntaxException e) {
System.err.println("Error converting URL to URI: " + e.getMessage());
} catch (IOException e) {
System.err.println("Error deleting file " + e.getMessage());
try {
S3ClientFactory.s3Client.deleteObject(b -> b.bucket(bucketName).key(key));
S3ClientFactory.s3Client.deleteBucket(b -> b.bucket(bucketName));

// Directly use the downloadedFileWithPath
if (downloadedFileWithPath != null && !downloadedFileWithPath.isEmpty()) {
Path filePath = Paths.get(downloadedFileWithPath);
try {
Files.deleteIfExists(filePath);
System.out.println("File deleted successfully");
} catch (NoSuchFileException e) {
System.err.println("The file wasn't found: " + e.getMessage());
} catch (IOException e) {
System.err.println("Error deleting file: " + e.getMessage());
}
}
} else {
System.err.println("The file wasn't found");
} catch (SdkException e) {
System.err.println("S3 operation failed: " + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
x-49267f42-03d5-49ee-bfea-0cfab75f76a8,object-key-1.txt
x-49267f42-03d5-49ee-bfea-0cfab75f76a8,object-key-2.txt
x-49267f42-03d5-49ee-bfea-0cfab75f76a8,object-key-3.txt
x-49267f42-03d5-49ee-bfea-0cfab75f76a8,object-key-4.txt
x-e7f53ef2-703e-4822-9176-54a9ad64bce9,object-key-1.txt
x-e7f53ef2-703e-4822-9176-54a9ad64bce9,object-key-2.txt
x-e7f53ef2-703e-4822-9176-54a9ad64bce9,object-key-3.txt
x-e7f53ef2-703e-4822-9176-54a9ad64bce9,object-key-4.txt
Loading