Add HTTP client infrastructure with Java HttpClient and Jackson 3#25
Conversation
Implements internal HTTP client for Montonio API calls with GET/POST support, JSON serialization via Jackson 3, and exception mapping for error responses, network failures, and timeouts. Closes #11 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a new MontonioHttpClient implemented atop java.net.http.HttpClient with synchronous JSON GET/POST methods, Jackson 3 for (de)serialization, configurable timeouts and detailed error mapping; includes design documentation, unit tests, and a Jackson databind production dependency. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant MontonioHttpClient
participant JavaHttpClient as java.net.http.HttpClient
participant RemoteAPI as Remote API
Client->>MontonioHttpClient: get(path, responseType)
MontonioHttpClient->>MontonioHttpClient: build URI (baseUrl + path), headers, timeout
MontonioHttpClient->>JavaHttpClient: send(HttpRequest)
JavaHttpClient->>RemoteAPI: HTTP request
RemoteAPI-->>JavaHttpClient: HTTP response
JavaHttpClient-->>MontonioHttpClient: HttpResponse
alt Status 2xx
MontonioHttpClient->>MontonioHttpClient: deserialize body -> responseType (Jackson)
MontonioHttpClient-->>Client: return typed object
else Status non-2xx
MontonioHttpClient->>MontonioHttpClient: attempt parse error JSON (errorCode, message)
MontonioHttpClient-->>Client: throw MontonioApiException
else Network failure (IOException / InterruptedException)
MontonioHttpClient-->>Client: throw MontonioNetworkException
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/plans/2026-04-10-http-client-design.md`:
- Around line 106-108: The docs claim buildApiException always falls back to the
raw body as errorMessage when JSON is absent or missing fields, but the
implementation only uses the raw body when JSON parsing fails; if JSON parses
but lacks errorCode/message it returns null fields. Update buildApiException to
(1) wrap JSON parsing in try/catch to avoid throwing, (2) after parsing, verify
parsed.errorCode and parsed.message (or whatever fields are expected) and if
they are missing/null use the raw response body (or a default string like
"unknown error") for errorMessage and a default errorCode (e.g.,
"UNKNOWN_ERROR"), and (3) ensure the function always returns a usable exception
object rather than nulls so it matches the documentation.
In `@src/main/java/ee/bitweb/montonio/sdk/http/MontonioHttpClient.java`:
- Around line 23-38: The package-private constructor
MontonioHttpClient(MontonioSdkConfiguration configuration, HttpClient
httpClient) prevents consumers from supplying their own HttpClient and there's
no API to toggle request/response logging; make the injectable constructor
public so callers can pass a pre-configured java.net.http.HttpClient, and add a
visible hook to enable/disable logging (for example: a public boolean flag, a
LoggingLevel enum, or a Consumer<HttpRequest/HttpResponse> callback exposed via
constructor or a fluent MontonioHttpClientBuilder) that the client code checks
when sending requests to emit request/response details; update
MontonioHttpClient constructors (and/or introduce a public builder) to accept
both HttpClient and the logging toggle so shared pools/proxies/TLS customisation
and toggleable logging are available to SDK users.
In `@src/test/java/ee/bitweb/montonio/sdk/http/MontonioHttpClientTest.java`:
- Around line 98-105: The test postSerializesBodyAndDeserializesResponse doesn't
assert the outbound JSON; modify the StubHttpClient to capture the request body
(e.g., add a lastRequestBody/getLastRequestBody on StubHttpClient that stores
the raw request body passed into its request/send method) and then in
postSerializesBodyAndDeserializesResponse add an assertion that the captured
body equals the expected serialized JSON for new TestRequest("hello") (or
compare via the same serializer used by MontonioHttpClient to avoid string
formatting brittleness). Reference StubHttpClient, MontonioHttpClient,
postSerializesBodyAndDeserializesResponse, and TestRequest when adding the
capture and assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 36df9596-f390-44ba-858f-d28ad55118b5
📒 Files selected for processing (4)
build.gradledocs/plans/2026-04-10-http-client-design.mdsrc/main/java/ee/bitweb/montonio/sdk/http/MontonioHttpClient.javasrc/test/java/ee/bitweb/montonio/sdk/http/MontonioHttpClientTest.java
Fix design doc to accurately describe null field behavior in error parsing. Add request body assertion to POST test to verify outbound JSON serialization. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
MontonioHttpClientinee.bitweb.montonio.sdk.httpwrappingjava.net.http.HttpClientget()andpost()methods with Jackson 3 JSON serialization/deserializationMontonioApiException(best-effort JSON field extraction), network failures toMontonioNetworkExceptionTest plan
MontonioApiExceptionwith parsed fieldsMontonioApiExceptionwith raw bodyMontonioNetworkExceptionMontonioNetworkException+ interrupt flag restoredMontonioExceptionCloses #11
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation
Chores
Tests