diff --git a/akka-docs/rst/java/code/docs/http/javadsl/server/directives/FileUploadDirectivesExamplesTest.java b/akka-docs/rst/java/code/docs/http/javadsl/server/directives/FileUploadDirectivesExamplesTest.java index 63324058e7..61a65f06e9 100644 --- a/akka-docs/rst/java/code/docs/http/javadsl/server/directives/FileUploadDirectivesExamplesTest.java +++ b/akka-docs/rst/java/code/docs/http/javadsl/server/directives/FileUploadDirectivesExamplesTest.java @@ -14,6 +14,9 @@ import akka.stream.javadsl.Source; import akka.util.ByteString; import org.junit.Ignore; import org.junit.Test; +import scala.concurrent.duration.Duration; +import scala.concurrent.duration.FiniteDuration; + import java.io.File; import java.nio.charset.Charset; import java.nio.file.Files; @@ -21,114 +24,117 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletionStage; +import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; public class FileUploadDirectivesExamplesTest extends JUnitRouteTest { - @Test - public void testUploadedFile() { - //#uploadedFile - // function (FileInfo, File) => Route to process the file metadata and file itself - BiFunction infoFileRoute = - (info, file) -> { - // do something with the file and file metadata ... - file.delete(); - return complete(StatusCodes.OK); - }; + @Test + public void testUploadedFile() { + //#uploadedFile + // function (FileInfo, File) => Route to process the file metadata and file itself + BiFunction infoFileRoute = + (info, file) -> { + // do something with the file and file metadata ... + file.delete(); + return complete(StatusCodes.OK); + }; - final Route route = uploadedFile("csv", infoFileRoute); + final Route route = uploadedFile("csv", infoFileRoute); - Map filenameMapping = new HashMap<>(); - filenameMapping.put("filename", "data.csv"); + Map filenameMapping = new HashMap<>(); + filenameMapping.put("filename", "data.csv"); - akka.http.javadsl.model.Multipart.FormData multipartForm = - Multiparts.createStrictFormDataFromParts(Multiparts.createFormDataBodyPartStrict("csv", - HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, - "1,5,7\n11,13,17"), filenameMapping)); + akka.http.javadsl.model.Multipart.FormData multipartForm = + Multiparts.createStrictFormDataFromParts(Multiparts.createFormDataBodyPartStrict("csv", + HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, + "1,5,7\n11,13,17"), filenameMapping)); - // test: - testRoute(route).run(HttpRequest.POST("/").withEntity( - multipartForm.toEntity(HttpCharsets.UTF_8, BodyPartRenderer - .randomBoundaryWithDefaults()))) - .assertStatusCode(StatusCodes.OK); - //# + // test: + testRoute(route).run(HttpRequest.POST("/") + .withEntity( + multipartForm.toEntity(HttpCharsets.UTF_8, + BodyPartRenderer + .randomBoundaryWithDefaults()))) + .assertStatusCode(StatusCodes.OK); + //# + } + + @Test + public void testFileUpload() { + //#fileUpload + final Route route = extractRequestContext(ctx -> { + // function (FileInfo, Source) => Route to process the file contents + BiFunction, Route> processUploadedFile = + (metadata, byteSource) -> { + CompletionStage sumF = byteSource.via(Framing.delimiter( + ByteString.fromString("\n"), 1024)) + .mapConcat(bs -> Arrays.asList(bs.utf8String().split(","))) + .map(s -> Integer.parseInt(s)) + .runFold(0, (acc, n) -> acc + n, ctx.getMaterializer()); + return onSuccess(() -> sumF, sum -> complete("Sum: " + sum)); + }; + return fileUpload("csv", processUploadedFile); + }); + + Map filenameMapping = new HashMap<>(); + filenameMapping.put("filename", "primes.csv"); + + akka.http.javadsl.model.Multipart.FormData multipartForm = + Multiparts.createStrictFormDataFromParts( + Multiparts.createFormDataBodyPartStrict("csv", + HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, + "2,3,5\n7,11,13,17,23\n29,31,37\n"), filenameMapping)); + + // test: + testRoute(route).run(HttpRequest.POST("/").withEntity( + multipartForm.toEntity(HttpCharsets.UTF_8, BodyPartRenderer.randomBoundaryWithDefaults()))) + .assertStatusCode(StatusCodes.OK).assertEntityAs(Unmarshaller.entityToString(), "Sum: 178"); + //# + } + + @Ignore("compileOnly") + @Test + public void testFileProcessing() { + //#fileProcessing + final Route route = extractRequestContext(ctx -> { + // function (FileInfo, Source) => Route to process the file contents + BiFunction, Route> processUploadedFile = + (metadata, byteSource) -> { + CompletionStage sumF = byteSource.via(Framing.delimiter( + ByteString.fromString("\n"), 1024)) + .mapConcat(bs -> Arrays.asList(bs.utf8String().split(","))) + .map(s -> Integer.parseInt(s)) + .runFold(0, (acc, n) -> acc + n, ctx.getMaterializer()); + return onSuccess(() -> sumF, sum -> complete("Sum: " + sum)); + }; + return fileUpload("csv", processUploadedFile); + }); + + Map filenameMapping = new HashMap<>(); + filenameMapping.put("filename", "primes.csv"); + + String prefix = "primes"; + String suffix = ".csv"; + + File tempFile = null; + try { + tempFile = File.createTempFile(prefix, suffix); + tempFile.deleteOnExit(); + Files.write(tempFile.toPath(), Arrays.asList("2,3,5", "7,11,13,17,23", "29,31,37"), Charset.forName("UTF-8")); + } catch (Exception e) { + // ignore } - @Test - public void testFileUpload() { - //#fileUpload - final Route route = extractRequestContext(ctx -> { - // function (FileInfo, Source) => Route to process the file contents - BiFunction, Route> processUploadedFile = - (metadata, byteSource) -> { - CompletionStage sumF = byteSource.via(Framing.delimiter( - ByteString.fromString("\n"), 1024)) - .mapConcat(bs -> Arrays.asList(bs.utf8String().split(","))) - .map(s -> Integer.parseInt(s)) - .runFold(0, (acc, n) -> acc + n, ctx.getMaterializer()); - return onSuccess(() -> sumF, sum -> complete("Sum: " + sum)); - }; - return fileUpload("csv", processUploadedFile); - }); - Map filenameMapping = new HashMap<>(); - filenameMapping.put("filename", "primes.csv"); + akka.http.javadsl.model.Multipart.FormData multipartForm = + Multiparts.createFormDataFromPath("csv", ContentTypes.TEXT_PLAIN_UTF8, tempFile.toPath()); - akka.http.javadsl.model.Multipart.FormData multipartForm = - Multiparts.createStrictFormDataFromParts( - Multiparts.createFormDataBodyPartStrict("csv", - HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, - "2,3,5\n7,11,13,17,23\n29,31,37\n"), filenameMapping)); - - // test: - testRoute(route).run(HttpRequest.POST("/").withEntity( - multipartForm.toEntity(HttpCharsets.UTF_8, BodyPartRenderer.randomBoundaryWithDefaults()))) - .assertStatusCode(StatusCodes.OK).assertEntityAs(Unmarshaller.entityToString(), "Sum: 178"); - //# - } - - @Ignore("compileOnly") - @Test - public void testFileProcessing() { - //#fileProcessing - final Route route = extractRequestContext(ctx -> { - // function (FileInfo, Source) => Route to process the file contents - BiFunction, Route> processUploadedFile = - (metadata, byteSource) -> { - CompletionStage sumF = byteSource.via(Framing.delimiter( - ByteString.fromString("\n"), 1024)) - .mapConcat(bs -> Arrays.asList(bs.utf8String().split(","))) - .map(s -> Integer.parseInt(s)) - .runFold(0, (acc, n) -> acc + n, ctx.getMaterializer()); - return onSuccess(() -> sumF, sum -> complete("Sum: " + sum)); - }; - return fileUpload("csv", processUploadedFile); - }); - - Map filenameMapping = new HashMap<>(); - filenameMapping.put("filename", "primes.csv"); - - String prefix = "primes"; - String suffix = ".csv"; - - File tempFile = null; - try { - tempFile = File.createTempFile(prefix, suffix); - tempFile.deleteOnExit(); - Files.write(tempFile.toPath(), Arrays.asList("2,3,5", "7,11,13,17,23", "29,31,37"), Charset.forName("UTF-8")); - } catch (Exception e) { - // ignore - } - - - akka.http.javadsl.model.Multipart.FormData multipartForm = - Multiparts.createFormDataFromPath("csv", ContentTypes.TEXT_PLAIN_UTF8, tempFile.toPath()); - - // test: - testRoute(route).run(HttpRequest.POST("/").withEntity( - multipartForm.toEntity(HttpCharsets.UTF_8, BodyPartRenderer.randomBoundaryWithDefaults()))) - .assertStatusCode(StatusCodes.OK).assertEntityAs(Unmarshaller.entityToString(), "Sum: 178"); - //# - } + // test: + testRoute(route).run(HttpRequest.POST("/").withEntity( + multipartForm.toEntity(HttpCharsets.UTF_8, BodyPartRenderer.randomBoundaryWithDefaults()))) + .assertStatusCode(StatusCodes.OK).assertEntityAs(Unmarshaller.entityToString(), "Sum: 178"); + //# + } } diff --git a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala index f5703d8f17..e6b9912d18 100644 --- a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala @@ -53,7 +53,7 @@ class ActorWithArgs(arg: String) extends Actor { //#actor-with-value-class-argument class Argument(val value: String) extends AnyVal class ValueClassActor(arg: Argument) extends Actor { - def receive = {case _ => () } + def receive = { case _ => () } } object ValueClassActor { diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/server/HttpServerBluePrint.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/server/HttpServerBluePrint.scala index ca5ea79999..9e6f78fd4a 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/server/HttpServerBluePrint.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/server/HttpServerBluePrint.scala @@ -415,9 +415,9 @@ private[http] object HttpServerBluePrint { val isEarlyResponse = messageEndPending && openRequests.isEmpty if (isEarlyResponse && response.status.isSuccess) log.warning( - "Sending an 2xx 'early' response before end of request was received... " + - "Note that the connection will be closed after this response. Also, many clients will not read early responses! " + - "Consider only issuing this response after the request data has been completely read!") + "Sending an 2xx 'early' response before end of request was received... " + + "Note that the connection will be closed after this response. Also, many clients will not read early responses! " + + "Consider only issuing this response after the request data has been completely read!") val close = requestStart.closeRequested || (requestStart.expect100Continue && oneHundredContinueResponsePending) || (isClosed(requestParsingIn) && openRequests.isEmpty) || diff --git a/akka-http-core/src/main/scala/akka/http/javadsl/settings/SettingsCompanion.scala b/akka-http-core/src/main/scala/akka/http/javadsl/settings/SettingsCompanion.scala index fbe12b6b90..e805fe0e35 100644 --- a/akka-http-core/src/main/scala/akka/http/javadsl/settings/SettingsCompanion.scala +++ b/akka-http-core/src/main/scala/akka/http/javadsl/settings/SettingsCompanion.scala @@ -9,7 +9,7 @@ trait SettingsCompanion[T] { /** * WARNING: This MUST overriden in sub-classes as otherwise won't be usable (return type) from Java. * Creates an instance of settings using the configuration provided by the given ActorSystem. - * + * * Java API */ def create(system: ActorSystem): T = create(system.settings.config) diff --git a/akka-http-testkit/src/main/scala/akka/http/javadsl/testkit/RouteTest.scala b/akka-http-testkit/src/main/scala/akka/http/javadsl/testkit/RouteTest.scala index 327dd75f47..e41ebed1b4 100644 --- a/akka-http-testkit/src/main/scala/akka/http/javadsl/testkit/RouteTest.scala +++ b/akka-http-testkit/src/main/scala/akka/http/javadsl/testkit/RouteTest.scala @@ -34,7 +34,7 @@ abstract class RouteTest extends AllDirectives { implicit def materializer: Materializer implicit def executionContext: ExecutionContextExecutor = system.dispatcher - protected def awaitDuration: FiniteDuration = 500.millis + protected def awaitDuration: FiniteDuration = 3.seconds protected def defaultHostInfo: DefaultHostInfo = DefaultHostInfo(Host.create("example.com"), false) diff --git a/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/MethodDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/MethodDirectivesSpec.scala index 3e83601175..5fdb50bf99 100644 --- a/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/MethodDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/MethodDirectivesSpec.scala @@ -40,7 +40,7 @@ class MethodDirectivesSpec extends RoutingSpec { Head() ~> headRoute ~> check { status shouldEqual StatusCodes.OK - val lengthF = response._3.dataBytes.runFold(0)((c, _) => c+1) + val lengthF = response._3.dataBytes.runFold(0)((c, _) ⇒ c + 1) val length = Await.result(lengthF, Duration(100, "millis")) length shouldEqual 0 } diff --git a/akka-http/src/main/scala/akka/http/scaladsl/server/directives/SecurityDirectives.scala b/akka-http/src/main/scala/akka/http/scaladsl/server/directives/SecurityDirectives.scala index b2a8cb0f7f..5a6b8d6bac 100644 --- a/akka-http/src/main/scala/akka/http/scaladsl/server/directives/SecurityDirectives.scala +++ b/akka-http/src/main/scala/akka/http/scaladsl/server/directives/SecurityDirectives.scala @@ -265,22 +265,22 @@ object Credentials { abstract case class Provided(identifier: String) extends Credentials { /** - * First applies the passed in `hasher` function to the received secret part of the Credentials - * and then safely compares the passed in `secret` with the hashed received secret. - * This method can be used if the secret is not stored in plain text. - * Use of this method instead of manual String equality testing is recommended in order to guard against timing attacks. - * - * See also [[EnhancedString#secure_==]], for more information. - */ + * First applies the passed in `hasher` function to the received secret part of the Credentials + * and then safely compares the passed in `secret` with the hashed received secret. + * This method can be used if the secret is not stored in plain text. + * Use of this method instead of manual String equality testing is recommended in order to guard against timing attacks. + * + * See also [[EnhancedString#secure_==]], for more information. + */ def verify(secret: String, hasher: String ⇒ String): Boolean - + /** * Safely compares the passed in `secret` with the received secret part of the Credentials. * Use of this method instead of manual String equality testing is recommended in order to guard against timing attacks. * * See also [[EnhancedString#secure_==]], for more information. */ - def verify(secret: String): Boolean = verify(secret, x => x) + def verify(secret: String): Boolean = verify(secret, x ⇒ x) } def apply(cred: Option[HttpCredentials]): Credentials = {