This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-http.git


The following commit(s) were added to refs/heads/main by this push:
     new 7412c4365 use convertIterable to wrap java Iterables (#613)
7412c4365 is described below

commit 7412c4365cf5382ce5199a882a207d40a1d30a4d
Author: PJ Fanning <[email protected]>
AuthorDate: Tue Oct 1 13:44:38 2024 +0100

    use convertIterable to wrap java Iterables (#613)
    
    * use convertIterable to wrap java Iterables
    
    * Update ConnectionContext.scala
    
    * Update MediaTypes.java
    
    * Update MediaTypes.java
---
 .../pekko/http/javadsl/model/MediaTypes.java       | 38 +++++++++-----------
 .../pekko/http/javadsl/ConnectionContext.scala     | 10 +++---
 .../pekko/http/javadsl/server/Rejections.scala     |  5 +--
 .../pekko/http/javadsl/server/RouteResult.scala    |  5 ++-
 .../server/directives/BasicDirectives.scala        | 41 +++++++++++-----------
 .../pekko/http/scaladsl/server/Rejection.scala     |  6 ++--
 6 files changed, 52 insertions(+), 53 deletions(-)

diff --git 
a/http-core/src/main/java/org/apache/pekko/http/javadsl/model/MediaTypes.java 
b/http-core/src/main/java/org/apache/pekko/http/javadsl/model/MediaTypes.java
index dcae80ca8..ae1f0c7b8 100644
--- 
a/http-core/src/main/java/org/apache/pekko/http/javadsl/model/MediaTypes.java
+++ 
b/http-core/src/main/java/org/apache/pekko/http/javadsl/model/MediaTypes.java
@@ -467,7 +467,7 @@ public final class MediaTypes {
             : 
org.apache.pekko.http.scaladsl.model.MediaType.NotCompressible$.MODULE$;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return 
org.apache.pekko.http.scaladsl.model.MediaType.applicationBinary(subType, comp, 
fileEx);
   }
@@ -478,7 +478,7 @@ public final class MediaTypes {
         (org.apache.pekko.http.scaladsl.model.MediaType.Compressibility) 
compressibility;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return 
org.apache.pekko.http.scaladsl.model.MediaType.applicationBinary(subType, comp, 
fileEx);
   }
@@ -489,7 +489,7 @@ public final class MediaTypes {
         (org.apache.pekko.http.scaladsl.model.HttpCharset) charset;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return 
org.apache.pekko.http.scaladsl.model.MediaType.applicationWithFixedCharset(
         subType, cs, fileEx);
@@ -498,7 +498,7 @@ public final class MediaTypes {
   public static MediaType.WithOpenCharset applicationWithOpenCharset(
       String subType, String... fileExtensions) {
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return 
org.apache.pekko.http.scaladsl.model.MediaType.applicationWithOpenCharset(
         subType, fileEx);
@@ -512,7 +512,7 @@ public final class MediaTypes {
             : 
org.apache.pekko.http.scaladsl.model.MediaType.NotCompressible$.MODULE$;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.audio(subType, comp, 
fileEx);
   }
@@ -523,7 +523,7 @@ public final class MediaTypes {
         (org.apache.pekko.http.scaladsl.model.MediaType.Compressibility) 
compressibility;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.audio(subType, comp, 
fileEx);
   }
@@ -536,7 +536,7 @@ public final class MediaTypes {
             : 
org.apache.pekko.http.scaladsl.model.MediaType.NotCompressible$.MODULE$;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.image(subType, comp, 
fileEx);
   }
@@ -547,7 +547,7 @@ public final class MediaTypes {
         (org.apache.pekko.http.scaladsl.model.MediaType.Compressibility) 
compressibility;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.image(subType, comp, 
fileEx);
   }
@@ -560,7 +560,7 @@ public final class MediaTypes {
             : 
org.apache.pekko.http.scaladsl.model.MediaType.NotCompressible$.MODULE$;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.message(subType, 
comp, fileEx);
   }
@@ -571,14 +571,14 @@ public final class MediaTypes {
         (org.apache.pekko.http.scaladsl.model.MediaType.Compressibility) 
compressibility;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.message(subType, 
comp, fileEx);
   }
 
   public static MediaType.WithOpenCharset text(String subType, String... 
fileExtensions) {
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.text(subType, 
fileEx);
   }
@@ -591,7 +591,7 @@ public final class MediaTypes {
             : 
org.apache.pekko.http.scaladsl.model.MediaType.NotCompressible$.MODULE$;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.video(subType, comp, 
fileEx);
   }
@@ -602,7 +602,7 @@ public final class MediaTypes {
         (org.apache.pekko.http.scaladsl.model.MediaType.Compressibility) 
compressibility;
 
     scala.collection.immutable.Seq<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions));
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions));
 
     return org.apache.pekko.http.scaladsl.model.MediaType.video(subType, comp, 
fileEx);
   }
@@ -638,8 +638,7 @@ public final class MediaTypes {
             : 
org.apache.pekko.http.scaladsl.model.MediaType.NotCompressible$.MODULE$;
 
     scala.collection.immutable.List<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions))
-            .toList();
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions)).toList();
 
     scala.collection.immutable.Map<String, String> p = 
Util.convertMapToScala(params);
 
@@ -658,8 +657,7 @@ public final class MediaTypes {
         (org.apache.pekko.http.scaladsl.model.MediaType.Compressibility) 
compressibility;
 
     scala.collection.immutable.List<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions))
-            .toList();
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions)).toList();
 
     scala.collection.immutable.Map<String, String> p = 
Util.convertMapToScala(params);
 
@@ -678,8 +676,7 @@ public final class MediaTypes {
         (org.apache.pekko.http.scaladsl.model.HttpCharset) charset;
 
     scala.collection.immutable.List<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions))
-            .toList();
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions)).toList();
 
     scala.collection.immutable.Map<String, String> p = 
Util.convertMapToScala(params);
 
@@ -694,8 +691,7 @@ public final class MediaTypes {
       boolean allowArbitrarySubtypes,
       String... fileExtensions) {
     scala.collection.immutable.List<String> fileEx =
-        
org.apache.pekko.japi.Util.<String>immutableSeq(java.util.Arrays.asList(fileExtensions))
-            .toList();
+        Util.<String, 
String>convertIterable(java.util.Arrays.asList(fileExtensions)).toList();
 
     scala.collection.immutable.Map<String, String> p = 
Util.convertMapToScala(params);
 
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/javadsl/ConnectionContext.scala
 
b/http-core/src/main/scala/org/apache/pekko/http/javadsl/ConnectionContext.scala
index 61e6010d6..5124ee194 100644
--- 
a/http-core/src/main/scala/org/apache/pekko/http/javadsl/ConnectionContext.scala
+++ 
b/http-core/src/main/scala/org/apache/pekko/http/javadsl/ConnectionContext.scala
@@ -17,8 +17,8 @@ import java.util.{ Collection => JCollection, Optional }
 
 import org.apache.pekko
 import pekko.annotation.{ ApiMayChange, DoNotInherit }
+import pekko.http.impl.util.Util
 import pekko.http.scaladsl
-import pekko.japi.Util
 import pekko.stream.TLSClientAuth
 import pekko.util.OptionConverters._
 import com.typesafe.sslconfig.pekko.PekkoSSLConfig
@@ -80,8 +80,8 @@ object ConnectionContext {
     scaladsl.ConnectionContext.https(
       sslContext,
       sslConfig.toScala,
-      enabledCipherSuites.toScala.map(Util.immutableSeq(_)),
-      enabledProtocols.toScala.map(Util.immutableSeq(_)),
+      enabledCipherSuites.toScala.map(Util.convertIterable[String, String](_)),
+      enabledProtocols.toScala.map(Util.convertIterable[String, String](_)),
       clientAuth.toScala,
       sslParameters.toScala)
 
@@ -97,8 +97,8 @@ object ConnectionContext {
     scaladsl.ConnectionContext.https(
       sslContext,
       None,
-      enabledCipherSuites.toScala.map(Util.immutableSeq(_)),
-      enabledProtocols.toScala.map(Util.immutableSeq(_)),
+      enabledCipherSuites.toScala.map(Util.convertIterable[String, String](_)),
+      enabledProtocols.toScala.map(Util.convertIterable[String, String](_)),
       clientAuth.toScala,
       sslParameters.toScala)
 
diff --git 
a/http/src/main/scala/org/apache/pekko/http/javadsl/server/Rejections.scala 
b/http/src/main/scala/org/apache/pekko/http/javadsl/server/Rejections.scala
index c1864701a..7580861aa 100644
--- a/http/src/main/scala/org/apache/pekko/http/javadsl/server/Rejections.scala
+++ b/http/src/main/scala/org/apache/pekko/http/javadsl/server/Rejections.scala
@@ -25,7 +25,7 @@ import java.lang.{ Iterable => JIterable }
 
 import pekko.annotation.DoNotInherit
 import pekko.http.scaladsl
-import pekko.japi.Util
+import pekko.http.impl.util.Util
 import pekko.pattern.CircuitBreakerOpenException
 import pekko.util.OptionConverters._
 
@@ -416,7 +416,8 @@ object Rejections {
     s.UnsupportedRequestEncodingRejection(supported.asScala)
 
   def unsatisfiableRange(unsatisfiableRanges: java.lang.Iterable[ByteRange], 
actualEntityLength: Long) =
-    
UnsatisfiableRangeRejection(Util.immutableSeq(unsatisfiableRanges).map(_.asScala),
 actualEntityLength)
+    UnsatisfiableRangeRejection(Util.convertIterable[ByteRange, 
ByteRange](unsatisfiableRanges).map(_.asScala),
+      actualEntityLength)
 
   def tooManyRanges(maxRanges: Int) = TooManyRangesRejection(maxRanges)
 
diff --git 
a/http/src/main/scala/org/apache/pekko/http/javadsl/server/RouteResult.scala 
b/http/src/main/scala/org/apache/pekko/http/javadsl/server/RouteResult.scala
index 2201d6ef2..757c0a0d5 100644
--- a/http/src/main/scala/org/apache/pekko/http/javadsl/server/RouteResult.scala
+++ b/http/src/main/scala/org/apache/pekko/http/javadsl/server/RouteResult.scala
@@ -28,8 +28,7 @@ trait Rejected extends RouteResult {
 
 object RouteResults {
   import pekko.http.scaladsl.{ server => s }
-  import pekko.japi.Util
-  import pekko.http.impl.util.JavaMapping
+  import pekko.http.impl.util.{ JavaMapping, Util }
   import JavaMapping.Implicits._
   import RoutingJavaMapping._
 
@@ -38,7 +37,7 @@ object RouteResults {
   }
 
   def rejected(rejections: java.lang.Iterable[Rejection]): Rejected = {
-    s.RouteResult.Rejected(Util.immutableSeq(rejections).map(_.asScala))
+    s.RouteResult.Rejected(Util.convertIterable[Rejection, 
Rejection](rejections).map(_.asScala))
   }
 
 }
diff --git 
a/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/BasicDirectives.scala
 
b/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/BasicDirectives.scala
index 2af03fedb..72605e383 100644
--- 
a/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/BasicDirectives.scala
+++ 
b/http/src/main/scala/org/apache/pekko/http/javadsl/server/directives/BasicDirectives.scala
@@ -17,39 +17,36 @@ import java.util.function.{ Function => JFunction }
 
 import org.apache.pekko
 import pekko.actor.ActorSystem
-import pekko.http.impl.util.JavaMapping
-import pekko.http.javadsl.settings.ParserSettings
-import pekko.http.javadsl.settings.RoutingSettings
+import pekko.dispatch.ExecutionContexts
+import pekko.event.LoggingAdapter
 import pekko.japi.Util
+import pekko.stream.Materializer
 import pekko.stream.javadsl.Source
 import pekko.util.ByteString
+import pekko.util.FutureConverters._
 
-import scala.concurrent.ExecutionContextExecutor
 import pekko.http.impl.model.JavaUri
-import pekko.http.javadsl.model.HttpRequest
-import pekko.http.javadsl.model.HttpEntity
-import pekko.http.javadsl.model.RequestEntity
-import pekko.http.javadsl.model.Uri
+import pekko.http.impl.util.JavaMapping
+import pekko.http.impl.util.Util.convertIterable
+import pekko.http.javadsl.model.{ HttpEntity, HttpRequest, RequestEntity, Uri }
 import pekko.http.javadsl.server._
-import pekko.http.scaladsl.server.{ Directives => D }
+import pekko.http.javadsl.settings.{ ParserSettings, RoutingSettings }
 import pekko.http.scaladsl
-import pekko.stream.Materializer
-import java.util.function.Supplier
-import java.util.{ List => JList }
+import pekko.http.scaladsl.server.{ Directives => D }
 
 import pekko.http.javadsl.model.HttpResponse
 import pekko.http.javadsl.model.ResponseEntity
 import pekko.http.javadsl.model.HttpHeader
 import pekko.http.scaladsl.util.FastFuture._
+import pekko.http.javadsl.server
+
 import java.lang.{ Iterable => JIterable }
+import java.util.function.Supplier
+import java.util.{ List => JList }
 import java.util.concurrent.CompletionStage
 import java.util.function.Predicate
 
-import pekko.dispatch.ExecutionContexts
-import pekko.event.LoggingAdapter
-import pekko.http.javadsl.server
-import pekko.util.FutureConverters._
-
+import scala.concurrent.ExecutionContextExecutor
 import scala.concurrent.duration.FiniteDuration
 
 abstract class BasicDirectives {
@@ -66,7 +63,8 @@ abstract class BasicDirectives {
 
   def mapRejections(f: JFunction[JList[Rejection], JList[Rejection]], inner: 
Supplier[Route]): Route = RouteAdapter {
     D.mapRejections(rejections =>
-      
Util.immutableSeq(f.apply(Util.javaArrayList(rejections.map(_.asJava)))).map(_.asScala))
 { inner.get.delegate }
+      convertIterable[Rejection, 
Rejection](f.apply(Util.javaArrayList(rejections.map(_.asJava)))).map(
+        _.asScala)) { inner.get.delegate }
   }
 
   def mapResponse(f: JFunction[HttpResponse, HttpResponse], inner: 
Supplier[Route]): Route = RouteAdapter {
@@ -79,7 +77,10 @@ abstract class BasicDirectives {
 
   def mapResponseHeaders(f: JFunction[JList[HttpHeader], JList[HttpHeader]], 
inner: Supplier[Route]): Route =
     RouteAdapter {
-      D.mapResponseHeaders(l => 
Util.immutableSeq(f.apply(Util.javaArrayList(l))).map(_.asScala)) { 
inner.get.delegate } // TODO try to remove map()
+      D.mapResponseHeaders(l =>
+        convertIterable[HttpHeader, 
HttpHeader](f.apply(Util.javaArrayList(l))).map(_.asScala)) {
+        inner.get.delegate
+      } // TODO try to remove map()
     }
 
   def mapInnerRoute(f: JFunction[Route, Route], inner: Supplier[Route]): Route 
= RouteAdapter {
@@ -155,7 +156,7 @@ abstract class BasicDirectives {
    * to the list of rejections potentially coming back from the inner route.
    */
   def cancelRejections(classes: JIterable[Class[_]], inner: Supplier[Route]): 
Route = RouteAdapter {
-    D.cancelRejections(Util.immutableSeq(classes): _*) { inner.get.delegate }
+    D.cancelRejections(convertIterable[Class[_], Class[_]](classes): _*) { 
inner.get.delegate }
   }
 
   /**
diff --git 
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/Rejection.scala 
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/Rejection.scala
index 21e4cfd8e..37a1c74e1 100644
--- a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/Rejection.scala
+++ b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/Rejection.scala
@@ -18,7 +18,7 @@ import java.util.Optional
 import java.util.function.Function
 
 import org.apache.pekko
-import pekko.japi.Util
+import pekko.http.impl.util.Util
 import pekko.http.scaladsl.model._
 import pekko.http.scaladsl.model.headers.{ ByteRange, HttpChallenge, 
HttpEncoding }
 import pekko.http.javadsl.{ model, server => jserver }
@@ -335,7 +335,9 @@ final case class TransformationRejection(transform: 
immutable.Seq[Rejection] =>
     override def apply(t: Iterable[jserver.Rejection]): 
Iterable[jserver.Rejection] = {
       // explicit collects assignment is because of unidoc failing compilation 
on .asScala and .asJava here
       val transformed: Seq[jserver.Rejection] =
-        transform(Util.immutableSeq(t).collect { case r: Rejection => r 
}).collect { case j: jserver.Rejection => j }
+        transform(Util.convertIterable[jserver.Rejection, 
jserver.Rejection](t).collect { case r: Rejection =>
+          r
+        }).collect { case j: jserver.Rejection => j }
       transformed.asJava // TODO "asJavaDeep" and optimise?
     }
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to