pjfanning opened a new pull request, #1375:
URL: https://github.com/apache/pekko-http/pull/1375

   ### Motivation
   The Java DSL `onComplete` and `onCompleteWithBreaker` directives pass the 
result to the inner route as a `scala.util.Try<T>`. Java users have to work 
with a Scala type to handle failures; the docs example needed `PFBuilder` and 
`Try.recover` just to map an exception to a response.
   
   ### Modification
   - Add `onComplete(Supplier<CompletionStage<T>>, BiFunction<T, Throwable, 
Route>)`, `onComplete(CompletionStage<T>, BiFunction<T, Throwable, Route>)` and 
`onCompleteWithBreaker(CircuitBreaker, Supplier<CompletionStage<T>>, 
BiFunction<T, Throwable, Route>)`.
   - The callback follows `CompletionStage.handle`: on success it gets the 
value and a `null` failure; on failure it gets a `null` value and the 
`Throwable`. `CompletionException` wrappers are unwrapped, as in the existing 
overloads.
   - Java lambdas pick the overload by arity (`result -> ...` vs `(value, ex) 
-> ...`), so existing `Try`-based callers compile unchanged. The `Try` 
overloads are kept and not deprecated.
   - Update the Java examples for `onComplete` and `onCompleteWithBreaker`, and 
the Java description on the `onComplete` docs page.
   
   ### Result
   Java users can handle `onComplete` results without Scala types, e.g.:
   ```java
   onComplete(() -> CompletableFuture.supplyAsync(() -> a / b),
       (result, ex) -> ex == null
           ? complete("The result was " + result)
           : complete(StatusCodes.INTERNAL_SERVER_ERROR, "An error occurred: " 
+ ex.getMessage()))
   ```
   
   ### Tests
   - `sbt "http-tests/Test/testOnly 
org.apache.pekko.http.javadsl.server.directives.FutureDirectivesTest"` - passed 
on Scala 2.13 and 3.3.8 (new test: success and failure for both new 
`onComplete` overloads, `CompletionException` unwrapping, and overload 
resolution of one- and two-argument lambdas)
   - `sbt "docs/Test/testOnly 
docs.http.javadsl.server.directives.FutureDirectivesExamplesTest 
docs.http.javadsl.server.FileUploadExamplesTest"` - passed (the breaker example 
test is `@Disabled` upstream; it compiles)
   - `sbt http/mimaReportBinaryIssues` - passed
   - `sbt http/scalafmt http-tests/Test/javafmt docs/Test/javafmt` - applied
   - Paradox not run locally; CI builds the docs.
   
   ### References
   None - Java DSL cleanup of Scala types in public API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to