Skip to content

Commit

Permalink
Merge branch 'playframework:main' into bump-ehcache
Browse files Browse the repository at this point in the history
  • Loading branch information
sdudzin committed May 3, 2024
2 parents e846478 + 2b2a5ca commit 429dcc1
Show file tree
Hide file tree
Showing 32 changed files with 65 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package play.api.http

import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletionStage

import scala.concurrent.duration.Duration
import scala.concurrent.Await
Expand Down Expand Up @@ -254,15 +255,15 @@ object HttpErrorHandlerSpec {
}

class CustomScalaErrorHandler extends HttpErrorHandler {
def onClientError(request: RequestHeader, statusCode: Int, message: String) =
def onClientError(request: RequestHeader, statusCode: Int, message: String): Future[Result] =
Future.successful(Results.Ok)
def onServerError(request: RequestHeader, exception: Throwable) =
def onServerError(request: RequestHeader, exception: Throwable): Future[Result] =
Future.successful(Results.Ok)
}

class CustomJavaErrorHandler extends play.http.HttpErrorHandler {
def onClientError(req: play.mvc.Http.RequestHeader, status: Int, msg: String) =
def onClientError(req: play.mvc.Http.RequestHeader, status: Int, msg: String): CompletionStage[play.mvc.Result] =
CompletableFuture.completedFuture(play.mvc.Results.ok())
def onServerError(req: play.mvc.Http.RequestHeader, exception: Throwable) =
def onServerError(req: play.mvc.Http.RequestHeader, exception: Throwable): CompletionStage[play.mvc.Result] =
CompletableFuture.completedFuture(play.mvc.Results.ok())
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import play.api.test._
class NettyServerIntegrationSpecificationSpec
extends ServerIntegrationSpecificationSpec
with NettyIntegrationSpecification {
override def expectedServerTag = Some("netty")
override def expectedServerTag: Option[String] = Some("netty")
}
class PekkoHttpServerIntegrationSpecificationSpec
extends ServerIntegrationSpecificationSpec
with PekkoHttpIntegrationSpecification {
override def expectedServerTag = None
override def expectedServerTag: Option[String] = None
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class SecuritySpec extends PlaySpecification {

def getUserInfoFromRequest(req: RequestHeader) = req.session.get("username")

def getUserFromRequest(req: RequestHeader) = req.session.get("user").map(User)
def getUserFromRequest(req: RequestHeader) = req.session.get("user").map(User.apply)

class AuthenticatedDbRequest[A](val user: User, val conn: Connection, request: Request[A])
extends WrappedRequest[A](request)

def Authenticated(implicit app: Application) = new ActionBuilder[AuthenticatedDbRequest, AnyContent] {
lazy val executionContext = app.materializer.executionContext
lazy val parser = app.injector.instanceOf[PlayBodyParsers].default
lazy val executionContext: ExecutionContext = app.materializer.executionContext
lazy val parser = app.injector.instanceOf[PlayBodyParsers].default
def invokeBlock[A](request: Request[A], block: (AuthenticatedDbRequest[A]) => Future[Result]) = {
val builder = AuthenticatedBuilder(req => getUserFromRequest(req), parser)(executionContext)
builder.authenticate(
Expand Down Expand Up @@ -100,7 +100,7 @@ class AuthMessagesRequest[A](val user: User, messagesApi: MessagesApi, request:
extends MessagesRequest[A](request, messagesApi)

class UserAuthenticatedBuilder(parser: BodyParser[AnyContent])(implicit ec: ExecutionContext)
extends AuthenticatedBuilder[User]({ (req: RequestHeader) => req.session.get("user").map(User) }, parser) {
extends AuthenticatedBuilder[User]({ (req: RequestHeader) => req.session.get("user").map(User.apply) }, parser) {
@Inject()
def this(parser: BodyParsers.Default)(implicit ec: ExecutionContext) = {
this(parser: BodyParser[AnyContent])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ trait BadClientHandlingSpec extends PlaySpecification with ServerIntegrationSpec
"allow accessing the raw unparsed path from an error handler" in withServer(new HttpErrorHandler() {
def onClientError(request: RequestHeader, statusCode: Int, message: String) =
Future.successful(Results.BadRequest("Bad path: " + request.path + " message: " + message))
def onServerError(request: RequestHeader, exception: Throwable) = Future.successful(Results.Ok)
def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = Future.successful(Results.Ok)
}) { port =>
val response = BasicHttpClient.makeRequests(port)(
BasicRequest("GET", "/[", "HTTP/1.1", Map(), "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class HttpErrorHandlingSpec
webCommandHandler = None,
filters = Seq(
new EssentialFilter {
def apply(next: EssentialAction) = {
def apply(next: EssentialAction): EssentialAction = {
throw new RuntimeException("filter exception!")
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@ class HttpErrorHandlingSpec
webCommandHandler = None,
filters = Seq(
new EssentialFilter {
def apply(next: EssentialAction) = {
def apply(next: EssentialAction): EssentialAction = {
throw new RuntimeException("filter exception!")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class JavaHttpErrorHandlingSpec
webCommandHandler = None,
filters = Seq(
new EssentialFilter {
def apply(next: EssentialAction) = {
def apply(next: EssentialAction): EssentialAction = {
throw new RuntimeException("filter exception!")
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ class JavaHttpErrorHandlingSpec
webCommandHandler = None,
filters = Seq(
new EssentialFilter {
def apply(next: EssentialAction) = {
def apply(next: EssentialAction): EssentialAction = {
throw new RuntimeException("filter exception!")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ trait JavaResultsHandlingSpec
}) { response => response.header(DATE) must beSome }

"work with non-standard HTTP response codes" in makeRequest(new MockController {
def action(request: Http.Request) = {
def action(request: Http.Request): Result = {
Results.status(498)
}
}) { response => response.status must beEqualTo(498) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import play.api.test.ApplicationFactory
import play.api.test.PlaySpecification
import play.api.test.ServerEndpointRecipe
import play.core.server.PekkoHttpServer
import play.core.server.Server
import play.core.server.ServerProvider
import play.it.test._

Expand Down Expand Up @@ -73,7 +74,7 @@ class PekkoHttpCustomServerProviderSpec
val customPekkoHttpEndpoint: ServerEndpointRecipe = PekkoHttp11Plaintext
.withDescription("Pekko HTTP HTTP/1.1 (plaintext, supports FOO)")
.withServerProvider(new ServerProvider {
def createServer(context: ServerProvider.Context) =
def createServer(context: ServerProvider.Context): Server =
new PekkoHttpServer(PekkoHttpServer.Context.fromServerProviderContext(context)) {
protected override def createParserSettings(): ParserSettings = {
super.createParserSettings().withCustomMethods(HttpMethod.custom("FOO"))
Expand All @@ -95,7 +96,7 @@ class PekkoHttpCustomServerProviderSpec
val customPekkoHttpEndpoint: ServerEndpointRecipe = PekkoHttp11Plaintext
.withDescription("Pekko HTTP HTTP/1.1 (plaintext, long headers)")
.withServerProvider(new ServerProvider {
def createServer(context: ServerProvider.Context) =
def createServer(context: ServerProvider.Context): Server =
new PekkoHttpServer(PekkoHttpServer.Context.fromServerProviderContext(context)) {
protected override def createParserSettings(): ParserSettings = {
super.createParserSettings().withMaxHeaderNameLength(100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ class CustomErrorHandler extends HttpErrorHandler {
.getOrElse("<not set>") + " / " + message
)
)
def onServerError(request: RequestHeader, exception: Throwable) =
def onServerError(request: RequestHeader, exception: Throwable): Future[Result] =
Future.successful(Results.BadRequest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ object WebSocketClient {
*/
def connect(url: URI, version: WebSocketVersion, subprotocol: Option[String])(
onConnected: (immutable.Seq[(String, String)], Flow[ExtendedMessage, ExtendedMessage, ?]) => Unit
) = {
): Future[?] = {
val normalized = url.normalize()
val tgt = if (normalized.getPath == null || normalized.getPath.trim().isEmpty) {
new URI(normalized.getScheme, normalized.getAuthority, "/", normalized.getQuery, normalized.getFragment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.apache.pekko.actor.Props
import org.apache.pekko.actor.Status
import org.apache.pekko.stream.scaladsl._
import org.apache.pekko.util.ByteString
import org.apache.pekko.util.Timeout
import org.specs2.execute.AsResult
import org.specs2.execute.EventuallyResults
import org.specs2.matcher.Matcher
Expand Down Expand Up @@ -343,7 +344,7 @@ trait WebSocketSpec
Props(new Actor() {
messages.foreach { msg => out ! msg }
out ! Status.Success(())
def receive = PartialFunction.empty
def receive: Actor.Receive = PartialFunction.empty
})
}
}
Expand All @@ -356,7 +357,7 @@ trait WebSocketSpec
ActorFlow.actorRef { out =>
Props(new Actor() {
system.scheduler.scheduleOnce(10.millis, out, Status.Success(()))
def receive = PartialFunction.empty
def receive: Actor.Receive = PartialFunction.empty
})
}
}
Expand All @@ -382,7 +383,7 @@ trait WebSocketSpec
WebSocket.accept[String, String] { req =>
ActorFlow.actorRef { out =>
Props(new Actor() {
def receive = PartialFunction.empty
def receive: Actor.Receive = PartialFunction.empty
override def postStop() = {
cleanedUp.success(true)
}
Expand Down Expand Up @@ -441,7 +442,7 @@ trait WebSocketSpecMethods extends PlaySpecification with WsTestClient with Serv
import scala.jdk.CollectionConverters._

// Extend the default spec timeout for CI.
implicit override def defaultAwaitTimeout = 10.seconds
implicit override def defaultAwaitTimeout: Timeout = 10.seconds

protected override def shouldRunSequentially(app: Application): Boolean = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ trait FiltersSpec extends Specification with ServerIntegrationSpecification {
def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
Future.successful(Results.NotFound(request.headers.get(filterAddedHeaderKey).getOrElse("undefined header")))
}
def onServerError(request: RequestHeader, exception: Throwable) = Future.successful(Results.InternalServerError)
def onServerError(request: RequestHeader, exception: Throwable): Future[Result] =
Future.successful(Results.InternalServerError)
}

"requests not matching a route should receive a RequestHeader modified by upstream filters" in withServer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ object HttpBinApplication {
new BuiltInComponentsFromContext(ApplicationLoader.Context.create(Environment.simple()))
with AhcWSComponents
with NoHttpFiltersComponents {
implicit override lazy val Action = defaultActionBuilder
implicit override lazy val Action: DefaultActionBuilder = defaultActionBuilder
override def router = SimpleRouter(
PartialFunction.empty
.orElse(getIp)
Expand Down
2 changes: 1 addition & 1 deletion core/play/src/test/scala/play/mvc/StatusHeaderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class StatusHeaderSpec extends TestKit(ActorSystem("StatusHeaderSpec")) with Spe
val materializer = Materializer.matFromSystem

Json.mapper.getFactory.setCharacterEscapes(new CharacterEscapes {
override def getEscapeSequence(ch: Int) = new SerializedString(f"\\u$ch%04x")
override def getEscapeSequence(ch: Int): SerializedString = new SerializedString(f"\\u$ch%04x")

override def getEscapeCodesForAscii: Array[Int] =
CharacterEscapes.standardAsciiEscapesForJSON.zipWithIndex.map {
Expand Down
4 changes: 2 additions & 2 deletions documentation/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ lazy val main = Project("Play-Documentation", file("."))
Test / unmanagedResourceDirectories ++= (baseDirectory.value / "manual" / "detailedTopics" ** "code").get,
// Don't include sbt files in the resources
Test / unmanagedResources / excludeFilter := (Test / unmanagedResources / excludeFilter).value || "*.sbt",
crossScalaVersions := Seq("2.13.13", "3.3.3"),
scalaVersion := "2.13.13",
crossScalaVersions := Seq("2.13.14", "3.3.3"),
scalaVersion := "2.13.14",
Test / fork := true,
Test / javaOptions ++= Seq("-Xmx512m", "-Xms128m"),
headerLicense := Some(
Expand Down
2 changes: 1 addition & 1 deletion documentation/manual/hacking/BuildingFromSource.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This will build and publish Play for the default Scala version. If you want to p
Or to publish for a specific Scala version:

```bash
> ++ 2.13.13 publishLocal
> ++ 2.13.14 publishLocal
```

## Build the documentation
Expand Down
2 changes: 1 addition & 1 deletion documentation/manual/releases/release27/Highlights27.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ scalaVersion := "2.11.12"
For Scala 2.13:

```scala
scalaVersion := "2.13.13"
scalaVersion := "2.13.14"
```

## Lifecycle managed by Akka's Coordinated Shutdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ Play 2.8 support Scala 2.12 and 2.13, but not 2.11, which has reached its end of
To set the Scala version in sbt, simply set the `scalaVersion` key, for example:

```scala
scalaVersion := "2.13.13"
scalaVersion := "2.13.14"
```

If you have a single project build, then this setting can just be placed on its own line in `build.sbt`. However, if you have a multi-project build, then the scala version setting must be set on each project. Typically, in a multi-project build, you will have some common settings shared by every project, this is the best place to put the setting, for example:

```scala
def commonSettings = Seq(
scalaVersion := "2.13.13"
scalaVersion := "2.13.14"
)

val projectA = (project in file("projectA"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Play 2.9 supports Scala 2.13 and Scala 3.3, but not 2.12 anymore. Scala 3 requir
To set the Scala version in sbt, simply set the `scalaVersion` key, for example:

```scala
scalaVersion := "2.13.13"
scalaVersion := "2.13.14"
```

Play 2.9 also supports Scala 3:
Expand All @@ -77,7 +77,7 @@ If you have a single project build, then this setting can just be placed on its

```scala
def commonSettings = Seq(
scalaVersion := "2.13.13"
scalaVersion := "2.13.14"
)

val projectA = (project in file("projectA"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ If you use `groupID %% artifactID % revision` rather than `groupID % artifactID

@[explicit-scala-version-dep](code/dependencies.sbt)

Assuming the `scalaVersion` for your build is `2.13.13`, the following is identical (note the double `%%` after `"org.scala-tools"`):
Assuming the `scalaVersion` for your build is `2.13.14`, the following is identical (note the double `%%` after `"org.scala-tools"`):

@[auto-scala-version-dep](code/dependencies.sbt)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class EvolutionsSpec extends Specification {
connection.createStatement.execute(sql)
}.get

def after = {
def after: Any = {
database.shutdown()
}
}
Expand Down
8 changes: 0 additions & 8 deletions project/PlayBuildBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ object PlayBuildBase extends AutoPlugin {
case Some((2, 13)) => Seq("-Xsource:3")
case _ => Seq.empty
}),
Test / scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) =>
Seq("-Xmigration:2.13")
case _ =>
Seq.empty
}
},
javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:-options"),
resolvers ++= {
if (isSnapshot.value) {
Expand Down
2 changes: 1 addition & 1 deletion project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

object ScalaVersions {
val scala212 = "2.12.19"
val scala213 = "2.13.13"
val scala213 = "2.13.14"
val scala3 = "3.3.3"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ class FakeServer(context: ServerProvider.Context) extends Server with Reloadable
}

class FakeServerProvider extends ServerProvider {
override def createServer(context: ServerProvider.Context) = new FakeServer(context)
override def createServer(context: ServerProvider.Context): Server = new FakeServer(context)
}

class StartupErrorServerProvider extends ServerProvider {
override def createServer(context: ServerProvider.Context) = throw new Exception("server fails to start")
override def createServer(context: ServerProvider.Context): Server = throw new Exception("server fails to start")
}

class ProdServerStartSpec extends Specification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import javax.inject.Inject
import play.api.http.HttpFilters
import play.api.inject.bind
import play.api.mvc.DefaultActionBuilder
import play.api.mvc.EssentialFilter
import play.api.mvc.Results
import play.api.routing.sird._
import play.api.routing.Router
Expand All @@ -19,7 +20,7 @@ import play.mvc.Http.HeaderNames._

object CORSFilterSpec {
class Filters @Inject() (corsFilter: CORSFilter) extends HttpFilters {
def filters = Seq(corsFilter)
def filters: Seq[EssentialFilter] = Seq(corsFilter)
}

class CorsApplicationRouter @Inject() (action: DefaultActionBuilder)
Expand Down

0 comments on commit 429dcc1

Please sign in to comment.