From 6d73cb0c634be53c780f314b0974997247f6ab70 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Mon, 20 Feb 2023 23:21:48 +0000 Subject: [PATCH 1/2] Downgrade client to build with Java 8 Signed-off-by: Harsha Vamsi Kalluri --- java-client/build.gradle.kts | 4 ++-- .../client/transport/aws/AwsSdk2Transport.java | 9 +++++++-- .../client/opensearch/integTest/aws/AwsSdk2SearchIT.java | 3 ++- .../integTest/aws/AwsSdk2TransportTestCase.java | 7 ++++--- .../httpclient5/HttpClient5TransportSupport.java | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index 4c0f7b8400..7c665eb016 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -60,8 +60,8 @@ checkstyle { } java { - targetCompatibility = JavaVersion.VERSION_11 - sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 withJavadocJar() withSourcesJar() diff --git a/java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java b/java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java index 8fd1dfa9b4..4aff430a47 100644 --- a/java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java +++ b/java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java @@ -46,6 +46,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; @@ -294,9 +295,13 @@ private SdkHttpFullRequest prepareRequest( Map params = endpoint.queryParameters(request); if (params != null && !params.isEmpty()) { char sep = '?'; - for (var ent : params.entrySet()) { + for (Map.Entry ent : params.entrySet()) { url.append(sep).append(ent.getKey()).append('='); - url.append(URLEncoder.encode(ent.getValue(), StandardCharsets.UTF_8)); + try { + url.append(URLEncoder.encode(ent.getValue(), StandardCharsets.UTF_8.name())); + } catch (UnsupportedEncodingException e) { + throw new AssertionError("UTF-8 is unknown"); + } sep = '&'; } } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/aws/AwsSdk2SearchIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/aws/AwsSdk2SearchIT.java index 1e7f4ce427..6edd5cb793 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/aws/AwsSdk2SearchIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/aws/AwsSdk2SearchIT.java @@ -18,6 +18,7 @@ import org.opensearch.client.opensearch.core.SearchResponse; import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.OpenSearchIndicesClient; +import org.opensearch.client.opensearch.indices.CreateIndexRequest.Builder; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -139,7 +140,7 @@ public void testDoubleWrappedException() throws Exception { resetTestIndex(false); // attempt to create the same index a second time OpenSearchIndicesClient client = getIndexesClient(false, null, null); - var req = new CreateIndexRequest.Builder().index(TEST_INDEX); + Builder req = new CreateIndexRequest.Builder().index(TEST_INDEX); Exception exception = Assert.assertThrows(OpenSearchException.class, () -> { client.create(req.build()); }); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/aws/AwsSdk2TransportTestCase.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/aws/AwsSdk2TransportTestCase.java index 8adcd4300b..5ee38f2ffa 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/aws/AwsSdk2TransportTestCase.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/aws/AwsSdk2TransportTestCase.java @@ -26,6 +26,7 @@ import org.opensearch.client.opensearch.indices.CreateIndexRequest; import org.opensearch.client.opensearch.indices.IndexState; import org.opensearch.client.opensearch.indices.OpenSearchIndicesClient; +import org.opensearch.client.opensearch.indices.CreateIndexRequest.Builder; import org.opensearch.client.transport.TransportOptions; import org.opensearch.client.transport.aws.AwsSdk2Transport; import org.opensearch.client.transport.aws.AwsSdk2TransportOptions; @@ -207,13 +208,13 @@ public void resetTestIndex(boolean async) throws Exception { if (indexExists) { client.delete(b -> b.index(List.of(TEST_INDEX))); } - var req = new CreateIndexRequest.Builder() + Builder req = new CreateIndexRequest.Builder() .index(TEST_INDEX); client.create(req.build()); } protected SearchResponse query(OpenSearchClient client, String title, String text) throws Exception { - var query = Query.of(qb -> { + Query query = Query.of(qb -> { if (title != null) { qb.match(mb -> mb.field("title").query(vb -> vb.stringValue(title))); } @@ -237,7 +238,7 @@ protected SearchResponse query(OpenSearchClient client, String title protected CompletableFuture> query( OpenSearchAsyncClient client, String title, String text) { - var query = Query.of(qb -> { + Query query = Query.of(qb -> { if (title != null) { qb.match(mb -> mb.field("title").query(vb -> vb.stringValue(title))); } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/HttpClient5TransportSupport.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/HttpClient5TransportSupport.java index 2b0c4088f8..b8cd54adfb 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/HttpClient5TransportSupport.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/HttpClient5TransportSupport.java @@ -51,7 +51,7 @@ default OpenSearchTransport buildTransport(Settings settings, HttpHost[] hosts) return builder.setStrictDeprecationMode(true).build(); } - private void configure(ApacheHttpClient5TransportBuilder builder, Settings settings, HttpHost[] hosts) throws IOException { + default void configure(ApacheHttpClient5TransportBuilder builder, Settings settings, HttpHost[] hosts) throws IOException { if (isHttps()) { try { final SSLContext sslcontext = SSLContextBuilder From 72ae598a050b95a010c805d41b7cea64d15d6111 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Fri, 10 Mar 2023 17:54:59 +0000 Subject: [PATCH 2/2] Adding Java 8 build step Signed-off-by: Harsha Vamsi Kalluri --- .github/workflows/build.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 668fc8b7b5..f66866c9ab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,16 +7,17 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - java: [ 11 ] + java: [ 8, 11 ] os: [ubuntu-latest, windows-latest, macOS-latest] steps: - name: Set up JDK ${{ matrix.java }} - uses: actions/setup-java@v1 + uses: actions/setup-java@v2 with: + distribution: 'zulu' java-version: ${{ matrix.java }} - name: Checkout Branch - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Build with Gradle run: ./gradlew clean build -x test