diff --git a/aws-spi-pekko-http/src/main/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClient.scala b/aws-spi-pekko-http/src/main/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClient.scala index 0a9cfe698..df57812e2 100644 --- a/aws-spi-pekko-http/src/main/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClient.scala +++ b/aws-spi-pekko-http/src/main/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClient.scala @@ -32,7 +32,8 @@ import pekko.http.scaladsl.settings.ConnectionPoolSettings import pekko.stream.scaladsl.Source import pekko.stream.{ Materializer, SystemMaterializer } import pekko.util.ByteString -import pekko.util.OptionConverters +import pekko.util.OptionConverters._ +import pekko.util.JavaDurationConverters._ import org.slf4j.LoggerFactory import software.amazon.awssdk.http.async._ import software.amazon.awssdk.http.{ SdkHttpConfigurationOption, SdkHttpRequest } @@ -41,7 +42,6 @@ import software.amazon.awssdk.utils.AttributeMap import scala.collection.immutable import scala.concurrent.duration.Duration import scala.concurrent.{ Await, ExecutionContext } -import scala.jdk.DurationConverters._ class PekkoHttpClient(shutdownHandle: () => Unit, private[awsspi] val connectionSettings: ConnectionPoolSettings)( implicit @@ -86,8 +86,7 @@ object PekkoHttpClient { contentType: ContentType, contentPublisher: SdkHttpContentPublisher): RequestEntity = method.requestEntityAcceptance match { - case Expected => - OptionConverters.toScala(contentPublisher.contentLength()) match { + case Expected => contentPublisher.contentLength().toScala match { case Some(length) => HttpEntity(contentType, length, Source.fromPublisher(contentPublisher).map(ByteString(_))) case None => HttpEntity(contentType, Source.fromPublisher(contentPublisher).map(ByteString(_))) @@ -157,12 +156,12 @@ object PekkoHttpClient { base: ConnectionPoolSettings, attributeMap: AttributeMap): ConnectionPoolSettings = { def zeroToInfinite(duration: java.time.Duration): scala.concurrent.duration.Duration = if (duration.isZero) scala.concurrent.duration.Duration.Inf - else duration.toScala + else duration.asScala base .withUpdatedConnectionSettings(s => - s.withConnectingTimeout(attributeMap.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT).toScala) - .withIdleTimeout(attributeMap.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toScala)) + s.withConnectingTimeout(attributeMap.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT).asScala) + .withIdleTimeout(attributeMap.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).asScala)) .withMaxConnections(attributeMap.get(SdkHttpConfigurationOption.MAX_CONNECTIONS).intValue()) .withMaxConnectionLifetime(zeroToInfinite(attributeMap.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE))) } diff --git a/aws-spi-pekko-http/src/test/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClientSpec.scala b/aws-spi-pekko-http/src/test/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClientSpec.scala index 2308ff23e..3ae36ed21 100644 --- a/aws-spi-pekko-http/src/test/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClientSpec.scala +++ b/aws-spi-pekko-http/src/test/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClientSpec.scala @@ -24,6 +24,7 @@ import org.apache.pekko import pekko.http.scaladsl.model.headers.`Content-Type` import pekko.http.scaladsl.model.MediaTypes import pekko.http.scaladsl.settings.{ ClientConnectionSettings, ConnectionPoolSettings } +import pekko.util.JavaDurationConverters._ import org.scalatest.OptionValues import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec @@ -31,7 +32,6 @@ import software.amazon.awssdk.http.SdkHttpConfigurationOption import software.amazon.awssdk.utils.AttributeMap import scala.concurrent.duration._ -import scala.jdk.DurationConverters._ class PekkoHttpClientSpec extends AnyWordSpec with Matchers with OptionValues { @@ -64,10 +64,10 @@ class PekkoHttpClientSpec extends AnyWordSpec with Matchers with OptionValues { "withConnectionPoolSettingsBuilderFromAttributeMap().buildWithDefaults() should propagate configuration options" in { val attributeMap = AttributeMap.builder() - .put(SdkHttpConfigurationOption.CONNECTION_TIMEOUT, 1.second.toJava) - .put(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT, 2.second.toJava) + .put(SdkHttpConfigurationOption.CONNECTION_TIMEOUT, 1.second.asJava) + .put(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT, 2.second.asJava) .put(SdkHttpConfigurationOption.MAX_CONNECTIONS, Integer.valueOf(3)) - .put(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE, 4.second.toJava) + .put(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE, 4.second.asJava) .build() val pekkoClient: PekkoHttpClient = new PekkoHttpAsyncHttpService().createAsyncHttpClientFactory() .withConnectionPoolSettingsBuilderFromAttributeMap() @@ -87,9 +87,9 @@ class PekkoHttpClientSpec extends AnyWordSpec with Matchers with OptionValues { .asInstanceOf[PekkoHttpClient] pekkoClient.connectionSettings.connectionSettings.connectingTimeout shouldBe - SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT).toScala + SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS.get(SdkHttpConfigurationOption.CONNECTION_TIMEOUT).asScala pekkoClient.connectionSettings.connectionSettings.idleTimeout shouldBe - SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).toScala + SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS.get(SdkHttpConfigurationOption.CONNECTION_MAX_IDLE_TIMEOUT).asScala pekkoClient.connectionSettings.maxConnections shouldBe SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS.get(SdkHttpConfigurationOption.MAX_CONNECTIONS).intValue() infiniteToZero(pekkoClient.connectionSettings.maxConnectionLifetime) shouldBe @@ -134,6 +134,6 @@ class PekkoHttpClientSpec extends AnyWordSpec with Matchers with OptionValues { private def infiniteToZero(duration: scala.concurrent.duration.Duration): java.time.Duration = duration match { case _: scala.concurrent.duration.Duration.Infinite => java.time.Duration.ZERO - case duration: FiniteDuration => duration.toJava + case duration: FiniteDuration => duration.asJava } }