Skip to content

Java API tests use Scala APIs in some cases #1180

Description

@pjfanning

I am working on fixing some of this but some issues look like they need improvements in our APIs to facilitate npt needing Scala DSL or Scala lib classes in some places in Java samples.

Java DSL RouteTest that is inherited directly or indirectly by most Java tests uses Scala Durations for waits.

protected def defaultAwaitDuration = 3.seconds
protected def awaitDuration: FiniteDuration = defaultAwaitDuration.dilated

So far, Java users need to extend the ScalaDSL CustomHeader class or use RawHeader.

// FIXME discuss how to provide a javadsl.CustomHeader where render() is either pre-implemented or
// trivial to write in Java

Scala Either used in JavaDSL authenticateOrRejectWithChallenge.
Java does provide an easy replacement and our sample code that demos this shows that the Scala Either, Left and Right classes are easy to use from Java.
example:

final Function<Optional<HttpCredentials>, CompletionStage<Either<HttpChallenge, String>>>
myUserPassAuthenticator =
opt -> {
if (opt.isPresent() && auth.apply(opt.get())) {
return CompletableFuture.completedFuture(Right.apply("some-user-name-from-creds"));
} else {
return CompletableFuture.completedFuture(Left.apply(challenge));
}
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions