Skip to content

Commit cd15722

Browse files
committed
updated POM file for S3
1 parent ddf26d2 commit cd15722

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed
421 KB
Binary file not shown.

javav2/example_code/s3/pom.xml

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,68 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6+
67
<groupId>S3J2Project</groupId>
78
<artifactId>S3J2Project</artifactId>
89
<version>1.0-SNAPSHOT</version>
10+
911
<properties>
1012
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1113
<java.version>21</java.version>
1214
<maven.compiler.target>21</maven.compiler.target>
1315
<maven.compiler.source>21</maven.compiler.source>
1416
</properties>
17+
1518
<build>
1619
<plugins>
1720
<plugin>
1821
<groupId>org.apache.maven.plugins</groupId>
1922
<artifactId>maven-surefire-plugin</artifactId>
2023
<version>3.5.2</version>
2124
</plugin>
25+
2226
<plugin>
2327
<groupId>org.apache.maven.plugins</groupId>
2428
<artifactId>maven-resources-plugin</artifactId>
2529
<version>3.3.1</version>
2630
</plugin>
31+
2732
<plugin>
2833
<groupId>org.apache.maven.plugins</groupId>
2934
<artifactId>maven-compiler-plugin</artifactId>
3035
<version>3.11.0</version>
3136
<configuration>
3237
<release>21</release>
3338
</configuration>
34-
<!-- The following execution section processes the plugin annotations for apache logging for the custom memory appender, MemoryLog4jAppender, used in the test for ParseUri.java -->
39+
40+
<!-- Processes Log4j plugin annotations for custom MemoryLog4jAppender -->
3541
<executions>
3642
<execution>
3743
<id>log4j-plugin-processor</id>
44+
<phase>process-classes</phase>
3845
<goals>
3946
<goal>compile</goal>
4047
</goals>
41-
<phase>process-classes</phase>
4248
<configuration>
4349
<proc>only</proc>
4450
<annotationProcessors>
45-
<annotationProcessor>org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor</annotationProcessor>
51+
<annotationProcessor>
52+
org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor
53+
</annotationProcessor>
4654
</annotationProcessors>
4755
</configuration>
4856
</execution>
4957
</executions>
5058
</plugin>
5159
</plugins>
5260
</build>
61+
5362
<dependencyManagement>
5463
<dependencies>
5564
<dependency>
5665
<groupId>software.amazon.awssdk</groupId>
5766
<artifactId>bom</artifactId>
58-
<version>2.31.8</version>
67+
<version>2.35.5</version>
5968
<type>pom</type>
6069
<scope>import</scope>
6170
</dependency>
@@ -68,26 +77,25 @@
6877
</dependency>
6978
</dependencies>
7079
</dependencyManagement>
80+
7181
<dependencies>
82+
<!-- Testing -->
7283
<dependency>
7384
<groupId>org.junit.jupiter</groupId>
7485
<artifactId>junit-jupiter</artifactId>
7586
<version>5.11.4</version>
7687
<scope>test</scope>
7788
</dependency>
89+
90+
<!-- AWS SDK v2 -->
7891
<dependency>
7992
<groupId>software.amazon.awssdk</groupId>
8093
<artifactId>cloudformation</artifactId>
8194
</dependency>
82-
<dependency>
83-
<groupId>com.fasterxml.jackson.core</groupId>
84-
<artifactId>jackson-databind</artifactId>
85-
<version>2.14.2</version>
86-
</dependency>
8795
<dependency>
8896
<groupId>software.amazon.awssdk.crt</groupId>
8997
<artifactId>aws-crt</artifactId>
90-
<version>0.29.25</version>
98+
<version>0.38.13</version>
9199
</dependency>
92100
<dependency>
93101
<groupId>software.amazon.awssdk</groupId>
@@ -161,15 +169,12 @@
161169
<groupId>software.amazon.awssdk</groupId>
162170
<artifactId>ec2</artifactId>
163171
</dependency>
172+
173+
<!-- Logging -->
164174
<dependency>
165175
<groupId>org.apache.logging.log4j</groupId>
166176
<artifactId>log4j-core</artifactId>
167177
</dependency>
168-
<dependency>
169-
<groupId>org.slf4j</groupId>
170-
<artifactId>slf4j-api</artifactId>
171-
<version>2.0.13</version>
172-
</dependency>
173178
<dependency>
174179
<groupId>org.apache.logging.log4j</groupId>
175180
<artifactId>log4j-slf4j2-impl</artifactId>
@@ -178,6 +183,13 @@
178183
<groupId>org.apache.logging.log4j</groupId>
179184
<artifactId>log4j-1.2-api</artifactId>
180185
</dependency>
186+
<dependency>
187+
<groupId>org.slf4j</groupId>
188+
<artifactId>slf4j-api</artifactId>
189+
<version>2.0.13</version>
190+
</dependency>
191+
192+
<!-- Utility Libraries -->
181193
<dependency>
182194
<groupId>org.apache.commons</groupId>
183195
<artifactId>commons-lang3</artifactId>
@@ -188,5 +200,10 @@
188200
<artifactId>gson</artifactId>
189201
<version>2.10.1</version>
190202
</dependency>
203+
<dependency>
204+
<groupId>com.fasterxml.jackson.core</groupId>
205+
<artifactId>jackson-databind</artifactId>
206+
<version>2.14.2</version>
207+
</dependency>
191208
</dependencies>
192-
</project>
209+
</project>

javav2/example_code/s3/src/main/java/com/example/s3/transfermanager/DownloadFile.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
10+
import software.amazon.awssdk.core.exception.SdkException;
1011
import software.amazon.awssdk.core.sync.RequestBody;
1112
import software.amazon.awssdk.transfer.s3.S3TransferManager;
1213
import software.amazon.awssdk.transfer.s3.model.CompletedFileDownload;
@@ -18,6 +19,7 @@
1819
import java.net.URISyntaxException;
1920
import java.net.URL;
2021
import java.nio.file.Files;
22+
import java.nio.file.NoSuchFileException;
2123
import java.nio.file.Path;
2224
import java.nio.file.Paths;
2325
import java.util.UUID;
@@ -127,20 +129,25 @@ private void setUp() {
127129
}
128130

129131
public void cleanUp() {
130-
S3ClientFactory.s3Client.deleteObject(b -> b.bucket(bucketName).key(key));
131-
S3ClientFactory.s3Client.deleteBucket(b -> b.bucket(bucketName));
132-
URL url = DownloadFile.class.getClassLoader().getResource(downloadedFileName);
133-
if (url != null) {
134-
try {
135-
Files.delete(Paths.get(url.toURI().getPath()));
136-
System.out.println("File deleted successfully");
137-
} catch (URISyntaxException e) {
138-
System.err.println("Error converting URL to URI: " + e.getMessage());
139-
} catch (IOException e) {
140-
System.err.println("Error deleting file " + e.getMessage());
132+
try {
133+
S3ClientFactory.s3Client.deleteObject(b -> b.bucket(bucketName).key(key));
134+
S3ClientFactory.s3Client.deleteBucket(b -> b.bucket(bucketName));
135+
136+
// Directly use the downloadedFileWithPath
137+
if (downloadedFileWithPath != null && !downloadedFileWithPath.isEmpty()) {
138+
Path filePath = Paths.get(downloadedFileWithPath);
139+
try {
140+
Files.deleteIfExists(filePath);
141+
System.out.println("File deleted successfully");
142+
} catch (NoSuchFileException e) {
143+
System.err.println("The file wasn't found: " + e.getMessage());
144+
} catch (IOException e) {
145+
System.err.println("Error deleting file: " + e.getMessage());
146+
}
141147
}
142-
} else {
143-
System.err.println("The file wasn't found");
148+
} catch (SdkException e) {
149+
System.err.println("S3 operation failed: " + e.getMessage());
144150
}
145151
}
152+
146153
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
x-49267f42-03d5-49ee-bfea-0cfab75f76a8,object-key-1.txt
2-
x-49267f42-03d5-49ee-bfea-0cfab75f76a8,object-key-2.txt
3-
x-49267f42-03d5-49ee-bfea-0cfab75f76a8,object-key-3.txt
4-
x-49267f42-03d5-49ee-bfea-0cfab75f76a8,object-key-4.txt
1+
x-e7f53ef2-703e-4822-9176-54a9ad64bce9,object-key-1.txt
2+
x-e7f53ef2-703e-4822-9176-54a9ad64bce9,object-key-2.txt
3+
x-e7f53ef2-703e-4822-9176-54a9ad64bce9,object-key-3.txt
4+
x-e7f53ef2-703e-4822-9176-54a9ad64bce9,object-key-4.txt

0 commit comments

Comments
 (0)