This is an automated email from the ASF dual-hosted git repository.
mdedetrich pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-pekko-http.git
The following commit(s) were added to refs/heads/main by this push:
new 18aa9d3e8 Add UnsupportedContentTypeException javadsl
18aa9d3e8 is described below
commit 18aa9d3e8d79a023bebb5c20af057114d61b6873
Author: Matthew de Detrich <[email protected]>
AuthorDate: Thu Dec 21 11:26:32 2023 +1100
Add UnsupportedContentTypeException javadsl
---
.../http/javadsl/unmarshalling/Unmarshaller.scala | 48 ++++++++++++++++++----
.../http/scaladsl/unmarshalling/Unmarshaller.scala | 28 +++++++++----
2 files changed, 61 insertions(+), 15 deletions(-)
diff --git
a/http/src/main/scala/org/apache/pekko/http/javadsl/unmarshalling/Unmarshaller.scala
b/http/src/main/scala/org/apache/pekko/http/javadsl/unmarshalling/Unmarshaller.scala
index 7c20d377d..187083e51 100644
---
a/http/src/main/scala/org/apache/pekko/http/javadsl/unmarshalling/Unmarshaller.scala
+++
b/http/src/main/scala/org/apache/pekko/http/javadsl/unmarshalling/Unmarshaller.scala
@@ -14,6 +14,7 @@
package org.apache.pekko.http.javadsl.unmarshalling
import java.util.concurrent.CompletionStage
+import java.util.Optional
import org.apache.pekko
import pekko.actor.ClassicActorSystemProvider
@@ -21,14 +22,12 @@ import pekko.annotation.InternalApi
import pekko.http.impl.model.JavaQuery
import pekko.http.impl.util.JavaMapping
import pekko.http.impl.util.JavaMapping.Implicits._
-import pekko.http.javadsl.model._
+import pekko.http.{ javadsl => jm }
+import jm.model._
import pekko.http.scaladsl.model.{ ContentTypeRange, ContentTypes }
import pekko.http.scaladsl.unmarshalling
import pekko.http.scaladsl.unmarshalling.FromEntityUnmarshaller
-import pekko.http.scaladsl.unmarshalling.Unmarshaller.{
- EnhancedFromEntityUnmarshaller,
- UnsupportedContentTypeException
-}
+import
pekko.http.scaladsl.unmarshalling.Unmarshaller.EnhancedFromEntityUnmarshaller
import pekko.http.scaladsl.util.FastFuture
import pekko.stream.{ Materializer, SystemMaterializer }
import pekko.util.ByteString
@@ -85,8 +84,9 @@ object Unmarshaller extends
pekko.http.javadsl.unmarshalling.Unmarshallers {
val mediaType = t.asScala
if (entity.contentType == ContentTypes.NoContentType ||
mediaType.matches(entity.contentType.mediaType)) {
um.asScala(entity)
- } else
FastFuture.failed(UnsupportedContentTypeException(Some(entity.contentType),
- ContentTypeRange(t.toRange.asScala)))
+ } else FastFuture.failed(
+
pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException(Some(entity.contentType),
+ ContentTypeRange(t.toRange.asScala)))
}
}
}
@@ -124,6 +124,40 @@ object Unmarshaller extends
pekko.http.javadsl.unmarshalling.Unmarshallers {
implicit mi: JavaMapping[JI, SI]): unmarshalling.Unmarshaller[JI, O] =
um.asInstanceOf[unmarshalling.Unmarshaller[JI, O]] // since guarantee
provided by existence of `mi`
+ class UnsupportedContentTypeException(
+ private val _supported: java.util.Set[jm.model.ContentTypeRange],
+ private val _actualContentType: Optional[jm.model.ContentType])
+ extends RuntimeException(_supported.asScala.mkString(
+ s"Unsupported Content-Type [${_actualContentType.asScala}], supported:
", ", ", "")) {
+
+ def this(supported: jm.model.ContentTypeRange*) = {
+ this(supported.toSet.asJava, Optional.empty[jm.model.ContentType]())
+ }
+
+ def this(supported: java.util.Set[jm.model.ContentTypeRange]) = {
+ this(supported, Optional.empty[jm.model.ContentType]())
+ }
+
+ def this(contentType: Optional[jm.model.ContentType], supported:
jm.model.ContentTypeRange*) = {
+ this(supported.toSet.asJava, contentType)
+ }
+
+ def toScala():
pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException =
+
pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException(
+
_supported.asScala.toSet.asInstanceOf[Set[pekko.http.scaladsl.model.ContentTypeRange]],
+ _actualContentType.asScala)
+
+ def getSupported(): java.util.Set[jm.model.ContentTypeRange] = _supported
+
+ def getActualContentType(): Optional[jm.model.ContentType] =
_actualContentType
+
+ override def equals(that: Any): Boolean = that match {
+ case that: UnsupportedContentTypeException =>
+ that._supported == this._supported && that._actualContentType ==
this._actualContentType
+ case _ => false
+ }
+ }
+
}
trait UnmarshallerBase[-A, B]
diff --git
a/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/Unmarshaller.scala
b/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/Unmarshaller.scala
index 2385d2f06..2743f9859 100644
---
a/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/Unmarshaller.scala
+++
b/http/src/main/scala/org/apache/pekko/http/scaladsl/unmarshalling/Unmarshaller.scala
@@ -15,15 +15,19 @@ package org.apache.pekko.http.scaladsl.unmarshalling
import org.apache.pekko
import pekko.event.Logging
+import pekko.http.{ javadsl => jm }
import pekko.http.scaladsl.model._
import pekko.http.scaladsl.util.FastFuture
import pekko.http.scaladsl.util.FastFuture._
+import pekko.http.impl.util.JavaMapping.Implicits._
import pekko.stream.Materializer
+import pekko.util.OptionConverters._
+import scala.collection.JavaConverters._
import scala.concurrent.{ ExecutionContext, Future }
import scala.util.control.{ NoStackTrace, NonFatal }
-trait Unmarshaller[-A, B] extends
pekko.http.javadsl.unmarshalling.Unmarshaller[A, B] {
+trait Unmarshaller[-A, B] extends jm.unmarshalling.Unmarshaller[A, B] {
implicit final def asScala: Unmarshaller[A, B] = this
@@ -164,21 +168,29 @@ object Unmarshaller
* [[pekko.http.scaladsl.unmarshalling.Unmarshaller]] instead.
*/
final class UnsupportedContentTypeException(
- val supported: Set[ContentTypeRange],
- val actualContentType: Option[ContentType])
- extends RuntimeException(supported.mkString(
- s"Unsupported Content-Type [$actualContentType], supported: ", ", ",
"")) with Product with Serializable {
+ private val _supported: java.util.Set[jm.model.ContentTypeRange],
+ private val _actualContentType: java.util.Optional[jm.model.ContentType])
+ extends
jm.unmarshalling.Unmarshaller.UnsupportedContentTypeException(_supported,
_actualContentType) with Product
+ with Serializable {
+
+ val supported: Set[ContentTypeRange] =
+
_supported.asScala.toSet.asInstanceOf[Set[pekko.http.scaladsl.model.ContentTypeRange]]
+ val actualContentType: Option[ContentType] = _actualContentType.asScala
+
+ def this(supported: Set[ContentTypeRange], actualContentType:
Option[ContentType]) =
+
this(supported.asJava.asInstanceOf[java.util.Set[jm.model.ContentTypeRange]],
+
actualContentType.toJava.asInstanceOf[java.util.Optional[jm.model.ContentType]])
@deprecated("for binary compatibility", since = "Akka HTTP 10.1.9")
def this(supported: Set[ContentTypeRange]) = this(supported, None)
@deprecated("for binary compatibility", since = "Akka HTTP 10.1.9")
def copy(supported: Set[ContentTypeRange]):
UnsupportedContentTypeException =
- new UnsupportedContentTypeException(supported, this.actualContentType)
+ new UnsupportedContentTypeException(supported, actualContentType)
@deprecated("for binary compatibility", since = "Akka HTTP 10.1.9")
def copy$default$1(supported: Set[ContentTypeRange]):
UnsupportedContentTypeException =
- new UnsupportedContentTypeException(supported, this.actualContentType)
+ new UnsupportedContentTypeException(supported, actualContentType)
@deprecated("for binary compatibility", since = "Akka HTTP 10.1.9")
def copy(
@@ -190,7 +202,7 @@ object Unmarshaller
override def equals(that: Any): Boolean = that match {
case that: UnsupportedContentTypeException =>
- that.canEqual(this) && that.supported == this.supported &&
that.actualContentType == this.actualContentType
+ that.canEqual(this) && super.equals(this)
case _ => false
}
override def productArity: Int = 1
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]