diff --git a/build.sbt b/build.sbt
index 2a8a5689..a9096408 100644
--- a/build.sbt
+++ b/build.sbt
@@ -396,10 +396,7 @@ lazy val `integration-tests` = project
Test / fork := true,
concurrentRestrictions += Tags.limitAll(1), // only one integration test at a time
Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v")),
- libraryDependencies ++= akkaHttp.map(_ % Test) ++ testDependencies,
- libraryDependencies ++= akkaStreams.map(
- _.cross(CrossVersion.for3Use2_13) // temporary, to make it tests work with Scala 3
- ),
+ libraryDependencies ++= playNettyServer.map(_ % Test) ++ testDependencies,
)
.settings(shadedAhcSettings)
.settings(shadedOAuthSettings)
diff --git a/integration-tests/src/test/java/play/libs/ws/ahc/AhcCurlRequestLoggerSpec.scala b/integration-tests/src/test/java/play/libs/ws/ahc/AhcCurlRequestLoggerSpec.scala
index 926a9271..413be5f5 100644
--- a/integration-tests/src/test/java/play/libs/ws/ahc/AhcCurlRequestLoggerSpec.scala
+++ b/integration-tests/src/test/java/play/libs/ws/ahc/AhcCurlRequestLoggerSpec.scala
@@ -4,11 +4,12 @@
package play.libs.ws.ahc
-import akka.http.scaladsl.server.Route
import org.specs2.concurrent.ExecutionEnv
import org.specs2.concurrent.FutureAwait
import org.specs2.mutable.Specification
-import play.AkkaServerProvider
+import play.NettyServerProvider
+import play.api.BuiltInComponents
+import play.api.mvc.Results
import play.libs.ws.DefaultBodyWritables
import play.libs.ws.DefaultWSCookie
import play.libs.ws.WSAuthInfo
@@ -19,23 +20,25 @@ import uk.org.lidalia.slf4jtest.TestLoggerFactory
import scala.jdk.CollectionConverters._
import scala.jdk.FutureConverters._
+import play.api.routing.sird._
class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
extends Specification
- with AkkaServerProvider
+ with NettyServerProvider
with StandaloneWSClientSupport
with FutureAwait
with DefaultBodyWritables {
- override def routes: Route = {
- import akka.http.scaladsl.server.Directives._
- get {
- complete("
Say hello to akka-http
")
- } ~
- post {
- entity(as[String]) { echo =>
- complete(echo)
- }
+ override def routes(components: BuiltInComponents) = {
+ case GET(_) =>
+ components.defaultActionBuilder(
+ Results.Ok("Say hello to play
")
+ )
+ case POST(_) =>
+ components.defaultActionBuilder { req =>
+ Results.Ok(
+ req.body.asText.getOrElse("")
+ )
}
}
diff --git a/integration-tests/src/test/scala/play/AkkaServerProvider.scala b/integration-tests/src/test/scala/play/NettyServerProvider.scala
similarity index 53%
rename from integration-tests/src/test/scala/play/AkkaServerProvider.scala
rename to integration-tests/src/test/scala/play/NettyServerProvider.scala
index 2be608a2..f2116efd 100644
--- a/integration-tests/src/test/scala/play/AkkaServerProvider.scala
+++ b/integration-tests/src/test/scala/play/NettyServerProvider.scala
@@ -5,49 +5,52 @@
package play
import akka.actor.ActorSystem
-import akka.http.scaladsl.Http
-import akka.http.scaladsl.server.Route
import org.specs2.concurrent.ExecutionEnv
import org.specs2.specification.BeforeAfterAll
import scala.concurrent.duration._
import scala.concurrent.Await
-import scala.concurrent.Future
import akka.stream.Materializer
-trait AkkaServerProvider extends BeforeAfterAll {
+import play.api.mvc.Handler
+import play.api.mvc.RequestHeader
+import play.core.server.NettyServer
+import play.core.server.ServerConfig
+import play.api.BuiltInComponents
+import play.api.Mode
+
+trait NettyServerProvider extends BeforeAfterAll {
/**
* @return Routes to be used by the test.
*/
- def routes: Route
+ def routes(components: BuiltInComponents): PartialFunction[RequestHeader, Handler]
/**
* The execution context environment.
*/
def executionEnv: ExecutionEnv
- var testServerPort: Int = _
+ lazy val testServerPort: Int = server.httpPort.getOrElse(sys.error("undefined port number"))
val defaultTimeout: FiniteDuration = 5.seconds
// Create Akka system for thread and streaming management
implicit val system: ActorSystem = ActorSystem()
implicit val materializer: Materializer = Materializer.matFromSystem
- lazy val futureServer: Future[Http.ServerBinding] = {
- // Using 0 (zero) means that a random free port will be used.
- // So our tests can run in parallel and won't mess with each other.
- Http().bindAndHandle(routes, "localhost", 0)
- }
+ // Using 0 (zero) means that a random free port will be used.
+ // So our tests can run in parallel and won't mess with each other.
+ val server = NettyServer.fromRouterWithComponents(
+ ServerConfig(
+ port = Option(0),
+ mode = Mode.Test
+ )
+ )(components => routes(components))
- override def beforeAll(): Unit = {
- val portFuture = futureServer.map(_.localAddress.getPort)(executionEnv.executionContext)
- portFuture.foreach(port => testServerPort = port)(executionEnv.executionContext)
- Await.ready(portFuture, defaultTimeout)
- }
+ override def beforeAll(): Unit = {}
override def afterAll(): Unit = {
- futureServer.foreach(_.unbind())(executionEnv.executionContext)
+ server.stop()
val terminate = system.terminate()
Await.ready(terminate, defaultTimeout)
}
diff --git a/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcCurlRequestLoggerSpec.scala b/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcCurlRequestLoggerSpec.scala
index aa425486..33130432 100644
--- a/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcCurlRequestLoggerSpec.scala
+++ b/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcCurlRequestLoggerSpec.scala
@@ -4,37 +4,43 @@
package play.api.libs.ws.ahc
-import akka.http.scaladsl.server.Route
import org.specs2.concurrent.ExecutionEnv
import org.specs2.concurrent.FutureAwait
import org.specs2.mutable.Specification
-import play.AkkaServerProvider
+import play.NettyServerProvider
+import play.api.BuiltInComponents
import play.api.libs.ws.DefaultBodyWritables
import play.api.libs.ws.DefaultWSCookie
import play.api.libs.ws.EmptyBody
import play.api.libs.ws.WSAuthScheme
+import play.api.mvc.Handler
+import play.api.mvc.RequestHeader
+import play.api.mvc.Results
import uk.org.lidalia.slf4jext.Level
import uk.org.lidalia.slf4jtest.TestLogger
import uk.org.lidalia.slf4jtest.TestLoggerFactory
+import play.api.routing.sird._
import scala.jdk.CollectionConverters._
class AhcCurlRequestLoggerSpec(implicit val executionEnv: ExecutionEnv)
extends Specification
- with AkkaServerProvider
+ with NettyServerProvider
with StandaloneWSClientSupport
with FutureAwait
with DefaultBodyWritables {
- override def routes: Route = {
- import akka.http.scaladsl.server.Directives._
- get {
- complete("Say hello to akka-http
")
- } ~
- post {
- entity(as[String]) { echo =>
- complete(echo)
- }
+ override def routes(components: BuiltInComponents): PartialFunction[RequestHeader, Handler] = {
+ case GET(_) =>
+ components.defaultActionBuilder(
+ Results
+ .Ok("Say hello to play
")
+ )
+ case POST(_) =>
+ components.defaultActionBuilder { req =>
+ Results.Ok(
+ req.body.asText.getOrElse("")
+ )
}
}
diff --git a/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSClientSpec.scala b/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSClientSpec.scala
index 9f4b29db..8b40f04f 100644
--- a/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSClientSpec.scala
+++ b/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSClientSpec.scala
@@ -4,14 +4,6 @@
package play.api.libs.ws.ahc
-import akka.http.scaladsl.model.StatusCodes.Redirection
-import akka.http.scaladsl.model.headers.HttpCookie
-import akka.http.scaladsl.model.headers.RawHeader
-import akka.http.scaladsl.model.StatusCode
-import akka.http.scaladsl.model.StatusCodes
-import akka.http.scaladsl.server.Directives._
-import akka.http.scaladsl.server.MissingCookieRejection
-import akka.http.scaladsl.server.Route
import akka.stream.scaladsl.Sink
import akka.util.ByteString
import org.specs2.concurrent.ExecutionEnv
@@ -19,15 +11,22 @@ import org.specs2.concurrent.FutureAwait
import org.specs2.execute.Result
import org.specs2.matcher.FutureMatchers
import org.specs2.mutable.Specification
-import play.AkkaServerProvider
+import play.NettyServerProvider
+import play.api.BuiltInComponents
+import play.api.http.Status.MOVED_PERMANENTLY
import play.api.libs.ws._
+import play.api.mvc.Cookie
+import play.api.mvc.Handler
+import play.api.mvc.RequestHeader
+import play.api.mvc.Results
+import play.api.routing.sird._
import play.shaded.ahc.org.asynchttpclient.handler.MaxRedirectException
import scala.concurrent._
class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
extends Specification
- with AkkaServerProvider
+ with NettyServerProvider
with StandaloneWSClientSupport
with FutureMatchers
with FutureAwait
@@ -44,62 +43,66 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
)(block)
}
- val indexRoutes: Route = {
- path("index") {
- extractRequest { request =>
- respondWithHeaders(request.headers.map(h => RawHeader(s"Req-${h.name}", h.value))) {
- get {
- complete("Say hello to akka-http")
- } ~
- post {
- complete(s"POST: ${request.entity}")
- }
- }
+ def routes(components: BuiltInComponents): PartialFunction[RequestHeader, Handler] = {
+ case p"/index" =>
+ components.defaultActionBuilder { request =>
+ (
+ request match {
+ case GET(_) =>
+ Results.Ok("Say hello to play")
+ case POST(_) =>
+ Results.Ok(s"POST: ${request.body.asText.getOrElse("")}")
+ case _ =>
+ Results.NotFound
+ }
+ ).withHeaders(request.headers.headers.map(h => (s"Req-${h._1}", h._2)): _*)
}
- }
- }
-
- val cookieRoutes: Route = {
- path("cookie") {
- get {
- setCookie(HttpCookie("flash", "redirect-cookie")) {
- redirect("/cookie-destination", StatusCodes.MovedPermanently)
- }
+ case p"/cookie" =>
+ components.defaultActionBuilder {
+ case GET(_) =>
+ Results
+ .Redirect(
+ url = "/cookie-destination",
+ status = MOVED_PERMANENTLY
+ )
+ .withCookies(
+ Cookie(
+ name = "flash",
+ value = "redirect-cookie"
+ )
+ )
+ case _ =>
+ Results.NotFound
}
- } ~
- path("cookie-destination") {
- get {
- optionalCookie("flash") {
- case Some(c) => complete(s"Cookie value => ${c.value}")
- case None => reject(MissingCookieRejection("flash"))
+ case p"/cookie-destination" =>
+ components.defaultActionBuilder {
+ case GET(req) =>
+ req.cookies.get("flash") match {
+ case Some(c) =>
+ Results.Ok(s"Cookie value => ${c.value}")
+ case None =>
+ Results.BadRequest("Request is missing required cookie 'flash'")
}
- }
+ case _ =>
+ Results.NotFound
}
- }
-
- val redirectRoutes: Route = {
- // Single redirect
- path("redirect" / IntNumber) { status =>
- get {
- val redirectCode = StatusCode.int2StatusCode(status).asInstanceOf[Redirection]
- redirect("/index", redirectCode)
- } ~
- post {
- val redirectCode = StatusCode.int2StatusCode(status).asInstanceOf[Redirection]
- redirect("/index", redirectCode)
- }
- } ~
- path("redirects" / IntNumber / IntNumber) { (status, count) =>
- get {
- val redirectCode = StatusCode.int2StatusCode(status).asInstanceOf[Redirection]
- if (status == 1) redirect("/index", redirectCode)
- else redirect(s"/redirects/$status/${count - 1}", redirectCode)
+ case p"/redirect/${status}" =>
+ components.defaultActionBuilder {
+ Results.Redirect("/index", status.toInt)
+ }
+ case GET(p"/redirects/${status}/${count}") =>
+ components.defaultActionBuilder {
+ if (status == "1") {
+ Results.Redirect("/index", status.toInt)
+ } else {
+ Results.Redirect(
+ s"/redirects/$status/${count.toInt - 1}",
+ status.toInt
+ )
}
}
}
- override val routes: Route = indexRoutes ~ cookieRoutes ~ redirectRoutes
-
"url" should {
"throw an exception on invalid url" in {
withClient() { client =>
@@ -122,7 +125,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
client.url(s"http://localhost:$testServerPort/index").get().map(res => res.body[String]),
defaultTimeout
)
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -140,7 +143,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
client.url(s"http://localhost:$testServerPort/index").get().map(res => res.body[Foo]),
defaultTimeout
)
- result must beEqualTo(Foo("Say hello to akka-http"))
+ result must beEqualTo(Foo("Say hello to play"))
}
}
@@ -151,7 +154,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
defaultTimeout
)
val bytes: ByteString = Await.result(resultSource.runWith(Sink.head), defaultTimeout)
- bytes.utf8String must beEqualTo("Say hello to akka-http")
+ bytes.utf8String must beEqualTo("Say hello to play")
}
}
@@ -176,7 +179,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
client.url(s"http://localhost:$testServerPort/redirect/302").get().map(res => res.body[String]),
defaultTimeout
)
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -208,7 +211,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
client.url(s"http://localhost:$testServerPort/redirect/301").get().map(res => res.body[String]),
defaultTimeout
)
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -218,7 +221,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
client.url(s"http://localhost:$testServerPort/redirect/302").get().map(res => res.body[String]),
defaultTimeout
)
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -228,7 +231,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
client.url(s"http://localhost:$testServerPort/redirect/303").get().map(res => res.body[String]),
defaultTimeout
)
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -238,7 +241,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
client.url(s"http://localhost:$testServerPort/redirect/307").get().map(res => res.body[String]),
defaultTimeout
)
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -248,7 +251,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
client.url(s"http://localhost:$testServerPort/redirect/308").get().map(res => res.body[String]),
defaultTimeout
)
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -325,7 +328,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
// 2. So when following the redirect, the GET path should be found
// and we get its body
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -335,7 +338,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
.url(s"http://localhost:$testServerPort/redirect/303")
.post("request body")
val result = Await.result(request.map(res => res.body[String]), defaultTimeout)
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
@@ -351,7 +354,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
// 2. So when following the redirect, the GET path should be found
// and we get its body
- result must beEqualTo("Say hello to akka-http")
+ result must beEqualTo("Say hello to play")
}
}
}
diff --git a/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSRequestFilterSpec.scala b/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSRequestFilterSpec.scala
index 1572c292..d1fd61ca 100644
--- a/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSRequestFilterSpec.scala
+++ b/integration-tests/src/test/scala/play/api/libs/ws/ahc/AhcWSRequestFilterSpec.scala
@@ -4,38 +4,42 @@
package play.api.libs.ws.ahc
-import akka.http.scaladsl.model.headers.RawHeader
-import akka.http.scaladsl.model.ContentTypes
-import akka.http.scaladsl.model.HttpEntity
-import akka.http.scaladsl.server.Route
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.mutable.Specification
-import play.AkkaServerProvider
+import play.NettyServerProvider
+import play.api.BuiltInComponents
import play.api.libs.ws._
+import play.api.mvc.Results
import scala.collection.mutable
class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
extends Specification
- with AkkaServerProvider
+ with NettyServerProvider
with StandaloneWSClientSupport
with FutureMatchers
with DefaultBodyReadables {
- override val routes: Route = {
- import akka.http.scaladsl.server.Directives._
- headerValueByName("X-Request-Id") { value =>
- respondWithHeader(RawHeader("X-Request-Id", value)) {
- val httpEntity = HttpEntity(ContentTypes.`text/html(UTF-8)`, "Say hello to akka-http
")
- complete(httpEntity)
- }
- } ~ {
- get {
- parameters("key".as[String]) { key =>
- val httpEntity = HttpEntity(ContentTypes.`text/html(UTF-8)`, s"Say hello to akka-http, key = $key
")
- complete(httpEntity)
- }
+ override def routes(components: BuiltInComponents) = { case _ =>
+ components.defaultActionBuilder { req =>
+ req.headers.get("X-Request-Id") match {
+ case Some(value) =>
+ Results
+ .Ok(
+ Say hello to play
+ )
+ .withHeaders(("X-Request-Id", value))
+ case None =>
+ req.getQueryString("key") match {
+ case Some(key) =>
+ Results
+ .Ok(
+ Say hello to play, key = ${key}
+ )
+ case None =>
+ Results.NotFound
+ }
}
}
}
diff --git a/integration-tests/src/test/scala/play/api/libs/ws/ahc/JsonRequestSpec.scala b/integration-tests/src/test/scala/play/api/libs/ws/ahc/JsonRequestSpec.scala
index 8cc3eaad..9b246aa1 100644
--- a/integration-tests/src/test/scala/play/api/libs/ws/ahc/JsonRequestSpec.scala
+++ b/integration-tests/src/test/scala/play/api/libs/ws/ahc/JsonRequestSpec.scala
@@ -70,7 +70,7 @@ class JsonRequestSpec extends Specification with AfterAll with JsonBodyWritables
}
"read an encoding of UTF-8" in {
- val json = io.Source.fromResource("test.json")(Codec.ISO8859).getLines().mkString
+ val json = scala.io.Source.fromResource("test.json")(Codec.ISO8859).getLines().mkString
val ahcResponse = mock[Response]
val response = new StandaloneAhcWSResponse(ahcResponse)
@@ -85,7 +85,7 @@ class JsonRequestSpec extends Specification with AfterAll with JsonBodyWritables
}
"read an encoding of ISO-8859-1" in {
- val json = io.Source.fromResource("test.json")(Codec.ISO8859).getLines().mkString
+ val json = scala.io.Source.fromResource("test.json")(Codec.ISO8859).getLines().mkString
val ahcResponse = mock[Response]
val response = new StandaloneAhcWSResponse(ahcResponse)
diff --git a/integration-tests/src/test/scala/play/api/libs/ws/ahc/cache/CachingSpec.scala b/integration-tests/src/test/scala/play/api/libs/ws/ahc/cache/CachingSpec.scala
index cee3c226..361cea81 100644
--- a/integration-tests/src/test/scala/play/api/libs/ws/ahc/cache/CachingSpec.scala
+++ b/integration-tests/src/test/scala/play/api/libs/ws/ahc/cache/CachingSpec.scala
@@ -4,9 +4,6 @@
package play.api.libs.ws.ahc.cache
-import akka.http.scaladsl.model._
-import akka.http.scaladsl.model.headers._
-import akka.http.scaladsl.server.Route
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito
import org.mockito.Mockito.when
@@ -14,9 +11,14 @@ import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.mutable.Specification
import org.specs2.specification.AfterAll
-import play.AkkaServerProvider
+import play.NettyServerProvider
+import play.api.BuiltInComponents
import play.api.libs.ws.ahc._
import play.api.libs.ws.DefaultBodyReadables._
+import play.api.mvc.Handler
+import play.api.mvc.RequestHeader
+import play.api.mvc.Results
+import play.api.routing.sird._
import play.shaded.ahc.org.asynchttpclient._
import scala.concurrent.Future
@@ -24,7 +26,7 @@ import scala.reflect.ClassTag
class CachingSpec(implicit val executionEnv: ExecutionEnv)
extends Specification
- with AkkaServerProvider
+ with NettyServerProvider
with AfterAll
with FutureMatchers {
@@ -37,14 +39,12 @@ class CachingSpec(implicit val executionEnv: ExecutionEnv)
new DefaultAsyncHttpClient(ahcConfig)
}
- override val routes: Route = {
- import akka.http.scaladsl.server.Directives._
- path("hello") {
- respondWithHeader(RawHeader("Cache-Control", "public")) {
- val httpEntity = HttpEntity(ContentTypes.`text/html(UTF-8)`, "Say hello to akka-http
")
- complete(httpEntity)
- }
- }
+ def routes(components: BuiltInComponents): PartialFunction[RequestHeader, Handler] = { case GET(p"/hello") =>
+ components.defaultActionBuilder(
+ Results
+ .Ok(Say hello to play
)
+ .withHeaders(("Cache-Control", "public"))
+ )
}
override def afterAll(): Unit = {
@@ -64,7 +64,7 @@ class CachingSpec(implicit val executionEnv: ExecutionEnv)
ws.url(s"http://localhost:$testServerPort/hello")
.get()
.map { response =>
- response.body[String] must be_==("Say hello to akka-http
")
+ response.body[String] must be_==("Say hello to play
")
}
.await
diff --git a/integration-tests/src/test/scala/play/libs/ws/ahc/AhcWSClientSpec.scala b/integration-tests/src/test/scala/play/libs/ws/ahc/AhcWSClientSpec.scala
index 871f0a27..bcb908ac 100644
--- a/integration-tests/src/test/scala/play/libs/ws/ahc/AhcWSClientSpec.scala
+++ b/integration-tests/src/test/scala/play/libs/ws/ahc/AhcWSClientSpec.scala
@@ -4,13 +4,17 @@
package play.libs.ws.ahc
-import akka.http.scaladsl.server.Route
import akka.stream.javadsl.Sink
import akka.util.ByteString
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.mutable.Specification
-import play.AkkaServerProvider
+import play.NettyServerProvider
+import play.api.BuiltInComponents
+import play.api.mvc.AnyContentAsText
+import play.api.mvc.AnyContentAsXml
+import play.api.mvc.Results
+import play.api.routing.sird._
import play.libs.ws._
import scala.jdk.FutureConverters._
@@ -19,20 +23,28 @@ import scala.concurrent.duration._
class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
extends Specification
- with AkkaServerProvider
+ with NettyServerProvider
with StandaloneWSClientSupport
with FutureMatchers
with XMLBodyWritables
with XMLBodyReadables {
- override val routes: Route = {
- import akka.http.scaladsl.server.Directives._
- get {
- complete("Say hello to akka-http
")
- } ~
- post {
- entity(as[String]) { echo =>
- complete(echo)
+ override def routes(components: BuiltInComponents) = {
+ case GET(_) =>
+ components.defaultActionBuilder {
+ Results.Ok(
+ Say hello to play
+ )
+ }
+ case POST(_) =>
+ components.defaultActionBuilder { req =>
+ req.body match {
+ case AnyContentAsText(txt) =>
+ Results.Ok(txt)
+ case AnyContentAsXml(xml) =>
+ Results.Ok(xml)
+ case _ =>
+ Results.NotFound
}
}
}
@@ -56,7 +68,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
val result: Future[ByteString] = future.flatMap { (response: StandaloneWSResponse) =>
response.getBodyAsSource.runWith(Sink.head[ByteString](), materializer).asScala
}
- val expected: ByteString = ByteString.fromString("Say hello to akka-http
")
+ val expected: ByteString = ByteString.fromString("Say hello to play
")
result must be_==(expected).await(retries = 0, timeout = 5.seconds)
}
diff --git a/integration-tests/src/test/scala/play/libs/ws/ahc/AhcWSRequestFilterSpec.scala b/integration-tests/src/test/scala/play/libs/ws/ahc/AhcWSRequestFilterSpec.scala
index 49146c8c..33212913 100644
--- a/integration-tests/src/test/scala/play/libs/ws/ahc/AhcWSRequestFilterSpec.scala
+++ b/integration-tests/src/test/scala/play/libs/ws/ahc/AhcWSRequestFilterSpec.scala
@@ -4,34 +4,31 @@
package play.libs.ws.ahc
-import akka.http.scaladsl.model.ContentTypes
-import akka.http.scaladsl.model.HttpEntity
-import akka.http.scaladsl.model.headers.RawHeader
-import akka.http.scaladsl.server.Route
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.mutable.Specification
-import play.AkkaServerProvider
+import play.NettyServerProvider
+import play.api.BuiltInComponents
+import play.api.mvc.Results
import scala.concurrent.duration._
import scala.jdk.FutureConverters._
class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
extends Specification
- with AkkaServerProvider
+ with NettyServerProvider
with StandaloneWSClientSupport
with FutureMatchers {
- override val routes: Route = {
- import akka.http.scaladsl.server.Directives._
- headerValueByName("X-Request-Id") { value =>
- respondWithHeader(RawHeader("X-Request-Id", value)) {
- val httpEntity = HttpEntity(ContentTypes.`text/html(UTF-8)`, "Say hello to akka-http
")
- complete(httpEntity)
+ override def routes(components: BuiltInComponents) = { case _ =>
+ components.defaultActionBuilder { req =>
+ val res = Results
+ .Ok(
+ Say hello to play
+ )
+ req.headers.get("X-Request-Id").fold(res) { value =>
+ res.withHeaders(("X-Request-Id", value))
}
- } ~ {
- val httpEntity = HttpEntity(ContentTypes.`text/html(UTF-8)`, "Say hello to akka-http
")
- complete(httpEntity)
}
}
diff --git a/project/Dependencies.scala b/project/Dependencies.scala
index 5ee84c9a..d93c7d5c 100644
--- a/project/Dependencies.scala
+++ b/project/Dependencies.scala
@@ -43,7 +43,8 @@ object Dependencies {
val asyncHttpClient = Seq("org.asynchttpclient" % "async-http-client" % "2.12.3")
val akkaStreams = Seq("com.typesafe.akka" %% "akka-stream" % "2.6.20")
- val akkaHttp = Seq(("com.typesafe.akka" %% "akka-http" % "10.2.10").cross(CrossVersion.for3Use2_13))
+
+ val playNettyServer = Seq("com.typesafe.play" %% "play-netty-server" % "2.9.0-M4")
val reactiveStreams = Seq("org.reactivestreams" % "reactive-streams" % "1.0.4")