=doc,htc #19252 fix docs where occasionally broken
This commit is contained in:
parent
2f762c995b
commit
ff152b816d
8 changed files with 98 additions and 23 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
.. _migration-2.0-java:
|
.. _migration-2.0-java:
|
||||||
|
|
||||||
############################
|
##########################
|
||||||
Migration Guide 1.0 to 2.x
|
Migration Guide 1.0 to 2.x
|
||||||
############################
|
##########################
|
||||||
|
|
||||||
The 2.0 release contains some structural changes that require some
|
The 2.0 release contains some structural changes that require some
|
||||||
simple, mechanical source-level changes in client code. While these are detailed below,
|
simple, mechanical source-level changes in client code. While these are detailed below,
|
||||||
|
|
@ -80,6 +80,7 @@ Update procedure
|
||||||
``BidiFlow.fromFlows`` or ``BidiFlow.fromFlowsMat``
|
``BidiFlow.fromFlows`` or ``BidiFlow.fromFlowsMat``
|
||||||
5. Replace all uses of ``BidiFlow.apply()`` (Scala DSL) or ``BidiFlow.create()`` (Java DSL) when it converts two
|
5. Replace all uses of ``BidiFlow.apply()`` (Scala DSL) or ``BidiFlow.create()`` (Java DSL) when it converts two
|
||||||
functions to a ``BidiFlow`` with ``BidiFlow.fromFunctions``
|
functions to a ``BidiFlow`` with ``BidiFlow.fromFunctions``
|
||||||
|
|
||||||
Example
|
Example
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
|
|
||||||
|
|
@ -122,7 +123,7 @@ Should be replaced by
|
||||||
|
|
||||||
|
|
||||||
Renamed ``inlet()`` and ``outlet()`` to ``in()`` and ``out()`` in ``SourceShape``, ``SinkShape`` and ``FlowShape``
|
Renamed ``inlet()`` and ``outlet()`` to ``in()`` and ``out()`` in ``SourceShape``, ``SinkShape`` and ``FlowShape``
|
||||||
==========================================================================================================
|
==================================================================================================================
|
||||||
|
|
||||||
The input and output ports of these shapes where called ``inlet()`` and ``outlet()`` compared to other shapes that
|
The input and output ports of these shapes where called ``inlet()`` and ``outlet()`` compared to other shapes that
|
||||||
consistently used ``in()`` and ``out()``. Now all :class:`Shape` s use ``in()`` and ``out()``.
|
consistently used ``in()`` and ``out()``. Now all :class:`Shape` s use ``in()`` and ``out()``.
|
||||||
|
|
|
||||||
|
|
@ -194,8 +194,8 @@ turns an object into a sequence of bytes.
|
||||||
|
|
||||||
The other stage that we talked about is a little more involved since reversing
|
The other stage that we talked about is a little more involved since reversing
|
||||||
a framing protocol means that any received chunk of bytes may correspond to
|
a framing protocol means that any received chunk of bytes may correspond to
|
||||||
zero or more messages. This is best implemented using a :class:`PushPullStage`
|
zero or more messages. This is best implemented using a :class:`GraphStage`
|
||||||
(see also :ref:`stream-using-push-pull-stage-java`).
|
(see also :ref:`graphstage-java`).
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/BidiFlowDocTest.java#framing
|
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/BidiFlowDocTest.java#framing
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import scala.util.control.NonFatal
|
||||||
|
|
||||||
class BasicDirectivesExamplesSpec extends RoutingSpec {
|
class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
"0extract" in {
|
"0extract" in {
|
||||||
|
//#0extract
|
||||||
val uriLength = extract(_.request.uri.toString.length)
|
val uriLength = extract(_.request.uri.toString.length)
|
||||||
val route =
|
val route =
|
||||||
uriLength { len =>
|
uriLength { len =>
|
||||||
|
|
@ -32,8 +33,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/abcdef") ~> route ~> check {
|
Get("/abcdef") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "The length of the request URI is 25"
|
responseAs[String] shouldEqual "The length of the request URI is 25"
|
||||||
}
|
}
|
||||||
|
//#0extract
|
||||||
}
|
}
|
||||||
"0extractLog" in {
|
"0extractLog" in {
|
||||||
|
//#0extractLog
|
||||||
val route =
|
val route =
|
||||||
extractLog { log =>
|
extractLog { log =>
|
||||||
log.debug("I'm logging things in much detail..!")
|
log.debug("I'm logging things in much detail..!")
|
||||||
|
|
@ -44,8 +47,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/abcdef") ~> route ~> check {
|
Get("/abcdef") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "It's amazing!"
|
responseAs[String] shouldEqual "It's amazing!"
|
||||||
}
|
}
|
||||||
|
//#0extractLog
|
||||||
}
|
}
|
||||||
"withMaterializer-0" in {
|
"withMaterializer-0" in {
|
||||||
|
//#withMaterializer-0
|
||||||
val special = ActorMaterializer(namePrefix = Some("special"))
|
val special = ActorMaterializer(namePrefix = Some("special"))
|
||||||
|
|
||||||
def sample() =
|
def sample() =
|
||||||
|
|
@ -73,8 +78,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/special/sample") ~> route ~> check {
|
Get("/special/sample") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual s"Materialized by ${special.##}!"
|
responseAs[String] shouldEqual s"Materialized by ${special.##}!"
|
||||||
}
|
}
|
||||||
|
//#withMaterializer-0
|
||||||
}
|
}
|
||||||
"extractMaterializer-0" in {
|
"extractMaterializer-0" in {
|
||||||
|
//#extractMaterializer-0
|
||||||
val route =
|
val route =
|
||||||
path("sample") {
|
path("sample") {
|
||||||
extractMaterializer { materializer =>
|
extractMaterializer { materializer =>
|
||||||
|
|
@ -90,8 +97,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/sample") ~> route ~> check {
|
Get("/sample") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual s"Materialized by ${materializer.##}!"
|
responseAs[String] shouldEqual s"Materialized by ${materializer.##}!"
|
||||||
}
|
}
|
||||||
|
//#extractMaterializer-0
|
||||||
}
|
}
|
||||||
"withExecutionContext-0" in compileOnlySpec {
|
"withExecutionContext-0" in compileOnlySpec {
|
||||||
|
//#withExecutionContext-0
|
||||||
val special = system.dispatchers.lookup("special")
|
val special = system.dispatchers.lookup("special")
|
||||||
|
|
||||||
def sample() =
|
def sample() =
|
||||||
|
|
@ -117,8 +126,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/special/sample") ~> route ~> check {
|
Get("/special/sample") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual s"Run on ${special.##}!"
|
responseAs[String] shouldEqual s"Run on ${special.##}!"
|
||||||
}
|
}
|
||||||
|
//#withExecutionContext-0
|
||||||
}
|
}
|
||||||
"extractExecutionContext-0" in compileOnlySpec {
|
"extractExecutionContext-0" in compileOnlySpec {
|
||||||
|
//#extractExecutionContext-0
|
||||||
def sample() =
|
def sample() =
|
||||||
path("sample") {
|
path("sample") {
|
||||||
extractExecutionContext { implicit ec =>
|
extractExecutionContext { implicit ec =>
|
||||||
|
|
@ -137,8 +148,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/sample") ~> route ~> check {
|
Get("/sample") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual s"Run on ${system.dispatcher.##}!"
|
responseAs[String] shouldEqual s"Run on ${system.dispatcher.##}!"
|
||||||
}
|
}
|
||||||
|
//#extractExecutionContext-0
|
||||||
}
|
}
|
||||||
"0withLog" in {
|
"0withLog" in {
|
||||||
|
//#0withLog
|
||||||
val special = Logging(system, "SpecialRoutes")
|
val special = Logging(system, "SpecialRoutes")
|
||||||
|
|
||||||
def sample() =
|
def sample() =
|
||||||
|
|
@ -166,8 +179,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/special/sample") ~> route ~> check {
|
Get("/special/sample") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual s"Logging using $special!"
|
responseAs[String] shouldEqual s"Logging using $special!"
|
||||||
}
|
}
|
||||||
|
//#0withLog
|
||||||
}
|
}
|
||||||
"withSettings-0" in compileOnlySpec {
|
"withSettings-0" in compileOnlySpec {
|
||||||
|
//#withSettings-0
|
||||||
val special = RoutingSettings(system).copy(fileIODispatcher = "special-io-dispatcher")
|
val special = RoutingSettings(system).copy(fileIODispatcher = "special-io-dispatcher")
|
||||||
|
|
||||||
def sample() =
|
def sample() =
|
||||||
|
|
@ -195,8 +210,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/sample") ~> route ~> check {
|
Get("/sample") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "{}"
|
responseAs[String] shouldEqual "{}"
|
||||||
}
|
}
|
||||||
|
//#withSettings-0
|
||||||
}
|
}
|
||||||
"textract" in {
|
"textract" in {
|
||||||
|
//#textract
|
||||||
val pathAndQuery = textract { ctx =>
|
val pathAndQuery = textract { ctx =>
|
||||||
val uri = ctx.request.uri
|
val uri = ctx.request.uri
|
||||||
(uri.path, uri.query())
|
(uri.path, uri.query())
|
||||||
|
|
@ -210,8 +227,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/abcdef?ghi=12") ~> route ~> check {
|
Get("/abcdef?ghi=12") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "The path is /abcdef and the query is ghi=12"
|
responseAs[String] shouldEqual "The path is /abcdef and the query is ghi=12"
|
||||||
}
|
}
|
||||||
|
//#textract
|
||||||
}
|
}
|
||||||
"tprovide" in {
|
"tprovide" in {
|
||||||
|
//#tprovide
|
||||||
def provideStringAndLength(value: String) = tprovide((value, value.length))
|
def provideStringAndLength(value: String) = tprovide((value, value.length))
|
||||||
val route =
|
val route =
|
||||||
provideStringAndLength("test") { (value, len) =>
|
provideStringAndLength("test") { (value, len) =>
|
||||||
|
|
@ -222,8 +241,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "Value is test and its length is 4"
|
responseAs[String] shouldEqual "Value is test and its length is 4"
|
||||||
}
|
}
|
||||||
|
//#tprovide
|
||||||
}
|
}
|
||||||
"0mapResponse" in {
|
"0mapResponse" in {
|
||||||
|
//#0mapResponse
|
||||||
def overwriteResultStatus(response: HttpResponse): HttpResponse =
|
def overwriteResultStatus(response: HttpResponse): HttpResponse =
|
||||||
response.copy(status = StatusCodes.BadGateway)
|
response.copy(status = StatusCodes.BadGateway)
|
||||||
val route = mapResponse(overwriteResultStatus)(complete("abc"))
|
val route = mapResponse(overwriteResultStatus)(complete("abc"))
|
||||||
|
|
@ -232,6 +253,7 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/abcdef?ghi=12") ~> route ~> check {
|
Get("/abcdef?ghi=12") ~> route ~> check {
|
||||||
status shouldEqual StatusCodes.BadGateway
|
status shouldEqual StatusCodes.BadGateway
|
||||||
}
|
}
|
||||||
|
//#0mapResponse
|
||||||
}
|
}
|
||||||
"1mapResponse-advanced-json" in {
|
"1mapResponse-advanced-json" in {
|
||||||
//#1mapResponse-advanced
|
//#1mapResponse-advanced
|
||||||
|
|
@ -277,6 +299,7 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
//#1mapResponse-advanced
|
//#1mapResponse-advanced
|
||||||
}
|
}
|
||||||
"mapRouteResult" in {
|
"mapRouteResult" in {
|
||||||
|
//#mapRouteResult
|
||||||
// this directive is a joke, don't do that :-)
|
// this directive is a joke, don't do that :-)
|
||||||
val makeEverythingOk = mapRouteResult { r =>
|
val makeEverythingOk = mapRouteResult { r =>
|
||||||
r match {
|
r match {
|
||||||
|
|
@ -297,8 +320,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
status shouldEqual StatusCodes.OK
|
status shouldEqual StatusCodes.OK
|
||||||
}
|
}
|
||||||
|
//#mapRouteResult
|
||||||
}
|
}
|
||||||
"mapRouteResultFuture" in {
|
"mapRouteResultFuture" in {
|
||||||
|
//#mapRouteResultFuture
|
||||||
val tryRecoverAddServer = mapRouteResultFuture { fr =>
|
val tryRecoverAddServer = mapRouteResultFuture { fr =>
|
||||||
fr recover {
|
fr recover {
|
||||||
case ex: IllegalArgumentException =>
|
case ex: IllegalArgumentException =>
|
||||||
|
|
@ -319,8 +344,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
status shouldEqual StatusCodes.OK
|
status shouldEqual StatusCodes.OK
|
||||||
header[Server] shouldEqual Some(Server("MyServer 1.0"))
|
header[Server] shouldEqual Some(Server("MyServer 1.0"))
|
||||||
}
|
}
|
||||||
|
//#mapRouteResultFuture
|
||||||
}
|
}
|
||||||
"mapResponseEntity" in {
|
"mapResponseEntity" in {
|
||||||
|
//#mapResponseEntity
|
||||||
def prefixEntity(entity: ResponseEntity): ResponseEntity = entity match {
|
def prefixEntity(entity: ResponseEntity): ResponseEntity = entity match {
|
||||||
case HttpEntity.Strict(contentType, data) =>
|
case HttpEntity.Strict(contentType, data) =>
|
||||||
HttpEntity.Strict(contentType, ByteString("test") ++ data)
|
HttpEntity.Strict(contentType, ByteString("test") ++ data)
|
||||||
|
|
@ -334,8 +361,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "testabc"
|
responseAs[String] shouldEqual "testabc"
|
||||||
}
|
}
|
||||||
|
//#mapResponseEntity
|
||||||
}
|
}
|
||||||
"mapResponseHeaders" in {
|
"mapResponseHeaders" in {
|
||||||
|
//#mapResponseHeaders
|
||||||
// adds all request headers to the response
|
// adds all request headers to the response
|
||||||
val echoRequestHeaders = extract(_.request.headers).flatMap(respondWithHeaders)
|
val echoRequestHeaders = extract(_.request.headers).flatMap(respondWithHeaders)
|
||||||
|
|
||||||
|
|
@ -352,8 +381,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
header("id") shouldEqual None
|
header("id") shouldEqual None
|
||||||
header("id2").get.value shouldEqual "67890"
|
header("id2").get.value shouldEqual "67890"
|
||||||
}
|
}
|
||||||
|
//#mapResponseHeaders
|
||||||
}
|
}
|
||||||
"mapInnerRoute" in {
|
"mapInnerRoute" in {
|
||||||
|
//#mapInnerRoute
|
||||||
val completeWithInnerException =
|
val completeWithInnerException =
|
||||||
mapInnerRoute { route =>
|
mapInnerRoute { route =>
|
||||||
ctx =>
|
ctx =>
|
||||||
|
|
@ -373,8 +404,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "Got IllegalArgumentException 'BLIP! BLOP! Everything broke'"
|
responseAs[String] shouldEqual "Got IllegalArgumentException 'BLIP! BLOP! Everything broke'"
|
||||||
}
|
}
|
||||||
|
//#mapInnerRoute
|
||||||
}
|
}
|
||||||
"mapRejections" in {
|
"mapRejections" in {
|
||||||
|
//#mapRejections
|
||||||
// ignore any rejections and replace them by AuthorizationFailedRejection
|
// ignore any rejections and replace them by AuthorizationFailedRejection
|
||||||
val replaceByAuthorizationFailed = mapRejections(_ => List(AuthorizationFailedRejection))
|
val replaceByAuthorizationFailed = mapRejections(_ => List(AuthorizationFailedRejection))
|
||||||
val route =
|
val route =
|
||||||
|
|
@ -390,8 +423,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/abc") ~> route ~> check {
|
Get("/abc") ~> route ~> check {
|
||||||
status shouldEqual StatusCodes.OK
|
status shouldEqual StatusCodes.OK
|
||||||
}
|
}
|
||||||
|
//#mapRejections
|
||||||
}
|
}
|
||||||
"recoverRejections" in {
|
"recoverRejections" in {
|
||||||
|
//#recoverRejections
|
||||||
val authRejectionsToNothingToSeeHere = recoverRejections { rejections =>
|
val authRejectionsToNothingToSeeHere = recoverRejections { rejections =>
|
||||||
if (rejections.exists(_.isInstanceOf[AuthenticationFailedRejection]))
|
if (rejections.exists(_.isInstanceOf[AuthenticationFailedRejection]))
|
||||||
Complete(HttpResponse(entity = "Nothing to see here, move along."))
|
Complete(HttpResponse(entity = "Nothing to see here, move along."))
|
||||||
|
|
@ -432,8 +467,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
status shouldEqual StatusCodes.NotFound
|
status shouldEqual StatusCodes.NotFound
|
||||||
responseAs[String] shouldEqual "Literally nothing to see here."
|
responseAs[String] shouldEqual "Literally nothing to see here."
|
||||||
}
|
}
|
||||||
|
//#recoverRejections
|
||||||
}
|
}
|
||||||
"recoverRejectionsWith" in {
|
"recoverRejectionsWith" in {
|
||||||
|
//#recoverRejectionsWith
|
||||||
val authRejectionsToNothingToSeeHere = recoverRejectionsWith { rejections =>
|
val authRejectionsToNothingToSeeHere = recoverRejectionsWith { rejections =>
|
||||||
Future {
|
Future {
|
||||||
// imagine checking rejections takes a longer time:
|
// imagine checking rejections takes a longer time:
|
||||||
|
|
@ -461,8 +498,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
status shouldEqual StatusCodes.OK
|
status shouldEqual StatusCodes.OK
|
||||||
responseAs[String] shouldEqual "Nothing to see here, move along."
|
responseAs[String] shouldEqual "Nothing to see here, move along."
|
||||||
}
|
}
|
||||||
|
//#recoverRejectionsWith
|
||||||
}
|
}
|
||||||
"0mapRequest" in {
|
"0mapRequest" in {
|
||||||
|
//#0mapRequest
|
||||||
def transformToPostRequest(req: HttpRequest): HttpRequest = req.copy(method = HttpMethods.POST)
|
def transformToPostRequest(req: HttpRequest): HttpRequest = req.copy(method = HttpMethods.POST)
|
||||||
val route =
|
val route =
|
||||||
mapRequest(transformToPostRequest) {
|
mapRequest(transformToPostRequest) {
|
||||||
|
|
@ -474,8 +513,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "The request method was POST"
|
responseAs[String] shouldEqual "The request method was POST"
|
||||||
}
|
}
|
||||||
|
//#0mapRequest
|
||||||
}
|
}
|
||||||
"mapRequestContext" in {
|
"mapRequestContext" in {
|
||||||
|
//#mapRequestContext
|
||||||
val replaceRequest =
|
val replaceRequest =
|
||||||
mapRequestContext(_.withRequest(HttpRequest(HttpMethods.POST)))
|
mapRequestContext(_.withRequest(HttpRequest(HttpMethods.POST)))
|
||||||
|
|
||||||
|
|
@ -490,8 +531,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/abc/def/ghi") ~> route ~> check {
|
Get("/abc/def/ghi") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "POST"
|
responseAs[String] shouldEqual "POST"
|
||||||
}
|
}
|
||||||
|
//#mapRequestContext
|
||||||
}
|
}
|
||||||
"0mapRouteResult" in {
|
"0mapRouteResult" in {
|
||||||
|
//#0mapRouteResult
|
||||||
val rejectAll = // not particularly useful directive
|
val rejectAll = // not particularly useful directive
|
||||||
mapRouteResult {
|
mapRouteResult {
|
||||||
case _ => Rejected(List(AuthorizationFailedRejection))
|
case _ => Rejected(List(AuthorizationFailedRejection))
|
||||||
|
|
@ -505,8 +548,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
rejections.nonEmpty shouldEqual true
|
rejections.nonEmpty shouldEqual true
|
||||||
}
|
}
|
||||||
|
//#0mapRouteResult
|
||||||
}
|
}
|
||||||
"mapRouteResultPF" in {
|
"mapRouteResultPF" in {
|
||||||
|
//#mapRouteResultPF
|
||||||
case object MyCustomRejection extends Rejection
|
case object MyCustomRejection extends Rejection
|
||||||
val rejectRejections = // not particularly useful directive
|
val rejectRejections = // not particularly useful directive
|
||||||
mapRouteResultPF {
|
mapRouteResultPF {
|
||||||
|
|
@ -521,8 +566,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
rejection shouldEqual AuthorizationFailedRejection
|
rejection shouldEqual AuthorizationFailedRejection
|
||||||
}
|
}
|
||||||
|
//#mapRouteResultPF
|
||||||
}
|
}
|
||||||
"mapRouteResultWithPF-0" in {
|
"mapRouteResultWithPF-0" in {
|
||||||
|
//#mapRouteResultWithPF-0
|
||||||
case object MyCustomRejection extends Rejection
|
case object MyCustomRejection extends Rejection
|
||||||
val rejectRejections = // not particularly useful directive
|
val rejectRejections = // not particularly useful directive
|
||||||
mapRouteResultWithPF {
|
mapRouteResultWithPF {
|
||||||
|
|
@ -537,8 +584,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
rejection shouldEqual AuthorizationFailedRejection
|
rejection shouldEqual AuthorizationFailedRejection
|
||||||
}
|
}
|
||||||
|
//#mapRouteResultWithPF-0
|
||||||
}
|
}
|
||||||
"mapRouteResultWith-0" in {
|
"mapRouteResultWith-0" in {
|
||||||
|
//#mapRouteResultWith-0
|
||||||
case object MyCustomRejection extends Rejection
|
case object MyCustomRejection extends Rejection
|
||||||
val rejectRejections = // not particularly useful directive
|
val rejectRejections = // not particularly useful directive
|
||||||
mapRouteResultWith { res =>
|
mapRouteResultWith { res =>
|
||||||
|
|
@ -556,16 +605,20 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
rejection shouldEqual AuthorizationFailedRejection
|
rejection shouldEqual AuthorizationFailedRejection
|
||||||
}
|
}
|
||||||
|
//#mapRouteResultWith-0
|
||||||
}
|
}
|
||||||
"pass" in {
|
"pass" in {
|
||||||
|
//#pass
|
||||||
val route = pass(complete("abc"))
|
val route = pass(complete("abc"))
|
||||||
|
|
||||||
// tests:
|
// tests:
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "abc"
|
responseAs[String] shouldEqual "abc"
|
||||||
}
|
}
|
||||||
|
//#pass
|
||||||
}
|
}
|
||||||
"0provide" in {
|
"0provide" in {
|
||||||
|
//#0provide
|
||||||
def providePrefixedString(value: String): Directive1[String] = provide("prefix:" + value)
|
def providePrefixedString(value: String): Directive1[String] = provide("prefix:" + value)
|
||||||
val route =
|
val route =
|
||||||
providePrefixedString("test") { value =>
|
providePrefixedString("test") { value =>
|
||||||
|
|
@ -576,8 +629,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "prefix:test"
|
responseAs[String] shouldEqual "prefix:test"
|
||||||
}
|
}
|
||||||
|
//#0provide
|
||||||
}
|
}
|
||||||
"cancelRejections-filter-example" in {
|
"cancelRejections-filter-example" in {
|
||||||
|
//#cancelRejections-filter-example
|
||||||
def isMethodRejection: Rejection => Boolean = {
|
def isMethodRejection: Rejection => Boolean = {
|
||||||
case MethodRejection(_) => true
|
case MethodRejection(_) => true
|
||||||
case _ => false
|
case _ => false
|
||||||
|
|
@ -595,8 +650,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
rejections shouldEqual Nil
|
rejections shouldEqual Nil
|
||||||
handled shouldEqual false
|
handled shouldEqual false
|
||||||
}
|
}
|
||||||
|
//#cancelRejections-filter-example
|
||||||
}
|
}
|
||||||
"cancelRejection-example" in {
|
"cancelRejection-example" in {
|
||||||
|
//#cancelRejection-example
|
||||||
val route =
|
val route =
|
||||||
cancelRejection(MethodRejection(HttpMethods.POST)) {
|
cancelRejection(MethodRejection(HttpMethods.POST)) {
|
||||||
post {
|
post {
|
||||||
|
|
@ -609,8 +666,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
rejections shouldEqual Nil
|
rejections shouldEqual Nil
|
||||||
handled shouldEqual false
|
handled shouldEqual false
|
||||||
}
|
}
|
||||||
|
//#cancelRejection-example
|
||||||
}
|
}
|
||||||
"extractRequest-example" in {
|
"extractRequest-example" in {
|
||||||
|
//#extractRequest-example
|
||||||
val route =
|
val route =
|
||||||
extractRequest { request =>
|
extractRequest { request =>
|
||||||
complete(s"Request method is ${request.method.name} and content-type is ${request.entity.contentType}")
|
complete(s"Request method is ${request.method.name} and content-type is ${request.entity.contentType}")
|
||||||
|
|
@ -623,8 +682,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "Request method is GET and content-type is none/none"
|
responseAs[String] shouldEqual "Request method is GET and content-type is none/none"
|
||||||
}
|
}
|
||||||
|
//#extractRequest-example
|
||||||
}
|
}
|
||||||
"extractSettings-examples" in {
|
"extractSettings-examples" in {
|
||||||
|
//#extractSettings-examples
|
||||||
val route =
|
val route =
|
||||||
extractSettings { settings: RoutingSettings =>
|
extractSettings { settings: RoutingSettings =>
|
||||||
complete(s"RoutingSettings.renderVanityFooter = ${settings.renderVanityFooter}")
|
complete(s"RoutingSettings.renderVanityFooter = ${settings.renderVanityFooter}")
|
||||||
|
|
@ -634,8 +695,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual s"RoutingSettings.renderVanityFooter = true"
|
responseAs[String] shouldEqual s"RoutingSettings.renderVanityFooter = true"
|
||||||
}
|
}
|
||||||
|
//#extractSettings-examples
|
||||||
}
|
}
|
||||||
"mapSettings-examples" in {
|
"mapSettings-examples" in {
|
||||||
|
//#mapSettings-examples
|
||||||
val tunedSettings = mapSettings { settings =>
|
val tunedSettings = mapSettings { settings =>
|
||||||
settings.copy(fileGetConditional = false)
|
settings.copy(fileGetConditional = false)
|
||||||
}
|
}
|
||||||
|
|
@ -651,8 +714,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual s"RoutingSettings.fileGetConditional = false"
|
responseAs[String] shouldEqual s"RoutingSettings.fileGetConditional = false"
|
||||||
}
|
}
|
||||||
|
//#mapSettings-examples
|
||||||
}
|
}
|
||||||
"extractRequestContext-example" in {
|
"extractRequestContext-example" in {
|
||||||
|
//#extractRequestContext-example
|
||||||
val route =
|
val route =
|
||||||
extractRequestContext { ctx =>
|
extractRequestContext { ctx =>
|
||||||
ctx.log.debug("Using access to additional context availablethings, like the logger.")
|
ctx.log.debug("Using access to additional context availablethings, like the logger.")
|
||||||
|
|
@ -667,8 +732,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/") ~> route ~> check {
|
Get("/") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "Request method is GET and content-type is none/none"
|
responseAs[String] shouldEqual "Request method is GET and content-type is none/none"
|
||||||
}
|
}
|
||||||
|
//#extractRequestContext-example
|
||||||
}
|
}
|
||||||
"extractUri-example" in {
|
"extractUri-example" in {
|
||||||
|
//#extractUri-example
|
||||||
val route =
|
val route =
|
||||||
extractUri { uri =>
|
extractUri { uri =>
|
||||||
complete(s"Full URI: $uri")
|
complete(s"Full URI: $uri")
|
||||||
|
|
@ -682,8 +749,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/test") ~> route ~> check {
|
Get("/test") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "Full URI: http://example.com/test"
|
responseAs[String] shouldEqual "Full URI: http://example.com/test"
|
||||||
}
|
}
|
||||||
|
//#extractUri-example
|
||||||
}
|
}
|
||||||
"mapUnmatchedPath-example" in {
|
"mapUnmatchedPath-example" in {
|
||||||
|
//#mapUnmatchedPath-example
|
||||||
def ignore456(path: Uri.Path) = path match {
|
def ignore456(path: Uri.Path) = path match {
|
||||||
case s @ Uri.Path.Segment(head, tail) if head.startsWith("456") =>
|
case s @ Uri.Path.Segment(head, tail) if head.startsWith("456") =>
|
||||||
val newHead = head.drop(3)
|
val newHead = head.drop(3)
|
||||||
|
|
@ -709,8 +778,10 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/123456/abc") ~> route ~> check {
|
Get("/123456/abc") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "Content"
|
responseAs[String] shouldEqual "Content"
|
||||||
}
|
}
|
||||||
|
//#mapUnmatchedPath-example
|
||||||
}
|
}
|
||||||
"extractUnmatchedPath-example" in {
|
"extractUnmatchedPath-example" in {
|
||||||
|
//#extractUnmatchedPath-example
|
||||||
val route =
|
val route =
|
||||||
pathPrefix("abc") {
|
pathPrefix("abc") {
|
||||||
extractUnmatchedPath { remaining =>
|
extractUnmatchedPath { remaining =>
|
||||||
|
|
@ -725,6 +796,7 @@ class BasicDirectivesExamplesSpec extends RoutingSpec {
|
||||||
Get("/abc/456") ~> route ~> check {
|
Get("/abc/456") ~> route ~> check {
|
||||||
responseAs[String] shouldEqual "Unmatched: '/456'"
|
responseAs[String] shouldEqual "Unmatched: '/456'"
|
||||||
}
|
}
|
||||||
|
//#extractUnmatchedPath-example
|
||||||
}
|
}
|
||||||
|
|
||||||
private def compileOnlySpec(block: => Unit) = pending
|
private def compileOnlySpec(block: => Unit) = pending
|
||||||
|
|
|
||||||
|
|
@ -294,21 +294,21 @@ Because of the number of ways one may interact with headers (i.e. try to match a
|
||||||
or the other way around etc), a helper trait for custom Header types and their companions classes are provided by Akka HTTP.
|
or the other way around etc), a helper trait for custom Header types and their companions classes are provided by Akka HTTP.
|
||||||
Thanks to extending :class:`ModeledCustomHeader` instead of the plain ``CustomHeader`` such header can be matched
|
Thanks to extending :class:`ModeledCustomHeader` instead of the plain ``CustomHeader`` such header can be matched
|
||||||
|
|
||||||
.. includecode:: ../../../../../akka-http-tests/src/test/scala/akka/http/scaladsl/server/CustomHeaderRoutingSpec.scala
|
.. includecode:: ../../../../../akka-http-tests/src/test/scala/akka/http/scaladsl/server/ModeledCustomHeaderSpec.scala
|
||||||
:include: modeled-api-key-custom-header
|
:include: modeled-api-key-custom-header
|
||||||
|
|
||||||
Which allows the this CustomHeader to be used in the following scenarios:
|
Which allows the this CustomHeader to be used in the following scenarios:
|
||||||
|
|
||||||
.. includecode:: ../../../../../akka-http-tests/src/test/scala/akka/http/scaladsl/server/CustomHeaderRoutingSpec.scala
|
.. includecode:: ../../../../../akka-http-tests/src/test/scala/akka/http/scaladsl/server/ModeledCustomHeaderSpec.scala
|
||||||
:include: matching-examples
|
:include: matching-examples
|
||||||
|
|
||||||
Including usage within the header directives like in the following :ref:`-headerValuePF-` example:
|
Including usage within the header directives like in the following :ref:`-headerValuePF-` example:
|
||||||
|
|
||||||
.. includecode:: ../../../../../akka-http-tests/src/test/scala/akka/http/scaladsl/server/CustomHeaderRoutingSpec.scala
|
.. includecode:: ../../../../../akka-http-tests/src/test/scala/akka/http/scaladsl/server/ModeledCustomHeaderSpec.scala
|
||||||
:include: matching-in-routes
|
:include: matching-in-routes
|
||||||
|
|
||||||
One can also directly extend :class:`CustomHeader` which requires less boilerplate, however that has the downside of
|
One can also directly extend :class:`CustomHeader` which requires less boilerplate, however that has the downside of
|
||||||
matching against :ref:`RawHeader` instances not working out-of-the-box, thus limiting its usefulnes in the routing layer
|
matching against :class:`RawHeader` instances not working out-of-the-box, thus limiting its usefulnes in the routing layer
|
||||||
of Akka HTTP. For only rendering such header however it would be enough.
|
of Akka HTTP. For only rendering such header however it would be enough.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,10 @@ Description
|
||||||
-----------
|
-----------
|
||||||
A directive that passes the request unchanged to its inner route.
|
A directive that passes the request unchanged to its inner route.
|
||||||
|
|
||||||
|
|
||||||
It is usually used as a "neutral element" when combining directives generically.
|
It is usually used as a "neutral element" when combining directives generically.
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
||||||
.. includecode2:: ../../../../code/docs/http/scaladsl/server/directives/BasicDirectivesExamplesSpec.scala
|
.. includecode2:: ../../../../code/docs/http/scaladsl/server/directives/BasicDirectivesExamplesSpec.scala
|
||||||
:snippet: pass
|
:snippet: pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
.. _migration-2.0-scala:
|
.. _migration-2.0-scala:
|
||||||
|
|
||||||
############################
|
##########################
|
||||||
Migration Guide 1.0 to 2.x
|
Migration Guide 1.0 to 2.x
|
||||||
############################
|
##########################
|
||||||
|
|
||||||
The 2.0 release contains some structural changes that require some
|
The 2.0 release contains some structural changes that require some
|
||||||
simple, mechanical source-level changes in client code. While these are detailed below,
|
simple, mechanical source-level changes in client code. While these are detailed below,
|
||||||
|
|
@ -128,7 +128,7 @@ Should be replaced by
|
||||||
.. includecode:: code/docs/MigrationsScala.scala#bidiflow-wrap
|
.. includecode:: code/docs/MigrationsScala.scala#bidiflow-wrap
|
||||||
|
|
||||||
FlowGraph class and builder methods have been renamed
|
FlowGraph class and builder methods have been renamed
|
||||||
===========================================
|
=====================================================
|
||||||
|
|
||||||
Due to incorrect overlap with the :class:`Flow` concept we renamed the :class:`FlowGraph` class to :class:`GraphDSL`.
|
Due to incorrect overlap with the :class:`Flow` concept we renamed the :class:`FlowGraph` class to :class:`GraphDSL`.
|
||||||
There is now only one graph creation method called ``create`` which is analogous to the old ``partial`` method. For
|
There is now only one graph creation method called ``create`` which is analogous to the old ``partial`` method. For
|
||||||
|
|
@ -473,7 +473,7 @@ Update procedure
|
||||||
1. All custom shapes must use ``@uncheckedVariance`` on their ``Inlet`` and ``Outlet`` members.
|
1. All custom shapes must use ``@uncheckedVariance`` on their ``Inlet`` and ``Outlet`` members.
|
||||||
|
|
||||||
Renamed ``inlet()`` and ``outlet()`` to ``in()`` and ``out()`` in ``SourceShape``, ``SinkShape`` and ``FlowShape``
|
Renamed ``inlet()`` and ``outlet()`` to ``in()`` and ``out()`` in ``SourceShape``, ``SinkShape`` and ``FlowShape``
|
||||||
==========================================================================================================
|
==================================================================================================================
|
||||||
|
|
||||||
The input and output ports of these shapes where called ``inlet()`` and ``outlet()`` compared to other shapes that
|
The input and output ports of these shapes where called ``inlet()`` and ``outlet()`` compared to other shapes that
|
||||||
consistently used ``in()`` and ``out()``. Now all :class:`Shape` s use ``in()`` and ``out()``.
|
consistently used ``in()`` and ``out()``. Now all :class:`Shape` s use ``in()`` and ``out()``.
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ Sometimes it is not possible (or needed) to construct the entire computation gra
|
||||||
all of its different phases in different places and in the end connect them all into a complete graph and run it.
|
all of its different phases in different places and in the end connect them all into a complete graph and run it.
|
||||||
|
|
||||||
This can be achieved by returning a different ``Shape`` than ``ClosedShape``, for example ``FlowShape(in, out)``, from the
|
This can be achieved by returning a different ``Shape`` than ``ClosedShape``, for example ``FlowShape(in, out)``, from the
|
||||||
function given to ``GraphDSL.create``. See :ref:`predefined_shapes`) for a list of such predefined shapes.
|
function given to ``GraphDSL.create``. See :ref:`predefined-shapes`) for a list of such predefined shapes.
|
||||||
|
|
||||||
Making a ``Graph`` a :class:`RunnableGraph` requires all ports to be connected, and if they are not
|
Making a ``Graph`` a :class:`RunnableGraph` requires all ports to be connected, and if they are not
|
||||||
it will throw an exception at construction time, which helps to avoid simple
|
it will throw an exception at construction time, which helps to avoid simple
|
||||||
|
|
@ -180,9 +180,14 @@ of type ``O``. To represent this interface, we need to define a custom :class:`S
|
||||||
|
|
||||||
.. includecode:: code/docs/stream/FlowGraphDocSpec.scala#flow-graph-components-shape
|
.. includecode:: code/docs/stream/FlowGraphDocSpec.scala#flow-graph-components-shape
|
||||||
|
|
||||||
|
.. _predefined-shapes:
|
||||||
|
|
||||||
|
Predefined shapes
|
||||||
|
-----------------
|
||||||
|
|
||||||
In general a custom :class:`Shape` needs to be able to provide all its input and output ports, be able to copy itself, and also be
|
In general a custom :class:`Shape` needs to be able to provide all its input and output ports, be able to copy itself, and also be
|
||||||
able to create a new instance from given ports. There are some predefined shapes provided to avoid unnecessary
|
able to create a new instance from given ports. There are some predefined shapes provided to avoid unnecessary
|
||||||
boilerplate
|
boilerplate:
|
||||||
|
|
||||||
* :class:`SourceShape`, :class:`SinkShape`, :class:`FlowShape` for simpler shapes,
|
* :class:`SourceShape`, :class:`SinkShape`, :class:`FlowShape` for simpler shapes,
|
||||||
* :class:`UniformFanInShape` and :class:`UniformFanOutShape` for junctions with multiple input (or output) ports
|
* :class:`UniformFanInShape` and :class:`UniformFanOutShape` for junctions with multiple input (or output) ports
|
||||||
|
|
@ -246,8 +251,8 @@ turns an object into a sequence of bytes.
|
||||||
|
|
||||||
The other stage that we talked about is a little more involved since reversing
|
The other stage that we talked about is a little more involved since reversing
|
||||||
a framing protocol means that any received chunk of bytes may correspond to
|
a framing protocol means that any received chunk of bytes may correspond to
|
||||||
zero or more messages. This is best implemented using a :class:`PushPullStage`
|
zero or more messages. This is best implemented using a :class:`GraphStage`
|
||||||
(see also :ref:`stream-using-push-pull-stage-scala`).
|
(see also :ref:`graphstage-scala`).
|
||||||
|
|
||||||
.. includecode:: code/docs/stream/BidiFlowDocSpec.scala#framing
|
.. includecode:: code/docs/stream/BidiFlowDocSpec.scala#framing
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ logic in Flows and attaching those to :class:`StreamIO` in order to implement yo
|
||||||
|
|
||||||
In this example both client and server may need to close the stream based on a parsed command - ``BYE`` in the case
|
In this example both client and server may need to close the stream based on a parsed command - ``BYE`` in the case
|
||||||
of the server, and ``q`` in the case of the client. This is implemented by using a custom :class:`PushStage`
|
of the server, and ``q`` in the case of the client. This is implemented by using a custom :class:`PushStage`
|
||||||
(see :ref:`stream-using-push-pull-stage-scala`) which completes the stream once it encounters such command.
|
which completes the stream once it encounters such command.
|
||||||
|
|
||||||
Streaming File IO
|
Streaming File IO
|
||||||
=================
|
=================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue