Skip to content

Java V2 updates the POM files to use JDK 21 #7327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 72 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
4c1b41b
updated POM to use JDK 21
scmacdon Mar 26, 2025
bc36855
updated POM to use JDK 21
scmacdon Mar 27, 2025
00df7be
updated POM to use JDK 21
scmacdon Mar 27, 2025
fd15e10
updated POM to use JDK 21
scmacdon Mar 27, 2025
e60c8bb
updated POM to use JDK 21
scmacdon Mar 27, 2025
0696438
updated POM to use JDK 21
scmacdon Mar 27, 2025
f4296c1
updated POM to use JDK 21
scmacdon Mar 27, 2025
40363dc
updated POM to use JDK 21
scmacdon Mar 27, 2025
297c1db
updated POM to use JDK 21
scmacdon Mar 27, 2025
96affe5
updated POM to use JDK 21
scmacdon Mar 27, 2025
1f48d3e
updated POM to use JDK 21
scmacdon Mar 27, 2025
e0237cc
updated POM to use JDK 21
scmacdon Mar 28, 2025
ba46d62
updated POM to use JDK 21
scmacdon Mar 28, 2025
2b5bb9f
updated POM to use JDK 21
scmacdon Mar 28, 2025
16315fe
updated POM to use JDK 21
scmacdon Mar 28, 2025
87b30bf
updated POM to use JDK 21
scmacdon Mar 28, 2025
777e357
updated POM to use JDK 21
scmacdon Mar 28, 2025
0e36a0a
updated POM to use JDK 21
scmacdon Mar 28, 2025
4f8563b
updated POM to use JDK 21
scmacdon Mar 28, 2025
89540ed
updated POM to use JDK 21
scmacdon Mar 29, 2025
8c20001
updated POM to use JDK 21
scmacdon Mar 29, 2025
3ef5128
updated POM to use JDK 21
scmacdon Mar 29, 2025
0da326a
updated POM to use JDK 21
scmacdon Mar 30, 2025
9c0cd02
updated POM to use JDK 21
scmacdon Mar 30, 2025
5a6709c
updated POM to use JDK 21
scmacdon Mar 31, 2025
a884b41
updated POM to use JDK 21
scmacdon Mar 31, 2025
d4a9a36
updated POM to use JDK 21
scmacdon Mar 31, 2025
09aa827
updated POM to use JDK 21
scmacdon Mar 31, 2025
7fa2f14
updated POM to use JDK 21
scmacdon Mar 31, 2025
5dbc4dc
updated POM to use JDK 21
scmacdon Mar 31, 2025
0a7d6e5
updated POM to use JDK 21
scmacdon Mar 31, 2025
83e26df
updated POM to use JDK 21
scmacdon Mar 31, 2025
6a929d4
updated POM to use JDK 21
scmacdon Mar 31, 2025
6c18b00
updated POM to use JDK 21
scmacdon Mar 31, 2025
f389da4
updated POM to use JDK 21
scmacdon Mar 31, 2025
47a9526
updated POM to use JDK 21
scmacdon Mar 31, 2025
50d1f29
updated POM to use JDK 21
scmacdon Mar 31, 2025
657283f
updated POM to use JDK 21
scmacdon Mar 31, 2025
c69c8c8
updated POM to use JDK 21
scmacdon Mar 31, 2025
81fab1f
updated POM to use JDK 21
scmacdon Mar 31, 2025
5151b0b
updated POM to use JDK 21
scmacdon Mar 31, 2025
9d68995
updated POM to use JDK 21
scmacdon Mar 31, 2025
7065c55
updated POM to use JDK 21
scmacdon Mar 31, 2025
406335e
updated POM to use JDK 21
scmacdon Mar 31, 2025
b11acc3
updated POM to use JDK 21
scmacdon Mar 31, 2025
714d60a
updated POM to use JDK 21
scmacdon Mar 31, 2025
c7dd7a4
updated POM to use JDK 21
scmacdon Mar 31, 2025
7f10f6a
updated POM to use JDK 21
scmacdon Mar 31, 2025
a8f833e
updated POM to use JDK 21
scmacdon Apr 1, 2025
47466ae
updated POM to use JDK 21
scmacdon Apr 1, 2025
2ad7cf8
updated POM to use JDK 21
scmacdon Apr 1, 2025
9a7b809
updated POM to use JDK 21
scmacdon Apr 1, 2025
d6bf726
updated POM to use JDK 21
scmacdon Apr 1, 2025
b3efe06
updated POM to use JDK 21
scmacdon Apr 1, 2025
a34a42a
updated POM to use JDK 21
scmacdon Apr 1, 2025
091d6cf
updated POM to use JDK 21
scmacdon Apr 1, 2025
e5ac62f
updated POM to use JDK 21
scmacdon Apr 1, 2025
528c434
updated POM to use JDK 21
scmacdon Apr 1, 2025
93468cb
updated POM to use JDK 21
scmacdon Apr 1, 2025
ca7bc47
updated POM to use JDK 21
scmacdon Apr 1, 2025
a5f64ef
updated POM to use JDK 21
scmacdon Apr 1, 2025
5b52df2
updated POM to use JDK 21
scmacdon Apr 1, 2025
836ea66
updated POM to use JDK 21
scmacdon Apr 1, 2025
d2e4414
updated POM to use JDK 21
scmacdon Apr 1, 2025
1612267
updated POM to use JDK 21
scmacdon Apr 1, 2025
aa6bc62
updated tests
scmacdon Apr 1, 2025
c496c5e
updated tests
scmacdon Apr 1, 2025
77d803d
updated tests
scmacdon Apr 1, 2025
6172222
updated tests
scmacdon Apr 1, 2025
f0664f4
updated POM to use JDK 21
scmacdon Apr 1, 2025
e7c9b71
updated POM to use JDK 21
scmacdon Apr 2, 2025
5e5f971
updated POM to use JDK 21
scmacdon Apr 2, 2025
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
12 changes: 8 additions & 4 deletions javav2/example_code/acm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<java.version>21</java.version>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
</properties>
<build>
<plugins>
Expand All @@ -36,7 +36,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.29.45</version>
<version>2.31.8</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -64,6 +64,10 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@

package com.example.acm;

import software.amazon.awssdk.core.ResponseInputStream;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.acm.AcmClient;
import software.amazon.awssdk.services.acm.model.ImportCertificateRequest;
import software.amazon.awssdk.services.acm.model.ImportCertificateResponse;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.awssdk.utils.IoUtils;
import java.io.FileInputStream;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;

// snippet-start:[acm.java2.import_cert.main]
Expand All @@ -25,58 +30,79 @@
public class ImportCert {

public static void main(String[] args) {

final String usage = """

Usage: <certificatePath> <privateKeyPath>

Usage: <bucketName> <certificateKey> <privateKeyKey>

Where:
certificatePath - the path to the SSL/TLS certificate file.
privateKeyPath - the path to the private key file associated with the SSL/TLS certificate.
bucketName - The name of the S3 bucket containing the certificate and private key.
certificateKey - The object key for the SSL/TLS certificate file in S3.
privateKeyKey - The object key for the private key file in S3.
""";

if (args.length != 2) {
System.out.println(usage);
return;
}
//if (args.length != 3) {
// System.out.println(usage);
// return;
// }

String bucketName = "certbucket100" ; //args[0];
String certificateKey = "certificate.pem" ; // args[1];
String privateKeyKey = "private_key.pem" ; //args[2];

String certificatePath = args[0];
String privateKeyPath = args[1];
String certificateArn = importCertificate(certificatePath, privateKeyPath);
String certificateArn = importCertificate(bucketName, certificateKey, privateKeyKey);
System.out.println("Certificate imported with ARN: " + certificateArn);
}

/**
* Imports an SSL/TLS certificate and private key into AWS Certificate Manager (ACM) for use with
* AWS services.
* Imports an SSL/TLS certificate and private key from S3 into AWS Certificate Manager (ACM).
*
* @param certificatePath the file path to the SSL/TLS certificate
* @param privateKeyPath the file path to the private key associated with the certificate
* @throws IOException if there is an error reading the certificate or private key files
* @param bucketName The name of the S3 bucket.
* @param certificateKey The key for the SSL/TLS certificate file in S3.
* @param privateKeyKey The key for the private key file in S3.
* @return The ARN of the imported certificate.
*/
public static String importCertificate(String certificatePath, String privateKeyPath) {
public static String importCertificate(String bucketName, String certificateKey, String privateKeyKey) {
AcmClient acmClient = AcmClient.create();
S3Client s3Client = S3Client.create();

try {
byte[] certificateBytes = readFileBytes(certificatePath);
byte[] privateKeyBytes = readFileBytes(privateKeyPath);
byte[] certificateBytes = downloadFileFromS3(s3Client, bucketName, certificateKey);
byte[] privateKeyBytes = downloadFileFromS3(s3Client, bucketName, privateKeyKey);

ImportCertificateRequest request = ImportCertificateRequest.builder()
.certificate(SdkBytes.fromByteBuffer(ByteBuffer.wrap(certificateBytes)))
.privateKey(SdkBytes.fromByteBuffer(ByteBuffer.wrap(privateKeyBytes)))
.build();
.certificate(SdkBytes.fromByteBuffer(ByteBuffer.wrap(certificateBytes)))
.privateKey(SdkBytes.fromByteBuffer(ByteBuffer.wrap(privateKeyBytes)))
.build();

ImportCertificateResponse response = acmClient.importCertificate(request);
String certificateArn = response.certificateArn();
return certificateArn;
return response.certificateArn();

} catch (IOException e) {
System.err.println("Error reading certificate or private key file: " + e.getMessage());
System.err.println("Error downloading certificate or private key from S3: " + e.getMessage());
} catch (S3Exception e) {
System.err.println("S3 error: " + e.awsErrorDetails().errorMessage());
}
return "";
}

private static byte[] readFileBytes(String filePath) throws IOException {
try (InputStream inputStream = new FileInputStream(filePath)) {
return IoUtils.toByteArray(inputStream);
/**
* Downloads a file from Amazon S3 and returns its contents as a byte array.
*
* @param s3Client The S3 client.
* @param bucketName The name of the S3 bucket.
* @param objectKey The key of the object in S3.
* @return The file contents as a byte array.
* @throws IOException If an I/O error occurs.
*/
private static byte[] downloadFileFromS3(S3Client s3Client, String bucketName, String objectKey) throws IOException {
GetObjectRequest getObjectRequest = GetObjectRequest.builder()
.bucket(bucketName)
.key(objectKey)
.build();

try (ResponseInputStream<GetObjectResponse> s3Object = s3Client.getObject(getObjectRequest);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
IoUtils.copy(s3Object, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions javav2/example_code/acm/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Configuration status="WARN">
<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%msg%n"/>
</Console>
<Console name="AlignedConsoleAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%m%n"/>
</Console>
</Appenders>
<Loggers>
<!-- Root logger configuration -->
<Root level="info">
<!-- Specify which appenders to use -->
<AppenderRef ref="ConsoleAppender" />
</Root>
</Loggers>
</Configuration>
92 changes: 67 additions & 25 deletions javav2/example_code/acm/src/test/java/ACMTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,48 @@
import com.example.acm.ListCertTags;
import com.example.acm.RemoveTagsFromCert;
import com.example.acm.RequestCert;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestMethodOrder;
import com.google.gson.Gson;
import org.junit.jupiter.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class ACMTests {

private static final Logger logger = LoggerFactory.getLogger(ACMTests.class);
private static String certificatePath = "";
private static String privateKeyPath = "";

private static String bucketName = "";
private static String certificateArn;

@BeforeAll
public static void setUp() {

certificatePath = "C:\\Users\\scmacdon\\cert_example\\certificate.pem";
privateKeyPath = "C:\\Users\\scmacdon\\cert_example\\private_key.pem";
public static void setUp() throws IOException {
Gson gson = new Gson();
String json = getSecretValues();
SecretValues values = gson.fromJson(json, SecretValues.class);
certificatePath = values.getCertificatePath();
privateKeyPath = values.getPrivateKeyPath();
bucketName = values.getBucketName();
}

@Test
@Tag("IntegrationTest")
@Order(1)
public void testImportCert() {
assertDoesNotThrow(() -> {
certificateArn = ImportCert.importCertificate(certificatePath, privateKeyPath);
certificateArn = ImportCert.importCertificate(bucketName, certificatePath, privateKeyPath);
assertNotNull(certificateArn);
});
logger.info("Test 1 passed");
}

@Test
Expand All @@ -52,6 +60,7 @@ public void testAddTags() {
assertDoesNotThrow(() -> {
AddTagsToCertificate.addTags(certificateArn);
});
logger.info("Test 2 passed");
}

@Test
Expand All @@ -61,42 +70,75 @@ public void testDescribeCert() {
assertDoesNotThrow(() -> {
DescribeCert.describeCertificate(certificateArn);
});
logger.info("Test 3 passed");
}

@Test
@Tag("IntegrationTest")
@Order(4)
public void testListCertTags() {
assertDoesNotThrow(() -> {
ListCertTags.listCertTags(certificateArn);
});
}

@Test
@Tag("IntegrationTest")
@Order(5)
public void testRemoveTagsFromCert() {
assertDoesNotThrow(() -> {
RemoveTagsFromCert.removeTags(certificateArn);
});
logger.info("Test 4 passed");
}


@Test
@Tag("IntegrationTest")
@Order(6)
@Order(5)
public void testRequestCert() {
assertDoesNotThrow(() -> {
RequestCert.requestCertificate();
});
logger.info("Test 5 passed");
}

@Test
@Tag("IntegrationTest")
@Order(7)
@Order(6)
public void testDeleteCert() {
assertDoesNotThrow(() -> {
DeleteCert.deleteCertificate(certificateArn);
});
logger.info("Test 6 passed");
}


private static String getSecretValues() {
SecretsManagerClient secretClient = SecretsManagerClient.builder()
.region(Region.US_EAST_1)
.build();
String secretName = "test/acm";

GetSecretValueRequest valueRequest = GetSecretValueRequest.builder()
.secretId(secretName)
.build();

GetSecretValueResponse valueResponse = secretClient.getSecretValue(valueRequest);
return valueResponse.secretString();
}

@Nested
@DisplayName("A class used to get test values from test/cognito (an AWS Secrets Manager secret)")
class SecretValues {
private String certificatePath;
private String privateKeyPath;
private String bucketName;

// Getter for certificatePath
public String getCertificatePath() {
return certificatePath;
}

// Getter for privateKeyPath
public String getPrivateKeyPath() {
return privateKeyPath;
}

// Getter for bucketName
public String getBucketName() {
return bucketName;
}
}
}
32 changes: 28 additions & 4 deletions javav2/example_code/apigateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<java.version>21</java.version>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
</properties>
<build>
<plugins>
Expand All @@ -26,7 +26,14 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.29.45</version>
<version>2.31.8</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.23.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -60,5 +67,22 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>ssooidc</artifactId>
</dependency>
<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>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
</dependency>
</dependencies>
</project>
Loading
Loading