Skip to content

Commit

Permalink
Support conversion between scaladsl.Uri and javadsl.Uri (#1950)
Browse files Browse the repository at this point in the history
* Support conversion between scaladsl.Uri and javadsl.Uri

* Exclude javadsl.moduel.Uri.asScala from MiMa

* Rephrase method documentation
  • Loading branch information
ennru authored and ktoso committed Mar 22, 2018
1 parent 6bab89f commit eb1ef78
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 10 deletions.
6 changes: 0 additions & 6 deletions akka-http-core/src/main/java/akka/http/impl/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package akka.http.impl.util;

import akka.http.impl.model.JavaUri;
import akka.http.javadsl.model.Uri;
import scala.compat.java8.OptionConverters;
import scala.None$;
import scala.collection.immutable.Map$;
Expand Down Expand Up @@ -61,10 +59,6 @@ public static <T, U extends T> Seq<U> convertArray(T[] els) {
return Util.<T, U>convertIterable(Arrays.asList(els));
}

public static akka.http.scaladsl.model.Uri convertUriToScala(Uri uri) {
return ((JavaUri) uri).uri();
}

public static <J, V extends J> Optional<J> lookupInRegistry(ObjectRegistry<Object, V> registry, int key) {
return Util.<J, V>convertOption(registry.getForKey(key));
}
Expand Down
13 changes: 13 additions & 0 deletions akka-http-core/src/main/java/akka/http/javadsl/model/Uri.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ public abstract class Uri {
*/
public abstract String getPathString();

/**
* Returns the Scala DSL representation of this Uri.
*/
public abstract akka.http.scaladsl.model.Uri asScala();


public static final akka.http.scaladsl.model.Uri.ParsingMode STRICT = UriJavaAccessor.pmStrict();
public static final akka.http.scaladsl.model.Uri.ParsingMode RELAXED = UriJavaAccessor.pmRelaxed();

Expand All @@ -186,6 +192,13 @@ public static Uri create(String uri) {
return new JavaUri(akka.http.scaladsl.model.Uri.apply(uri));
}

/**
* Returns the Java DSL representation of a Scala DSL Uri.
*/
public static Uri create(akka.http.scaladsl.model.Uri uri) {
return new JavaUri(uri);
}

/**
* Returns a Uri created by parsing the given string representation with the provided parsing mode.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static LinkParam rel(String value) {
return new akka.http.scaladsl.model.headers.LinkParams.rel(value);
}
public static LinkParam anchor(Uri uri) {
return new akka.http.scaladsl.model.headers.LinkParams.anchor(Util.convertUriToScala(uri));
return new akka.http.scaladsl.model.headers.LinkParams.anchor(uri.asScala());
}
public static LinkParam rev(String value) {
return new akka.http.scaladsl.model.headers.LinkParams.rev(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class LinkValue {

public static LinkValue create(Uri uri, LinkParam... params) {
return new akka.http.scaladsl.model.headers.LinkValue(
Util.convertUriToScala(uri),
uri.asScala(),
Util.<LinkParam, akka.http.scaladsl.model.headers.LinkParam>convertArray(params));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class Location extends akka.http.scaladsl.model.HttpHeader {
public abstract Uri getUri();

public static Location create(Uri uri) {
return new akka.http.scaladsl.model.headers.Location(akka.http.impl.util.Util.convertUriToScala(uri));
return new akka.http.scaladsl.model.headers.Location(uri.asScala());
}
public static Location create(String uri) {
return create(Uri.create(uri));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public abstract class Referer extends akka.http.scaladsl.model.HttpHeader {
public abstract Uri getUri();

public static Referer create(Uri uri) {
return new akka.http.scaladsl.model.headers.Referer(akka.http.impl.util.Util.convertUriToScala(uri));
return new akka.http.scaladsl.model.headers.Referer(uri.asScala());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Don't monitor changes to internal API
ProblemFilters.exclude[Problem]("akka.http.impl.*")

# Uri conversion additions https://github.com/akka/akka-http/pull/1950
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.http.javadsl.model.Uri.asScala")
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ case class JavaUri(uri: sm.Uri) extends jm.Uri {
override def getPort(): Int = port()
override def getUserInfo(): String = userInfo()
override def getPathString(): String = path()
override def asScala(): sm.Uri = uri

def pathSegments(): jl.Iterable[String] = {
import sm.Uri.Path._
Expand Down

0 comments on commit eb1ef78

Please sign in to comment.