From 14c3cdda26864a8912d816e8b1a56a69a208cdd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=99=8E=E9=B8=A3?= Date: Sun, 5 Jul 2026 13:44:49 +0800 Subject: [PATCH] refactor: remove deprecated FiniteDuration overloads in TimeoutDirectives and BasicDirectives (since 1.3.0) Motivation: The FiniteDuration overloads were deprecated since pekko-http 1.3.0 in favor of java.time.Duration overloads. Modification: Removed deprecated methods from Java API: - TimeoutDirectives.withRequestTimeout(Duration, Supplier) - TimeoutDirectives.withRequestTimeout(Duration, JFunction, Supplier) - BasicDirectives.extractStrictEntity(FiniteDuration, JFunction) - BasicDirectives.extractStrictEntity(FiniteDuration, Long, JFunction) - BasicDirectives.toStrictEntity(FiniteDuration, Supplier) - BasicDirectives.toStrictEntity(FiniteDuration, Long, Supplier) Removed unused FiniteDuration import and duplicate toStrictEntity method. Added MiMa filters for DirectMissingMethodProblem and IncompatibleMethTypeProblem in BasicDirectives, TimeoutDirectives, and Directives. Result: Deprecated API removed. Users should use java.time.Duration overloads. MiMa binary compatibility check passes. --- .../remove-deprecated-methods.excludes | 11 +++ .../server/directives/BasicDirectives.scala | 76 ------------------- .../server/directives/TimeoutDirectives.scala | 29 ------- 3 files changed, 11 insertions(+), 105 deletions(-) diff --git a/http/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes b/http/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes index 6375262da..f3ffce80f 100644 --- a/http/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes +++ b/http/src/main/mima-filters/2.0.x.backwards.excludes/remove-deprecated-methods.excludes @@ -95,3 +95,14 @@ ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.scalad ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.scaladsl.unmarshalling.sse.EventStreamUnmarshalling.maxEventSize") ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.scaladsl.unmarshalling.sse.EventStreamUnmarshalling.fromEventStream") ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.scaladsl.unmarshalling.sse.EventStreamUnmarshalling.$init$") + +# Remove deprecated TimeoutDirectives and BasicDirectives FiniteDuration overloads (since 1.3.0) +ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.javadsl.server.directives.TimeoutDirectives.withRequestTimeout") +ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.javadsl.server.directives.BasicDirectives.extractStrictEntity") +ProblemFilters.exclude[DirectMissingMethodProblem]("org.apache.pekko.http.javadsl.server.directives.BasicDirectives.toStrictEntity") +ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.http.javadsl.server.directives.TimeoutDirectives.withRequestTimeout") +ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.http.javadsl.server.directives.BasicDirectives.extractStrictEntity") +ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.http.javadsl.server.directives.BasicDirectives.toStrictEntity") +ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.http.javadsl.server.Directives.withRequestTimeout") +ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.http.javadsl.server.Directives.extractStrictEntity") +ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.pekko.http.javadsl.server.Directives.toStrictEntity") diff --git a/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/BasicDirectives.scala b/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/BasicDirectives.scala index d766a085e..bb509c9e5 100644 --- a/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/BasicDirectives.scala +++ b/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/BasicDirectives.scala @@ -22,7 +22,6 @@ import java.util.function.Predicate import java.util.function.Supplier import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor } -import scala.concurrent.duration.FiniteDuration import scala.jdk.DurationConverters._ import scala.jdk.FutureConverters._ @@ -337,25 +336,6 @@ abstract class BasicDirectives { */ def extractRequestEntity(inner: JFunction[RequestEntity, Route]): Route = extractEntity(inner) - /** - * WARNING: This will read the entire request entity into memory and effectively disable streaming. - * - * To help protect against excessive memory use, the request will be aborted if the request is larger - * than allowed by the `pekko.http.parsing.max-to-strict-bytes` configuration setting. - * - * Converts the HttpEntity from the [[pekko.http.javadsl.server.RequestContext]] into an - * [[pekko.http.javadsl.model.HttpEntity.Strict]] and extracts it, or fails the route if unable to drain the - * entire request body within the timeout. - * - * @param timeout The directive is failed if the stream isn't completed after the given timeout. - * @deprecated As of 1.3.0, use the overloaded method taking a `java.time.Duration` instead. - */ - @Deprecated(since = "1.3.0") - @deprecated("use the overloaded method taking a `java.time.Duration` instead.", "1.3.0") - def extractStrictEntity(timeout: FiniteDuration, inner: JFunction[HttpEntity.Strict, Route]): Route = RouteAdapter { - D.extractStrictEntity(timeout) { strict => inner.apply(strict).delegate } - } - /** * WARNING: This will read the entire request entity into memory and effectively disable streaming. * @@ -373,26 +353,6 @@ abstract class BasicDirectives { D.extractStrictEntity(timeout.toScala) { strict => inner.apply(strict).delegate } } - /** - * WARNING: This will read the entire request entity into memory and effectively disable streaming. - * - * To help protect against excessive memory use, the request will be aborted if the request is larger - * than allowed by the `pekko.http.parsing.max-to-strict-bytes` configuration setting. - * - * Converts the HttpEntity from the [[pekko.http.javadsl.server.RequestContext]] into an - * [[pekko.http.javadsl.model.HttpEntity.Strict]] and extracts it, or fails the route if unable to drain the - * entire request body within the timeout. - * - * @param timeout The directive is failed if the stream isn't completed after the given timeout. - * @deprecated As of 1.3.0, use the overloaded method taking a `java.time.Duration` instead. - */ - @Deprecated(since = "1.3.0") - @deprecated("use the overloaded method taking a `java.time.Duration` instead.", "1.3.0") - def extractStrictEntity(timeout: FiniteDuration, maxBytes: Long, inner: JFunction[HttpEntity.Strict, Route]): Route = - RouteAdapter { - D.extractStrictEntity(timeout, maxBytes) { strict => inner.apply(strict).delegate } - } - /** * WARNING: This will read the entire request entity into memory and effectively disable streaming. * @@ -411,24 +371,6 @@ abstract class BasicDirectives { D.extractStrictEntity(timeout.toScala, maxBytes) { strict => inner.apply(strict).delegate } } - /** - * WARNING: This will read the entire request entity into memory and effectively disable streaming. - * - * To help protect against excessive memory use, the request will be aborted if the request is larger - * than allowed by the `pekko.http.parsing.max-to-strict-bytes` configuration setting. - * - * Extracts the [[pekko.http.javadsl.server.RequestContext]] itself with the strict HTTP entity, - * or fails the route if unable to drain the entire request body within the timeout. - * - * @param timeout The directive is failed if the stream isn't completed after the given timeout. - * @deprecated As of 1.3.0, use the overloaded method taking a `java.time.Duration` instead. - */ - @Deprecated(since = "1.3.0") - @deprecated("use the overloaded method taking a `java.time.Duration` instead.", "1.3.0") - def toStrictEntity(timeout: FiniteDuration, inner: Supplier[Route]): Route = RouteAdapter { - D.toStrictEntity(timeout) { inner.get.delegate } - } - /** * WARNING: This will read the entire request entity into memory and effectively disable streaming. * @@ -445,24 +387,6 @@ abstract class BasicDirectives { D.toStrictEntity(timeout.toScala) { inner.get.delegate } } - /** - * WARNING: This will read the entire request entity into memory and effectively disable streaming. - * - * To help protect against excessive memory use, the request will be aborted if the request is larger - * than allowed by the `pekko.http.parsing.max-to-strict-bytes` configuration setting. - * - * Extracts the [[pekko.http.javadsl.server.RequestContext]] itself with the strict HTTP entity, - * or fails the route if unable to drain the entire request body within the timeout. - * - * @param timeout The directive is failed if the stream isn't completed after the given timeout. - * @deprecated As of 1.3.0, use the overloaded method taking a `java.time.Duration` instead. - */ - @Deprecated(since = "1.3.0") - @deprecated("use the overloaded method taking a `java.time.Duration` instead.", "1.3.0") - def toStrictEntity(timeout: FiniteDuration, maxBytes: Long, inner: Supplier[Route]): Route = RouteAdapter { - D.toStrictEntity(timeout, maxBytes) { inner.get.delegate } - } - /** * WARNING: This will read the entire request entity into memory and effectively disable streaming. * diff --git a/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/TimeoutDirectives.scala b/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/TimeoutDirectives.scala index 3b8abd001..8adf2075f 100644 --- a/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/TimeoutDirectives.scala +++ b/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/TimeoutDirectives.scala @@ -40,20 +40,6 @@ abstract class TimeoutDirectives extends WebSocketDirectives { } } - /** - * Tries to set a new request timeout and handler (if provided) at the same time. - * - * Due to the inherent raciness it is not guaranteed that the update will be applied before - * the previously set timeout has expired! - * @deprecated As of 1.3.0, use the overloaded method taking a `java.time.Duration` instead. - */ - @Deprecated(since = "1.3.0") - @deprecated("use the overloaded method taking a `java.time.Duration` instead.", "1.3.0") - def withRequestTimeout(timeout: scala.concurrent.duration.Duration, inner: Supplier[Route]): RouteAdapter = - RouteAdapter { - D.withRequestTimeout(timeout) { inner.get.delegate } - } - /** * Tries to set a new request timeout and handler (if provided) at the same time. * @@ -66,21 +52,6 @@ abstract class TimeoutDirectives extends WebSocketDirectives { D.withRequestTimeout(timeout.toScala) { inner.get.delegate } } - /** - * Tries to set a new request timeout and handler (if provided) at the same time. - * - * Due to the inherent raciness it is not guaranteed that the update will be applied before - * the previously set timeout has expired! - * @deprecated As of 1.3.0, use the overloaded method taking a `java.time.Duration` instead. - */ - @Deprecated(since = "1.3.0") - @deprecated("use the overloaded method taking a `java.time.Duration` instead.", "1.3.0") - def withRequestTimeout(timeout: scala.concurrent.duration.Duration, - timeoutHandler: JFunction[HttpRequest, HttpResponse], - inner: Supplier[Route]): RouteAdapter = RouteAdapter { - D.withRequestTimeout(timeout, in => timeoutHandler(in.asJava).asScala) { inner.get.delegate } - } - /** * Tries to set a new request timeout and handler (if provided) at the same time. *