diff --git a/akka-docs/rst/java/code/docs/http/javadsl/server/HttpBasicAuthenticatorExample.java b/akka-docs/rst/java/code/docs/http/javadsl/server/HttpBasicAuthenticatorExample.java index 8c6b3beb27..d7a1b90f30 100644 --- a/akka-docs/rst/java/code/docs/http/javadsl/server/HttpBasicAuthenticatorExample.java +++ b/akka-docs/rst/java/code/docs/http/javadsl/server/HttpBasicAuthenticatorExample.java @@ -3,6 +3,7 @@ */ package docs.http.javadsl.server; +import java.util.Optional; import akka.http.javadsl.model.HttpRequest; import akka.http.javadsl.model.headers.Host; import akka.http.javadsl.server.Handler1; @@ -75,4 +76,4 @@ public class HttpBasicAuthenticatorExample extends JUnitRouteTest { } -} \ No newline at end of file +} diff --git a/akka-docs/rst/java/http/client-side/https-support.rst b/akka-docs/rst/java/http/client-side/https-support.rst index 6ccc818815..f9a9e02776 100644 --- a/akka-docs/rst/java/http/client-side/https-support.rst +++ b/akka-docs/rst/java/http/client-side/https-support.rst @@ -9,12 +9,12 @@ Akka HTTP supports TLS encryption on the client-side as well as on the :ref:`ser Akka HTTP 1.0 does not completely validate certificates when using HTTPS. Please do not treat HTTPS connections made with this version as secure. Requests are vulnerable to a Man-In-The-Middle attack via certificate substitution. - -The central vehicle for configuring encryption is the ``HttpsContext``, which can be created using -the static method ``HttpsContext.create`` which is defined like this: -.. includecode:: /../../akka-http-core/src/main/java/akka/http/javadsl/HttpsContext.java - :include: http-context-creation +The central vehicle for configuring encryption is the ``HttpsConnectionContext``, which can be created using +the static method ``ConnectionContext.https`` which is defined like this: + +.. includecode:: /../../akka-http-core/src/main/scala/akka/http/javadsl/ConnectionContext.scala + :include: https-context-creation In addition to the ``outgoingConnection``, ``newHostConnectionPool`` and ``cachedHostConnectionPool`` methods the `akka.http.javadsl.Http`_ extension also defines ``outgoingConnectionTls``, ``newHostConnectionPoolTls`` and diff --git a/akka-docs/rst/java/http/server-side/low-level-server-side-api.rst b/akka-docs/rst/java/http/server-side/low-level-server-side-api.rst index 8c0dc024e1..f13ebd2647 100644 --- a/akka-docs/rst/java/http/server-side/low-level-server-side-api.rst +++ b/akka-docs/rst/java/http/server-side/low-level-server-side-api.rst @@ -138,11 +138,11 @@ Server-Side HTTPS Support Akka HTTP supports TLS encryption on the server-side as well as on the :ref:`client-side `. -The central vehicle for configuring encryption is the ``HttpsContext``, which can be created using -the static method ``HttpsContext.create`` which is defined like this: +The central vehicle for configuring encryption is the ``HttpsConnectionContext``, which can be created using +the static method ``ConnectionContext.https`` which is defined like this: -.. includecode:: /../../akka-http-core/src/main/java/akka/http/javadsl/HttpsContext.java - :include: http-context-creation +.. includecode:: /../../akka-http-core/src/main/scala/akka/http/javadsl/ConnectionContext.scala + :include: https-context-creation On the server-side the ``bind``, and ``bindAndHandleXXX`` methods of the `akka.http.javadsl.Http`_ extension define an optional ``httpsContext`` parameter, which can receive the HTTPS configuration in the form of an ``HttpsContext`` diff --git a/akka-docs/rst/scala/http/client-side/https-support.rst b/akka-docs/rst/scala/http/client-side/https-support.rst index be5620c65b..4c480db335 100644 --- a/akka-docs/rst/scala/http/client-side/https-support.rst +++ b/akka-docs/rst/scala/http/client-side/https-support.rst @@ -10,10 +10,11 @@ Akka HTTP supports TLS encryption on the client-side as well as on the :ref:`ser Akka HTTP 1.0 does not completely validate certificates when using HTTPS. Please do not treat HTTPS connections made with this version as secure. Requests are vulnerable to a Man-In-The-Middle attack via certificate substitution. -The central vehicle for configuring encryption is the ``HttpsContext``, which is defined as such: +The central vehicle for configuring encryption is the ``HttpsConnectionContext``, which can be created using +the static method ``ConnectionContext.https`` which is defined like this: -.. includecode2:: /../../akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala - :snippet: https-context-impl +.. includecode:: /../../akka-http-core/src/main/scala/akka/http/scaladsl/ConnectionContext.scala + :include: https-context-creation In addition to the ``outgoingConnection``, ``newHostConnectionPool`` and ``cachedHostConnectionPool`` methods the `akka.http.scaladsl.Http`_ extension also defines ``outgoingConnectionTls``, ``newHostConnectionPoolTls`` and diff --git a/akka-docs/rst/scala/http/low-level-server-side-api.rst b/akka-docs/rst/scala/http/low-level-server-side-api.rst index f52aa7f4ef..b4c2156b44 100644 --- a/akka-docs/rst/scala/http/low-level-server-side-api.rst +++ b/akka-docs/rst/scala/http/low-level-server-side-api.rst @@ -140,10 +140,11 @@ Server-Side HTTPS Support Akka HTTP supports TLS encryption on the server-side as well as on the :ref:`client-side `. -The central vehicle for configuring encryption is the ``HttpsContext``, which is defined as such: +The central vehicle for configuring encryption is the ``HttpsConnectionContext``, which can be created using +the static method ``ConnectionContext.https`` which is defined like this: -.. includecode2:: /../../akka-http-core/src/main/scala/akka/http/scaladsl/Http.scala - :snippet: https-context-impl +.. includecode:: /../../akka-http-core/src/main/scala/akka/http/scaladsl/ConnectionContext.scala + :include: https-context-creation On the server-side the ``bind``, and ``bindAndHandleXXX`` methods of the `akka.http.scaladsl.Http`_ extension define an optional ``httpsContext`` parameter, which can receive the HTTPS configuration in the form of an ``HttpsContext`` diff --git a/akka-http-core/src/main/scala/akka/http/javadsl/ConnectionContext.scala b/akka-http-core/src/main/scala/akka/http/javadsl/ConnectionContext.scala index d405644267..12f660fe36 100644 --- a/akka-http-core/src/main/scala/akka/http/javadsl/ConnectionContext.scala +++ b/akka-http-core/src/main/scala/akka/http/javadsl/ConnectionContext.scala @@ -11,6 +11,7 @@ import akka.stream.io.ClientAuth import scala.compat.java8.OptionConverters object ConnectionContext { + //#https-context-creation /** Used to serve HTTPS traffic. */ def https(sslContext: SSLContext): HttpsConnectionContext = scaladsl.ConnectionContext.https(sslContext) @@ -19,6 +20,7 @@ object ConnectionContext { def https(sslContext: SSLContext, enabledCipherSuites: Optional[JCollection[String]], enabledProtocols: Optional[JCollection[String]], clientAuth: Optional[ClientAuth], sslParameters: Optional[SSLParameters]) = scaladsl.ConnectionContext.https(sslContext, sslParameters = OptionConverters.toScala(sslParameters)) + //#https-context-creation /** Used to serve HTTP traffic. */ def noEncryption(): HttpConnectionContext = @@ -52,4 +54,3 @@ abstract class HttpsConnectionContext extends akka.http.javadsl.ConnectionContex /** Java API */ def getSslParameters: Optional[SSLParameters] } - diff --git a/akka-http-core/src/main/scala/akka/http/scaladsl/ConnectionContext.scala b/akka-http-core/src/main/scala/akka/http/scaladsl/ConnectionContext.scala index 71616d48d2..0db6d2c903 100644 --- a/akka-http-core/src/main/scala/akka/http/scaladsl/ConnectionContext.scala +++ b/akka-http-core/src/main/scala/akka/http/scaladsl/ConnectionContext.scala @@ -18,6 +18,7 @@ trait ConnectionContext extends akka.http.javadsl.ConnectionContext { } object ConnectionContext { + //#https-context-creation def https(sslContext: SSLContext, enabledCipherSuites: Option[immutable.Seq[String]] = None, enabledProtocols: Option[immutable.Seq[String]] = None, @@ -25,6 +26,7 @@ object ConnectionContext { sslParameters: Option[SSLParameters] = None) = { new HttpsConnectionContext(sslContext, enabledCipherSuites, enabledProtocols, clientAuth, sslParameters) } + //#https-context-creation def noEncryption() = HttpConnectionContext } diff --git a/akka-http/src/main/scala/akka/http/impl/server/HeaderImpl.scala b/akka-http/src/main/scala/akka/http/impl/server/HeaderImpl.scala index 0ff24e6cd0..a070054e35 100644 --- a/akka-http/src/main/scala/akka/http/impl/server/HeaderImpl.scala +++ b/akka-http/src/main/scala/akka/http/impl/server/HeaderImpl.scala @@ -4,6 +4,8 @@ package akka.http.impl.server +import java.util.Optional + import akka.http.javadsl.model.HttpHeader import akka.http.javadsl.server.RequestVal import akka.http.javadsl.server.values.Header @@ -12,6 +14,7 @@ import akka.http.scaladsl.server._ import akka.http.scaladsl.server.directives.BasicDirectives._ import akka.http.scaladsl.server.directives.RouteDirectives._ +import scala.compat.java8.OptionConverters._ import scala.reflect.ClassTag /** @@ -38,9 +41,9 @@ private[http] object HeaderImpl { def directive: Directive1[U] = instanceDirective } - def optionalInstance(): RequestVal[Option[U]] = - new StandaloneExtractionImpl[Option[U]] { - def directive: Directive1[Option[U]] = optionalDirective(uClassTag) + def optionalInstance(): RequestVal[Optional[U]] = + new StandaloneExtractionImpl[Optional[U]] { + def directive: Directive1[Optional[U]] = optionalDirective(uClassTag).map(_.asJava) } def value(): RequestVal[String] = @@ -48,9 +51,9 @@ private[http] object HeaderImpl { def directive: Directive1[String] = instanceDirective.map(_.value) } - def optionalValue(): RequestVal[Option[String]] = - new StandaloneExtractionImpl[Option[String]] { - def directive: Directive1[Option[String]] = optionalDirective(uClassTag).map(_.map(_.value)) + def optionalValue(): RequestVal[Optional[String]] = + new StandaloneExtractionImpl[Optional[String]] { + def directive: Directive1[Optional[String]] = optionalDirective(uClassTag).map(_.map(_.value).asJava) } }.asInstanceOf[Header[T]] // undeclared covariance } diff --git a/akka-http/src/main/scala/akka/http/impl/server/RouteImplementation.scala b/akka-http/src/main/scala/akka/http/impl/server/RouteImplementation.scala index 1055ef9ccd..763e4ed341 100644 --- a/akka-http/src/main/scala/akka/http/impl/server/RouteImplementation.scala +++ b/akka-http/src/main/scala/akka/http/impl/server/RouteImplementation.scala @@ -8,7 +8,6 @@ import akka.http.impl.util.JavaMapping import akka.http.javadsl.server.values.{ PathMatcher, BasicCredentials, OAuth2Credentials } import akka.http.scaladsl.model.StatusCodes.Redirection import akka.http.scaladsl.server.util.TupleOps.Join - import scala.language.implicitConversions import scala.annotation.tailrec import scala.collection.immutable @@ -98,7 +97,7 @@ private[http] object RouteImplementation extends Directives with server.RouteCon } } - authenticator.authenticate(javaCreds).toScala.map(_.asScala)(sameThreadExecutionContext) + authenticator.authenticate(javaCreds).toScala.map(_.asScala)(akka.dispatch.ExecutionContexts.sameThreadExecutionContext) }).flatMap { user ⇒ addExtraction(authenticator.asInstanceOf[RequestVal[Any]], user) } diff --git a/akka-http/src/main/scala/akka/http/javadsl/server/values/Header.scala b/akka-http/src/main/scala/akka/http/javadsl/server/values/Header.scala index 542b784125..71212489e4 100644 --- a/akka-http/src/main/scala/akka/http/javadsl/server/values/Header.scala +++ b/akka-http/src/main/scala/akka/http/javadsl/server/values/Header.scala @@ -4,6 +4,8 @@ package akka.http.javadsl.server.values +import java.util.Optional + import akka.http.impl.server.HeaderImpl import akka.http.javadsl.model.HttpHeader import akka.http.javadsl.server.RequestVal @@ -11,27 +13,28 @@ import akka.http.scaladsl.model import akka.http.scaladsl.server.Directive1 import akka.http.scaladsl.server.util.ClassMagnet +import scala.compat.java8.OptionConverters._ import scala.reflect.{ ClassTag, classTag } trait Header[T <: HttpHeader] { def instance(): RequestVal[T] - def optionalInstance(): RequestVal[Option[T]] + def optionalInstance(): RequestVal[Optional[T]] def value(): RequestVal[String] - def optionalValue(): RequestVal[Option[String]] + def optionalValue(): RequestVal[Optional[String]] } object Headers { import akka.http.scaladsl.server.directives.BasicDirectives._ import akka.http.scaladsl.server.directives.HeaderDirectives._ def byName(name: String): Header[HttpHeader] = - HeaderImpl[HttpHeader](name, _ ⇒ optionalHeaderInstanceByName(name.toLowerCase()), classTag[HttpHeader]) + HeaderImpl[HttpHeader](name, _ ⇒ optionalHeaderInstanceByName(name.toLowerCase()).map(_.asScala), classTag[HttpHeader]) def byClass[T <: HttpHeader](clazz: Class[T]): Header[T] = HeaderImpl[T](clazz.getSimpleName, ct ⇒ optionalHeaderValueByType(ClassMagnet(ct)), ClassTag(clazz)) - private def optionalHeaderInstanceByName(lowercaseName: String): Directive1[Option[model.HttpHeader]] = + private def optionalHeaderInstanceByName(lowercaseName: String): Directive1[Optional[model.HttpHeader]] = extract(_.request.headers.collectFirst { case h @ model.HttpHeader(`lowercaseName`, _) ⇒ h - }) -} \ No newline at end of file + }.asJava) +}