Skip to content

Add logbook-jdkhttpclient module for JDK HttpClient (#2006) - #2386

Open
Vinu2111 wants to merge 8 commits into
zalando:mainfrom
Vinu2111:feature/logbook-jdkhttpclient
Open

Add logbook-jdkhttpclient module for JDK HttpClient (#2006)#2386
Vinu2111 wants to merge 8 commits into
zalando:mainfrom
Vinu2111:feature/logbook-jdkhttpclient

Conversation

@Vinu2111

@Vinu2111 Vinu2111 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Description

Implements Phase 1 of the logbook-jdkhttpclient module providing request and response logging support for JDK 11+'s built-in java.net.http.HttpClient:

  • LogbookHttpClient: Decorator extending java.net.http.HttpClient that wraps the synchronous send() method with Logbook's two-stage request/response logging lifecycle. All abstract HttpClient getter/delegator methods are passed through to the delegate. Both sendAsync() overloads are stubbed throwing UnsupportedOperationException (planned for follow-up).
  • JdkRequest: Implements org.zalando.logbook.HttpRequest wrapping java.net.http.HttpRequest with a lazy body-buffering state machine (Unbuffered -> Offering -> Buffering / Ignoring / Passing). Drains the BodyPublisher on-demand via reactive streams and reconstructs the HttpRequest with all original attributes (headers, method, URI, timeout, version, expectContinue) intact for transport.
  • TeeingBodySubscriber: Decorates the response HttpResponse.BodySubscriber<T> and tees incoming ByteBuffers into a cache without mutating buffer positions or limits for the delegate subscriber.
  • RemoteResponse: Implements org.zalando.logbook.HttpResponse wrapping HttpResponse<?> and cached response bytes with state machine transitions.
  • Resilience: Pre-send request logging and post-send response logging are isolated in try/catch blocks to ensure logging failures never break the underlying HTTP invocation.
  • Documentation: Registered in pom.xml, logbook-bom/pom.xml, and added configuration instructions in README.md.
  • Test Suite: Comprehensive WireMock test suite covering single-chunk, multi-chunk, chunked, and non-chunked transfer encoding, inactive writer short-circuits, delegator methods, and failure scenarios. JaCoCo 100% line and branch coverage enforced.

Motivation and Context

Closes #2006.

Provides first-class, zero-dependency logging support for applications using Java's standard java.net.http.HttpClient without requiring third-party HTTP client libraries (such as Apache HttpClient or OkHttp).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All commits are signed

Introduce new logbook-jdkhttpclient module for JDK HttpClient (java.net.http) integration, registering it in the root POM reactor and logbook-bom.
Add TeeingBodySubscriber to capture incoming response bytes into a buffer without disturbing the delegate BodySubscriber ByteBuffer positions. Add RemoteResponse wrapping HttpResponse with lazy body buffering state machine.
Add JdkRequest implementing org.zalando.logbook.HttpRequest wrapping java.net.http.HttpRequest with lazy Flow-based body draining and request rebuilding to preserve body for transport.
Add LogbookHttpClient extending java.net.http.HttpClient with two-stage Logbook logging around send(), resilient exception handling, and full AbstractHttpTest WireMock test suite covering chunked/non-chunked bodies.
@kasmarian

Copy link
Copy Markdown
Collaborator

is it a duplicate of #2383?

@Vinu2111

Vinu2111 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kasmarian, thanks for flagging! #2386 targets the same issue (#2006) but takes a different technical approach from #2383:

  • Works within the project's current Java 17+ baseline; Add Support For Native JDK HttpClient #2383 requires JDK 21+, which would raise the minimum Java version project-wide
  • Decorator-based (LogbookHttpClient wrapping java.net.http.HttpClient), following the existing logbook-httpclient5 pattern, rather than a Spring autoconfiguration-first approach
  • Sync send() is fully implemented and tested (WireMock suite, 100% JaCoCo line/branch coverage); sendAsync() is stubbed for a Phase 2 follow-up
  • Build is currently green

Happy to align with @ChristianLohmann on scope, or consolidate into one PR, if that's what the maintainers would prefer, just let me know which direction keeps things cleanest.

@kasmarian

Copy link
Copy Markdown
Collaborator

@ChristianLohmann what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support java built in httpclient java.net.http.HttpClient

2 participants