From d25b3af2527cf547778919eb9cb48d249c79a8aa Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Fri, 24 Apr 2015 16:51:10 +0200 Subject: [PATCH] !htc move ServerSettings and ParserSettings up a package to make them accessible both from the java and scala side This follow the example from akka.stream. --- .../engine/parsing => }/ParserSettings.scala | 28 ++++++++++++- .../http/{scaladsl => }/ServerSettings.scala | 39 +++++++++++++------ .../client/ClientConnectionSettings.scala | 2 +- .../engine/parsing/HttpMessageParser.scala | 2 + .../engine/parsing/HttpRequestParser.scala | 2 + .../engine/parsing/HttpResponseParser.scala | 2 + .../http/impl/engine/parsing/package.scala | 2 + .../engine/server/HttpServerBluePrint.scala | 2 +- .../main/scala/akka/http/javadsl/Http.scala | 4 +- .../main/scala/akka/http/scaladsl/Http.scala | 1 + .../engine/client/ConnectionPoolSpec.scala | 4 +- .../engine/parsing/HttpHeaderParserSpec.scala | 1 + .../parsing/HttpHeaderParserTestBed.scala | 1 + .../engine/parsing/RequestParserSpec.scala | 1 + .../engine/parsing/ResponseParserSpec.scala | 1 + .../impl/engine/server/HttpServerSpec.scala | 3 +- .../akka/http/scaladsl/ClientServerSpec.scala | 1 + 17 files changed, 78 insertions(+), 18 deletions(-) rename akka-http-core/src/main/scala/akka/http/{impl/engine/parsing => }/ParserSettings.scala (80%) rename akka-http-core/src/main/scala/akka/http/{scaladsl => }/ServerSettings.scala (72%) diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/ParserSettings.scala b/akka-http-core/src/main/scala/akka/http/ParserSettings.scala similarity index 80% rename from akka-http-core/src/main/scala/akka/http/impl/engine/parsing/ParserSettings.scala rename to akka-http-core/src/main/scala/akka/http/ParserSettings.scala index 217d73b619..63e424b4b4 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/ParserSettings.scala +++ b/akka-http-core/src/main/scala/akka/http/ParserSettings.scala @@ -2,13 +2,15 @@ * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.http.impl.engine.parsing +package akka.http import java.util.Locale +import akka.actor.ActorSystem import com.typesafe.config.Config import scala.collection.JavaConverters._ import akka.http.scaladsl.model.{ StatusCode, HttpMethod, Uri } import akka.http.impl.util._ +import akka.http.impl.engine.parsing.HttpHeaderParser final case class ParserSettings( maxUriLength: Int, @@ -88,5 +90,29 @@ object ParserSettings extends SettingsCompanion[ParserSettings]("akka.http.parsi case x ⇒ throw new IllegalArgumentException(s"[$x] is not a legal `error-logging-verbosity` setting") } } + + /** + * Creates an instance of ParserSettings using the configuration provided by the given + * ActorSystem. + * + * Java API + */ + def create(system: ActorSystem): ParserSettings = ParserSettings(system) + + /** + * Creates an instance of ParserSettings using the given Config. + * + * Java API + */ + def create(config: Config): ParserSettings = ParserSettings(config) + + /** + * Create an instance of ParserSettings using the given String of config overrides to override + * settings set in the class loader of this class (i.e. by application.conf or reference.conf files in + * the class loader of this class). + * + * Java API + */ + def create(configOverrides: String): ParserSettings = ParserSettings(configOverrides) } diff --git a/akka-http-core/src/main/scala/akka/http/scaladsl/ServerSettings.scala b/akka-http-core/src/main/scala/akka/http/ServerSettings.scala similarity index 72% rename from akka-http-core/src/main/scala/akka/http/scaladsl/ServerSettings.scala rename to akka-http-core/src/main/scala/akka/http/ServerSettings.scala index b3b9b91d11..6ab673445a 100644 --- a/akka-http-core/src/main/scala/akka/http/scaladsl/ServerSettings.scala +++ b/akka-http-core/src/main/scala/akka/http/ServerSettings.scala @@ -2,17 +2,17 @@ * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.http.scaladsl +package akka.http -import com.typesafe.config.Config -import scala.language.implicitConversions -import scala.concurrent.duration._ import akka.ConfigurationException -import akka.actor.{ ActorRefFactory, ActorSystem } -import akka.http.impl.engine.parsing.ParserSettings +import akka.actor.{ ActorSystem, ActorRefFactory } import akka.http.impl.util._ import akka.http.scaladsl.model.HttpHeader import akka.http.scaladsl.model.headers.{ Host, Server } +import com.typesafe.config.Config + +import scala.concurrent.duration._ +import scala.language.implicitConversions final case class ServerSettings( serverHeader: Option[Server], @@ -57,13 +57,28 @@ object ServerSettings extends SettingsCompanion[ServerSettings]("akka.http.serve def apply(optionalSettings: Option[ServerSettings])(implicit actorRefFactory: ActorRefFactory): ServerSettings = optionalSettings getOrElse apply(actorSystem) - /** Java API */ - def create(system: ActorSystem): ServerSettings = apply(system) + /** + * Creates an instance of ServerSettings using the configuration provided by the given + * ActorSystem. + * + * Java API + */ + def create(system: ActorSystem): ServerSettings = ServerSettings(system) - /** Java API */ - def create(config: Config): ServerSettings = apply(config) + /** + * Creates an instance of ServerSettings using the given Config. + * + * Java API + */ + def create(config: Config): ServerSettings = ServerSettings(config) - /** Java API */ - def create(configOverrides: String): ServerSettings = apply(configOverrides) + /** + * Create an instance of ServerSettings using the given String of config overrides to override + * settings set in the class loader of this class (i.e. by application.conf or reference.conf files in + * the class loader of this class). + * + * Java API + */ + def create(configOverrides: String): ServerSettings = ServerSettings(configOverrides) } diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/client/ClientConnectionSettings.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/client/ClientConnectionSettings.scala index fc793e7ec0..b696f2cffc 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/client/ClientConnectionSettings.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/client/ClientConnectionSettings.scala @@ -4,10 +4,10 @@ package akka.http.impl.engine.client +import akka.http.ParserSettings import com.typesafe.config.Config import scala.concurrent.duration.{ FiniteDuration, Duration } import akka.http.scaladsl.model.headers.`User-Agent` -import akka.http.impl.engine.parsing.ParserSettings import akka.http.impl.util._ final case class ClientConnectionSettings( diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpMessageParser.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpMessageParser.scala index 77db7a28e5..03457828b1 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpMessageParser.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpMessageParser.scala @@ -4,6 +4,8 @@ package akka.http.impl.engine.parsing +import akka.http.ParserSettings + import scala.annotation.tailrec import scala.collection.mutable.ListBuffer import akka.parboiled2.CharUtils diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpRequestParser.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpRequestParser.scala index 104f16ab1e..7b0c3c7abb 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpRequestParser.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpRequestParser.scala @@ -5,6 +5,8 @@ package akka.http.impl.engine.parsing import java.lang.{ StringBuilder ⇒ JStringBuilder } +import akka.http.ParserSettings + import scala.annotation.tailrec import akka.actor.ActorRef import akka.stream.stage.{ Context, PushPullStage } diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpResponseParser.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpResponseParser.scala index 8ce57052b5..7922a3e1e8 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpResponseParser.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/HttpResponseParser.scala @@ -4,6 +4,8 @@ package akka.http.impl.engine.parsing +import akka.http.ParserSettings + import scala.annotation.tailrec import akka.http.impl.model.parser.CharacterClasses import akka.stream.scaladsl.Source diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/package.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/package.scala index 9dd084664d..ebb032d9ca 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/package.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/package.scala @@ -5,6 +5,8 @@ package akka.http.impl.engine import java.lang.{ StringBuilder ⇒ JStringBuilder } +import akka.http.ParserSettings + import scala.annotation.tailrec import akka.event.LoggingAdapter import akka.util.ByteString 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 77f66e123a..85a5106c76 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 @@ -4,6 +4,7 @@ package akka.http.impl.engine.server +import akka.http.ServerSettings import org.reactivestreams.{ Subscriber, Publisher } import scala.util.control.NonFatal import akka.util.ByteString @@ -18,7 +19,6 @@ import akka.http.impl.engine.parsing._ import akka.http.impl.engine.rendering.{ ResponseRenderingContext, HttpResponseRendererFactory } import akka.http.impl.engine.TokenSourceActor import akka.http.scaladsl.model._ -import akka.http.scaladsl.ServerSettings import akka.http.impl.util._ import akka.http.impl.engine.ws._ import Websocket.SwitchToWebsocketToken diff --git a/akka-http-core/src/main/scala/akka/http/javadsl/Http.scala b/akka-http-core/src/main/scala/akka/http/javadsl/Http.scala index 5758e9d9ab..a8c4ccf92f 100644 --- a/akka-http-core/src/main/scala/akka/http/javadsl/Http.scala +++ b/akka-http-core/src/main/scala/akka/http/javadsl/Http.scala @@ -5,6 +5,8 @@ package akka.http.javadsl import java.lang.{ Iterable ⇒ JIterable } +import akka.http.ServerSettings + import scala.concurrent.Future import akka.japi.Util._ import akka.japi.Function @@ -13,7 +15,7 @@ import akka.event.LoggingAdapter import akka.io.Inet import akka.stream.FlowMaterializer import akka.stream.javadsl.{ Flow, Source } -import akka.http.scaladsl.{ model ⇒ sm, ServerSettings } +import akka.http.scaladsl.{ model ⇒ sm } import akka.http.javadsl.model._ object Http extends ExtensionId[Http] with ExtensionIdProvider { diff --git a/akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala b/akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala index 5636ad3c89..e97a8556e4 100644 --- a/akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala +++ b/akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala @@ -6,6 +6,7 @@ package akka.http.scaladsl import java.net.InetSocketAddress import java.util.concurrent.ConcurrentHashMap +import akka.http.ServerSettings import com.typesafe.config.Config import scala.util.Try import scala.util.control.NonFatal diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/client/ConnectionPoolSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/client/ConnectionPoolSpec.scala index 0ed980f8d6..b50550a898 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/client/ConnectionPoolSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/client/ConnectionPoolSpec.scala @@ -5,10 +5,12 @@ package akka.http.impl.engine.client import java.util.concurrent.atomic.AtomicInteger +import akka.http.ServerSettings + import scala.concurrent.Await import scala.concurrent.duration._ import scala.util.{ Failure, Success, Try } -import akka.http.scaladsl.{ TestUtils, Http, ServerSettings } +import akka.http.scaladsl.{ TestUtils, Http } import akka.http.impl.util.{ SingletonException, StreamUtils } import akka.util.ByteString import akka.stream.{ BidiShape, ActorFlowMaterializer } diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/HttpHeaderParserSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/HttpHeaderParserSpec.scala index ea73debc48..58fe58ade9 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/HttpHeaderParserSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/HttpHeaderParserSpec.scala @@ -5,6 +5,7 @@ package akka.http.impl.engine.parsing import java.lang.{ StringBuilder ⇒ JStringBuilder } +import akka.http.ParserSettings import com.typesafe.config.{ ConfigFactory, Config } import scala.annotation.tailrec import scala.util.Random diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/HttpHeaderParserTestBed.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/HttpHeaderParserTestBed.scala index 69799308d5..448c946f96 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/HttpHeaderParserTestBed.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/HttpHeaderParserTestBed.scala @@ -1,6 +1,7 @@ package akka.http.impl.engine.parsing import akka.actor.ActorSystem +import akka.http.ParserSettings import com.typesafe.config.{ ConfigFactory, Config } object HttpHeaderParserTestBed extends App { diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala index 080683266c..724b50d96e 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala @@ -4,6 +4,7 @@ package akka.http.impl.engine.parsing +import akka.http.ParserSettings import akka.http.scaladsl.util.FastFuture import com.typesafe.config.{ ConfigFactory, Config } import scala.concurrent.Future diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/ResponseParserSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/ResponseParserSpec.scala index 344c713273..2ea87dbeb9 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/ResponseParserSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/ResponseParserSpec.scala @@ -4,6 +4,7 @@ package akka.http.impl.engine.parsing +import akka.http.ParserSettings import akka.http.scaladsl.util.FastFuture import com.typesafe.config.{ ConfigFactory, Config } import scala.concurrent.{ Future, Await } diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerSpec.scala index d44ca00238..6e6b6370b9 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerSpec.scala @@ -4,6 +4,8 @@ package akka.http.impl.engine.server +import akka.http.ServerSettings + import scala.util.Random import scala.annotation.tailrec import scala.concurrent.duration._ @@ -13,7 +15,6 @@ import akka.util.ByteString import akka.stream.scaladsl._ import akka.stream.ActorFlowMaterializer import akka.stream.testkit._ -import akka.http.scaladsl.ServerSettings import akka.http.scaladsl.model._ import akka.http.impl.util._ import headers._ diff --git a/akka-http-core/src/test/scala/akka/http/scaladsl/ClientServerSpec.scala b/akka-http-core/src/test/scala/akka/http/scaladsl/ClientServerSpec.scala index 2f9f462d6d..90603ea07e 100644 --- a/akka-http-core/src/test/scala/akka/http/scaladsl/ClientServerSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/scaladsl/ClientServerSpec.scala @@ -6,6 +6,7 @@ package akka.http.scaladsl import java.io.{ BufferedReader, BufferedWriter, InputStreamReader, OutputStreamWriter } import java.net.Socket +import akka.http.ServerSettings import com.typesafe.config.{ Config, ConfigFactory } import scala.annotation.tailrec import scala.concurrent.Await