Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 6 additions & 32 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ lazy val `shaded-asynchttpclient` = project
assembly / logLevel := Level.Error,
assembly / assemblyMergeStrategy := {
val NettyPropertiesPath = "META-INF" + File.separator + "io.netty.versions.properties"
val ModuleInfoClass = "META-INF" + File.separator + "versions" + File.separator + "9" + File.separator + "module-info.class"
val mergeStrategy: String => MergeStrategy = {
case ModuleInfoClass =>
MergeStrategy.discard

case NettyPropertiesPath =>
MergeStrategy.first

Expand Down Expand Up @@ -212,47 +216,18 @@ lazy val `shaded-asynchttpclient` = project
Compile / packageBin := assembly.value
)

//---------------------------------------------------------------
// Shaded oauth
//---------------------------------------------------------------

lazy val `shaded-oauth` = project
.in(file("shaded/oauth"))
.disablePlugins(MimaPlugin)
.settings(commonSettings)
.settings(shadeAssemblySettings)
.settings(
libraryDependencies ++= oauth,
name := "shaded-oauth",
// logLevel in assembly := Level.Debug,
assembly / assemblyShadeRules := Seq(
ShadeRule.rename("oauth.**" -> "play.shaded.oauth.@0").inAll,
ShadeRule.rename("org.apache.commons.**" -> "play.shaded.oauth.@0").inAll
),
// https://stackoverflow.com/questions/24807875/how-to-remove-projectdependencies-from-pom
// Remove dependencies from the POM because we have a FAT jar here.
makePomConfiguration := makePomConfiguration.value.withProcess(process = dependenciesFilter),
assembly / assemblyOption := (assembly / assemblyOption).value.withIncludeBin(false).withIncludeScala(false),
Compile / packageBin := assembly.value
)

// Make the shaded version of AHC available downstream
val shadedAhcSettings = Seq(
Compile / unmanagedJars += (`shaded-asynchttpclient` / Compile / packageBin).value
)

val shadedOAuthSettings = Seq(
Compile / unmanagedJars += (`shaded-oauth` / Compile / packageBin).value
)

//---------------------------------------------------------------
// Shaded aggregate project
//---------------------------------------------------------------

lazy val shaded = Project(id = "shaded", base = file("shaded"))
.aggregate(
`shaded-asynchttpclient`,
`shaded-oauth`
`shaded-asynchttpclient`
)
.disablePlugins(sbtassembly.AssemblyPlugin, HeaderPlugin, MimaPlugin)
.settings(
Expand Down Expand Up @@ -296,7 +271,7 @@ def addShadedDeps(deps: Seq[xml.Node], node: xml.Node): xml.Node = {
lazy val `play-ahc-ws-standalone` = project
.in(file("play-ahc-ws-standalone"))
.settings(
commonSettings ++ shadedAhcSettings ++ shadedOAuthSettings ++ Seq(
commonSettings ++ shadedAhcSettings ++ Seq(
Test / fork := true,
Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v")),
libraryDependencies ++= standaloneAhcWSDependencies,
Expand Down Expand Up @@ -381,7 +356,6 @@ lazy val `integration-tests` = project
libraryDependencies ++= backendServerTestDependencies ++ testDependencies,
)
.settings(shadedAhcSettings)
.settings(shadedOAuthSettings)
.dependsOn(
`play-ahc-ws-standalone`,
`play-ws-standalone-json`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@

package play.api.libs.ws.ahc

import org.apache.pekko.stream.scaladsl.Sink
import org.apache.pekko.util.ByteString
import org.specs2.concurrent.ExecutionEnv
import org.specs2.concurrent.FutureAwait
import org.specs2.concurrent.{ExecutionEnv, FutureAwait}
import org.specs2.execute.Result
import org.specs2.matcher.FutureMatchers
import org.specs2.mutable.Specification
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.mvc.{Cookie, Handler, RequestHeader, Results}
import play.api.routing.sird._
import play.shaded.ahc.org.asynchttpclient.handler.MaxRedirectException

Expand Down Expand Up @@ -133,7 +127,7 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
case class Foo(body: String)

implicit val fooBodyReadable: BodyReadable[Foo] = BodyReadable[Foo] { response =>
import play.shaded.ahc.org.asynchttpclient.{ Response => AHCResponse }
import play.shaded.ahc.org.asynchttpclient.{Response => AHCResponse}
val ahcResponse = response.asInstanceOf[StandaloneAhcWSResponse].underlying[AHCResponse]
Foo(ahcResponse.getResponseBody)
}
Expand All @@ -147,17 +141,6 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
}
}

"request a url as a stream" in {
withClient() { client =>
val resultSource = Await.result(
client.url(s"http://localhost:$testServerPort/index").stream().map(_.bodyAsSource),
defaultTimeout
)
val bytes: ByteString = Await.result(resultSource.runWith(Sink.head), defaultTimeout)
bytes.utf8String must beEqualTo("Say hello to play")
}
}

"when following redirect" in {

"honor the number of redirects allowed" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
.await(retries = 0, timeout = defaultTimeout)
}

"stream with adhoc request filter" in withClient() { client =>
client
.url(s"http://localhost:$testServerPort")
.withRequestFilter(WSRequestFilter { e =>
WSRequestExecutor(r => e.apply(r.withQueryStringParameters("key" -> "some string")))
})
.withMethod("GET")
.stream()
.map { response =>
response.body[String] must contain("some string")
}
.await(retries = 0, timeout = defaultTimeout)
}

"work with one request filter" in withClient() { client =>
val callList = scala.collection.mutable.ArrayBuffer[Int]()
client
Expand All @@ -98,19 +84,6 @@ class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
.await(retries = 0, timeout = defaultTimeout)
}

"stream with one request filter" in withClient() { client =>
val callList = scala.collection.mutable.ArrayBuffer[Int]()
client
.url(s"http://localhost:$testServerPort")
.withRequestFilter(new CallbackRequestFilter(callList, 1))
.withMethod("GET")
.stream()
.map { _ =>
callList must contain(1)
}
.await(retries = 0, timeout = defaultTimeout)
}

"work with three request filter" in withClient() { client =>
val callList = scala.collection.mutable.ArrayBuffer[Int]()
client
Expand All @@ -125,21 +98,6 @@ class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
.await(retries = 0, timeout = defaultTimeout)
}

"stream with three request filters" in withClient() { client =>
val callList = scala.collection.mutable.ArrayBuffer[Int]()
client
.url(s"http://localhost:$testServerPort")
.withRequestFilter(new CallbackRequestFilter(callList, 1))
.withRequestFilter(new CallbackRequestFilter(callList, 2))
.withRequestFilter(new CallbackRequestFilter(callList, 3))
.withMethod("GET")
.stream()
.map { _ =>
callList must containTheSameElementsAs(Seq(1, 2, 3))
}
.await(retries = 0, timeout = defaultTimeout)
}

"should allow filters to modify the request" in withClient() { client =>
val appendedHeader = "X-Request-Id"
val appendedHeaderValue = "someid"
Expand All @@ -153,18 +111,5 @@ class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
.await(retries = 0, timeout = defaultTimeout)
}

"allow filters to modify the streaming request" in withClient() { client =>
val appendedHeader = "X-Request-Id"
val appendedHeaderValue = "someid"
client
.url(s"http://localhost:$testServerPort")
.withRequestFilter(new HeaderAppendingFilter(appendedHeader, appendedHeaderValue))
.withMethod("GET")
.stream()
.map { response =>
response.headers("X-Request-Id").head must be_==("someid")
}
.await(retries = 0, timeout = defaultTimeout)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@

package play.libs.ws.ahc

import org.apache.pekko.stream.javadsl.Sink
import org.apache.pekko.util.ByteString
import org.specs2.concurrent.ExecutionEnv
import org.specs2.matcher.FutureMatchers
import org.specs2.mutable.Specification
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.mvc.{AnyContentAsText, AnyContentAsXml, Results}
import play.api.routing.sird._
import play.libs.ws._

import scala.jdk.FutureConverters._
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.jdk.FutureConverters._

class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
extends Specification
Expand Down Expand Up @@ -63,15 +58,6 @@ class AhcWSClientSpec(implicit val executionEnv: ExecutionEnv)
.await(retries = 0, timeout = 5.seconds)
}

"source successfully" in withClient() { client =>
val future = client.url(s"http://localhost:$testServerPort").stream().asScala
val result: Future[ByteString] = future.flatMap { (response: StandaloneWSResponse) =>
response.getBodyAsSource.runWith(Sink.head[ByteString](), materializer).asScala
}
val expected: ByteString = ByteString.fromString("<h1>Say hello to play</h1>")
result must be_==(expected).await(retries = 0, timeout = 5.seconds)
}

"round trip XML successfully" in withClient() { client =>
val document = XML.fromString("""<?xml version="1.0" encoding='UTF-8'?>
|<note>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
.await(retries = 0, timeout = 5.seconds)
}

"stream with one request filter" in withClient() { client =>
import scala.jdk.CollectionConverters._
val callList = new java.util.ArrayList[Integer]()
val responseFuture =
client
.url(s"http://localhost:$testServerPort")
.setRequestFilter(new CallbackRequestFilter(callList, 1))
.stream()
.asScala
responseFuture
.map { _ =>
callList.asScala must contain(1)
}
.await(retries = 0, timeout = 5.seconds)
}

"work with three request filter" in withClient() { client =>
import scala.jdk.CollectionConverters._
val callList = new java.util.ArrayList[Integer]()
Expand All @@ -84,24 +68,6 @@ class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
.await(retries = 0, timeout = 5.seconds)
}

"stream with three request filters" in withClient() { client =>
import scala.jdk.CollectionConverters._
val callList = new java.util.ArrayList[Integer]()
val responseFuture =
client
.url(s"http://localhost:$testServerPort")
.setRequestFilter(new CallbackRequestFilter(callList, 1))
.setRequestFilter(new CallbackRequestFilter(callList, 2))
.setRequestFilter(new CallbackRequestFilter(callList, 3))
.stream()
.asScala
responseFuture
.map { _ =>
callList.asScala must containTheSameElementsAs(Seq(1, 2, 3))
}
.await(retries = 0, timeout = 5.seconds)
}

"should allow filters to modify the request" in withClient() { client =>
val appendedHeader = "X-Request-Id"
val appendedHeaderValue = "someid"
Expand All @@ -118,22 +84,5 @@ class AhcWSRequestFilterSpec(implicit val executionEnv: ExecutionEnv)
}
.await(retries = 0, timeout = 5.seconds)
}

"allow filters to modify the streaming request" in withClient() { client =>
val appendedHeader = "X-Request-Id"
val appendedHeaderValue = "someid"
val responseFuture =
client
.url(s"http://localhost:$testServerPort")
.setRequestFilter(new HeaderAppendingFilter(appendedHeader, appendedHeaderValue))
.stream()
.asScala

responseFuture
.map { response =>
response.getHeaders.get("X-Request-Id").get(0) must be_==("someid")
}
.await(retries = 0, timeout = 5.seconds)
}
}
}
Loading
Loading