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

   ### Motivation
   The Java DSL host-level and super pool flows (`newHostConnectionPool`, 
`cachedHostConnectionPool`, `cachedHostConnectionPoolHttps`, `superPool`) emit 
`Pair<scala.util.Try<HttpResponse>, T>`. These are the standard way to stream 
client requests, so Java users of that API have to work with a Scala type. Java 
cannot overload on return type, so the existing methods cannot gain Java-typed 
twins the way the routing directives can.
   
   ### Modification
   - Add `org.apache.pekko.http.javadsl.HttpResponseResult`, a 
success-or-failure holder with `isSuccess()`, `isFailure()`, `getResponse()`, 
`getFailure()`, `fold(onSuccess, onFailure)` and a 
`CompletionStage.handle`-style `handle((response, failure) -> ...)`. 
`getResponse()` on a failure throws `IllegalStateException` with the failure as 
its cause. Instances are created with `HttpResponseResult.success(...)` / 
`failure(...)`.
   - Add `*WithResult` variants for all 11 pool overloads: 
`newHostConnectionPoolWithResult` (3), `cachedHostConnectionPoolWithResult` 
(3), `cachedHostConnectionPoolHttpsWithResult` (2) and `superPoolWithResult` 
(3). Each delegates to the existing method and maps the `Try` to an 
`HttpResponseResult`.
   - Document the variants in the host-level client docs (the request-level 
`superPool` docs defer to that section).
   
   The existing `Try`-emitting methods are unchanged and not deprecated.
   
   ### Result
   Java users can stream requests through connection pools without 
`scala.util.Try`:
   ```java
   Source.single(Pair.create(HttpRequest.GET("http://example.com/";), ctx))
       .via(http.<Ctx>superPoolWithResult())
       .map(pair -> pair.first().fold(
           response -> handleResponse(response, pair.second()),
           failure -> handleFailure(failure, pair.second())));
   ```
   
   ### Tests
   - `sbt "http-core/Test/testOnly 
org.apache.pekko.http.javadsl.HttpResponseResultTest 
org.apache.pekko.http.javadsl.HttpExtensionApiSpec"` - passed on Scala 2.13 and 
3.3.8
     - new `HttpResponseResultTest` (Java): accessors, `fold`, `handle`, null 
rejection, equality
     - new `HttpExtensionApiSpec` cases against a local server: 
`newHostConnectionPoolWithResult`, `cachedHostConnectionPoolWithResult` and 
`superPoolWithResult` success, and a failed `HttpResponseResult` from 
`superPoolWithResult` when the connection is refused; each checks the context 
object is carried through
   - `sbt http-core/mimaReportBinaryIssues` - passed
   - `sbt http-core/scalafmtCheckAll http-core/Test/javafmtCheck` - passed
   - 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