diff --git a/CHANGELOG.md b/CHANGELOG.md index 146487cf16..761c7f9b3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Fixed - ApacheHttpClient5Transport requires Apache Commons Logging dependency ([#1003](https://github.com/opensearch-project/opensearch-java/pull/1003)) +- Preserve caller information in stack traces when synchronous callers use asynchronous transports ([#656](https://github.com/opensearch-project/opensearch-java/pull/656)) ### Security diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index cfd9ad3a9d..569dada74a 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -80,7 +80,7 @@ java { registerFeature("awsSdk2Support") { usingSourceSet(sourceSets.get("main")) } - + toolchain { languageVersion = JavaLanguageVersion.of(runtimeJavaVersion.majorVersion) vendor = JvmVendorSpec.ADOPTIUM @@ -205,6 +205,7 @@ dependencies { // For AwsSdk2Transport "awsSdk2SupportCompileOnly"("software.amazon.awssdk","sdk-core","[2.15,3.0)") "awsSdk2SupportCompileOnly"("software.amazon.awssdk","auth","[2.15,3.0)") + "awsSdk2SupportCompileOnly"("io.netty","netty-handler","4.1.108.Final") testImplementation("software.amazon.awssdk","sdk-core","[2.15,3.0)") testImplementation("software.amazon.awssdk","auth","[2.15,3.0)") testImplementation("software.amazon.awssdk","aws-crt-client","[2.15,3.0)") @@ -372,17 +373,17 @@ if (runtimeJavaVersion >= JavaVersion.VERSION_11) { targetCompatibility = JavaVersion.VERSION_11.toString() sourceCompatibility = JavaVersion.VERSION_11.toString() } - + tasks.named("compileTestJava") { targetCompatibility = JavaVersion.VERSION_11.toString() sourceCompatibility = JavaVersion.VERSION_11.toString() } - + tasks.named("integrationTest") { testClassesDirs += java11.output.classesDirs classpath = sourceSets["java11"].runtimeClasspath } - + tasks.named("unitTest") { testClassesDirs += java11.output.classesDirs classpath = sourceSets["java11"].runtimeClasspath 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 f2db2bb7de..2569335331 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 @@ -8,6 +8,10 @@ package org.opensearch.client.transport.aws; +import io.netty.channel.ChannelPipelineException; +import io.netty.channel.EventLoopException; +import io.netty.handler.timeout.ReadTimeoutException; +import io.netty.handler.timeout.WriteTimeoutException; import jakarta.json.JsonObject; import jakarta.json.stream.JsonParser; import java.io.ByteArrayInputStream; @@ -662,9 +666,6 @@ private static Exception extractAndWrapCause(Exception exception) { e.initCause(exception); return e; } - if (exception instanceof IOException) { - return new IOException(exception.getMessage(), exception); - } if (exception instanceof OpenSearchException) { final OpenSearchException e = new OpenSearchException(((OpenSearchException) exception).response()); e.initCause(exception); @@ -675,6 +676,29 @@ private static Exception extractAndWrapCause(Exception exception) { e.initCause(exception); return e; } + if (exception instanceof ReadTimeoutException) { + final ReadTimeoutException e = new ReadTimeoutException(exception.getMessage()); + e.initCause(exception); + return e; + } + if (exception instanceof WriteTimeoutException) { + final WriteTimeoutException e = new WriteTimeoutException(exception.getMessage()); + e.initCause(exception); + return e; + } + if (exception instanceof ChannelPipelineException) { + final ChannelPipelineException e = new ChannelPipelineException(exception.getMessage()); + e.initCause(exception); + return e; + } + if (exception instanceof EventLoopException) { + final EventLoopException e = new EventLoopException(exception.getMessage()); + e.initCause(exception); + return e; + } + if (exception instanceof IOException) { + return new IOException(exception.getMessage(), exception); + } if (exception instanceof RuntimeException) { return new RuntimeException(exception.getMessage(), exception); }